Commit 66be4ac7 authored by dave griffiths's avatar dave griffiths
Browse files

pack changes and sql indices

parent ff0ecb6a
......@@ -37,22 +37,45 @@
(define (upgrade-table db name)
(db-exec db (string-append "alter table " name " add version integer")))
(db-exec db (string-append "alter table " name " add version integer"))
(db-exec db (string-append "create index if not exists index_" table "_entity on " table "_entity (unique_id)"))
(db-exec db (string-append "create index if not exists index_" table "_attribute on " table "_attribute (entity_type)"))
(db-exec db (string-append "create index if not exists index_" table "_value_varchar on " table "_value_varchar (entity_id,attribute_id)"))
(db-exec db (string-append "create index if not exists index_" table "_value_int on " table "_value_int (entity_id,attribute_id)"))
(db-exec db (string-append "create index if not exists index_" table "_value_real on " table "_value_real (entity_id,attribute_id)"))
(db-exec db (string-append "create index if not exists index_" table "_value_file on " table "_value_file (entity_id,attribute_id)"))
)
;; create eav tables (add types as required)
(define (setup db table)
(msg "db setup")
(db-exec db (string-append "create table " table "_entity ( entity_id integer primary key autoincrement, entity_type varchar(256), unique_id varchar(256), dirty integer, version integer)"))
(db-exec db (string-append "create index if not exists index_" table "_entity on " table "_entity (unique_id)"))
(db-exec db (string-append "create table " table "_attribute ( id integer primary key autoincrement, attribute_id varchar(256), entity_type varchar(256), attribute_type varchar(256))"))
(db-exec db (string-append "create index if not exists index_" table "_attribute on " table "_attribute (entity_type)"))
(db-exec db (string-append "create table " table "_value_varchar ( id integer primary key autoincrement, entity_id integer, attribute_id varchar(255), value varchar(4096), dirty integer, version integer)"))
(upgrade-table db (string-append table "_value_varchar"))
(db-exec db (string-append "create index if not exists index_" table "_value_varchar on " table "_value_varchar (entity_id,attribute_id)"))
(db-exec db (string-append "create table " table "_value_int ( id integer primary key autoincrement, entity_id integer, attribute_id varchar(255), value integer, dirty integer, version integer)"))
(upgrade-table db (string-append table "_value_int"))
(db-exec db (string-append "create index if not exists index_" table "_value_int on " table "_value_int (entity_id,attribute_id)"))
(db-exec db (string-append "create table " table "_value_real ( id integer primary key autoincrement, entity_id integer, attribute_id varchar(255), value real, dirty integer, version integer)"))
(upgrade-table db (string-append table "_value_real"))
(db-exec db (string-append "create index if not exists index_" table "_value_real on " table "_value_real (entity_id,attribute_id)"))
(db-exec db (string-append "create table " table "_value_file ( id integer primary key autoincrement, entity_id integer, attribute_id varchar(255), value varchar(4096), dirty integer, version integer)"))
(upgrade-table db (string-append table "_value_file")))
(upgrade-table db (string-append table "_value_file"))
(db-exec db (string-append "create index if not exists index_" table "_value_file on " table "_value_file (entity_id,attribute_id)"))
)
(define (validate db)
......
INDIV SEX PACK BORN LITTER
DF130 F 11 11/10/2008 D0803
DF139 F 11 11/10/2008 D0803
DF169 F 11 12/05/2010 D1002
DF190 F 11 22/10/2011 D1107
DF200 F 11 16/05/2012 D1202
DF201 F 11 16/05/2012 D1202
DF208 F 11 16/05/2012 D1202
DF216 F 11 06/10/2012 D1204
DF222 F 11 26/06/2013 D1302
DF223 F 11 26/06/2013 D1302
DF225 F 11 26/06/2013 D1302
DF226 F 11 26/06/2013 D1302
DM126 M 11 08/05/2008 D0801
DM165 M 11 14/10/2009 D0904
DM168 M 11 28/12/2009 D0905
DM170 M 11 12/05/2010 D1002
DM171 M 11 12/05/2010 D1002
DM179 M 11 23/07/2010 D1003
DM180 M 11 23/07/2010 D1003
DM189 M 11 02/08/2011 D1106
DM192 M 11 22/10/2011 D1107
DM193 M 11 22/10/2011 D1107
DM194 M 11 22/10/2011 D1107
DM198 M 11 16/05/2012 D1202
DM202 M 11 16/05/2012 D1202
DM203 M 11 16/05/2012 D1202
DM204 M 11 16/05/2012 D1202
DM206 M 11 16/05/2012 D1202
DM209 M 11 16/05/2012 D1202
DM212 M 11 06/10/2012 D1204
DM213 M 11 06/10/2012 D1204
DM215 M 11 06/10/2012 D1204
DM220 M 11 16/04/2013 D1301
DM224 M 11 26/06/2013 D1302
VM107 M 14 28/07/2009 V0904
YF011 F 14 22/08/2013
YF097 F 14 16/11/2010 Y1004
YM096 M 14 16/11/2010 Y1004
UF019 F 15 01/08/2011 U1103
VF033 F 15 26/04/2006
VF137 F 15 15/10/2012 V1203
VF138 F 15 27/04/2013 V1301
VF139 F 15 19/08/2013
VF140 F 15 19/08/2013
VF141 F 15 19/08/2013
VF142 F 15 19/08/2013
VF143 F 15 19/08/2013
VM096 M 15 09/10/2008 V0803
VM123 M 15 01/11/2010 V1005
VM135 M 15 15/10/2012 V1203
VM136 M 15 15/10/2012 V1203
HM069 M 17 31/10/2003 H0304
HM092 M 17 19/04/2005 H0502
SF017 F 17 23/08/2010
SF024 F 17 13/07/2011
SF034 F 17 05/11/2012 S1205
SF038 F 17 05/11/2012 S1205
SF041 F 17 26/04/2013 S1301
SF045 F 17 26/04/2013 S1301
SM009 M 17 15/09/2008 S0804
SM013 M 17 15/09/2008 S0804
SM018 M 17 23/08/2010
SM021 M 17 11/05/2011 S1101
SM028 M 17 09/09/2011 S1102
SM037 M 17 05/11/2012 S1205
SM039 M 17 05/11/2012 S1205
UM020 M 18 01/08/2011 U1103
BF473 F 1B 22/01/2010 B1001
BF484 F 1B 07/05/2010 B1003
BF487 F 1B 07/05/2010 B1003
BF535 F 1B 02/07/2011 B1103
BF561 F 1B 20/04/2012 B1202
BF566 F 1B 20/04/2012 B1202
BF585 F 1B 27/06/2012 B1203
BF589 F 1B 27/06/2012 B1203
BF593 F 1B 17/09/2012 B1204
BF616 F 1B 03/07/2013 B1304
BF617 F 1B 03/07/2013 B1304
BF619 F 1B 03/07/2013 B1304
BF621 F 1B 03/07/2013 B1304
BF622 F 1B 03/07/2013 B1304
BF624 F 1B 03/07/2013 B1304
BF625 F 1B 03/07/2013 B1304
BF627 F 1B 03/07/2013 B1304
BM216 M 1B 27/03/2004 B0402
BM310 M 1B 20/07/2006 B0604
BM410 M 1B 15/09/2008 B0805
BM436 M 1B 25/03/2009 B0902A
BM438 M 1B 25/03/2009 B0902A
BM455 M 1B 20/06/2009 B0903
BM500 M 1B 09/12/2010 B1006
BM558 M 1B 20/04/2012 B1202
BM559 M 1B 20/04/2012 B1202
BM562 M 1B 20/04/2012 B1202
BM564 M 1B 20/04/2012 B1202
BM580 M 1B 27/06/2012 B1203
BM609 M 1B 29/04/2013 B1303
BM614 M 1B 03/07/2013 B1304
BM615 M 1B 03/07/2013 B1304
BM618 M 1B 03/07/2013 B1304
BM620 M 1B 03/07/2013 B1304
BM623 M 1B 03/07/2013 B1304
BM626 M 1B 03/07/2013 B1304
HF125 F 1H 30/11/2006 H0605
HF178 F 1H 14/10/2008 H0804
HF182 F 1H 12/03/2009 H0901
HF220 F 1H 10/11/2010 H1004
HF240 F 1H 23/04/2012 H1202
HF242 F 1H 23/04/2012 H1202
HF248 F 1H 27/06/2012 H1203
HF251 F 1H 27/06/2012 H1203
HF260 F 1H 06/06/2013 H1303
HF261 F 1H 06/06/2013 H1303
HM117 M 1H 17/05/2006 H0602
HM180 M 1H 14/10/2008 H0804
HM195 M 1H 18/12/2009 H0905
HM216 M 1H 10/11/2010 H1004
HM217 M 1H 10/11/2010 H1004
HM222 M 1H 10/11/2010 H1004
HM223 M 1H 10/11/2010 H1004
HM241 M 1H 23/04/2012 H1202
HM243 M 1H 23/04/2012 H1202
HM246 M 1H 23/04/2012 H1202
HM253 M 1H 27/06/2012 H1203
TF249 F 2 02/10/2008 T0804
TF284 F 2 24/06/2010 T1003
TF285 F 2 24/06/2010 T1003
TF297 F 2 21/04/2012 T1202
TF298 F 2 21/04/2012 T1202
TF299 F 2 21/04/2012 T1202
TF319 F 2 06/07/2012 T1203
TF321 F 2 06/07/2012 T1203
TF322 F 2 06/07/2012 T1203
TF332 F 2 26/01/2013 T1301
TF334 F 2 26/01/2013 T1301
TF336 F 2 26/01/2013 T1301
TM233 M 2 30/07/2008 T0803
TM236 M 2 02/10/2008 T0804
TM272 M 2 02/02/2010 T1001
TM279 M 2 15/04/2010 T1002
TM283 M 2 24/06/2010 T1003
TM286 M 2 24/06/2010 T1003
TM300 M 2 21/04/2012 T1202
TM304 M 2 21/04/2012 T1202
TM307 M 2 21/04/2012 T1202
TM309 M 2 21/04/2012 T1202
TM312 M 2 21/04/2012 T1202
TM317 M 2 06/07/2012 T1203
TM323 M 2 06/07/2012 T1203
TM335 M 2 26/01/2013 T1301
TM339 M 2 08/04/2013 T1302
TP355 P 2 28/09/2013 T1305
TP356 P 2 28/09/2013 T1305
TP357 P 2 28/09/2013 T1305
TP358 P 2 28/09/2013 T1305
TP359 P 2 28/09/2013 T1305
TP360 P 2 28/09/2013 T1305
TP361 P 2 28/09/2013 T1305
TP362 P 2 28/09/2013 T1305
TP363 P 2 28/09/2013 T1305
FF166 F 4B 10/01/2010 F1001
FF196 F 4B 28/10/2011 F1104
FM176 M 4B 06/12/2010
FM178 M 4B 06/12/2010
FM188 M 4B 07/04/2011
FM191 M 4B 07/04/2011
FM199 M 4B 18/02/2013 F1301
FF165 F 4E 10/01/2010 F1001
FF187 F 4E 07/04/2011
FF190 F 4E 07/04/2011
MM002 M 4E 27/03/2012
MM004 M 4E 22/08/2012
GF092 F 7A 06/04/2011 G1101
GF093 F 7A 06/04/2011 G1101
GF096 F 7A 12/07/2011 G1102
GF100 F 7A 22/10/2011 G1103
GF106 F 7A 16/06/2012 G1201
GF118 F 7A 22/04/2013 G1301
GM035 M 7A 12/05/2006 G0602
GM049 M 7A 22/10/2007
GM060 M 7A 05/05/2009 G0902
GM061 M 7A 05/05/2009 G0902
GM065 M 7A 23/07/2009 G0903
GM080 M 7A 26/04/2010 G1002
GM082 M 7A 26/04/2010 G1002
GM087 M 7A 28/11/2010 G1004
GM089 M 7A 28/11/2010 G1004
GM090 M 7A 06/04/2011 G1101
GM097 M 7A 12/07/2011 G1102
GM099 M 7A 22/10/2011 G1103
GM105 M 7A 16/06/2012 G1201
GM110 M 7A 01/12/2012 G1203
GM111 M 7A 01/12/2012 G1203
GM112 M 7A 01/12/2012 G1203
GM114 M 7A 01/12/2012 G1203
GM115 M 7A 01/12/2012 G1203
GM117 M 7A 22/04/2013 G1301
ID Sex Pack Birth Date Estimated birth date
DM126 M 11 08-May-08
DM165 M 11 14-Oct-09
DM168 M 11 28-Dec-09
DM170 M 11 12-May-10
DM171 M 11 12-May-10
DM179 M 11 23-Jul-10
DM180 M 11 23-Jul-10
DM189 M 11 02-Aug-11
DF190 F 11 22-Oct-11
DM192 M 11 22-Oct-11
DM193 M 11 22-Oct-11
DM194 M 11 22-Oct-11
DM198 M 11 16-May-12
DF200 F 11 16-May-12
DF201 F 11 16-May-12
DM203 M 11 16-May-12
DM204 M 11 16-May-12
DM206 M 11 16-May-12
DF208 F 11 16-May-12
DM209 M 11 16-May-12
DM212 M 11 06-Oct-12
DM213 M 11 06-Oct-12
DM215 M 11 06-Oct-12
DF216 F 11 06-Oct-12
DM220 M 11 16-Apr-13
DF222 F 11 26-Jun-13
DF223 F 11 26-Jun-13
SM009 M 17 15-Sep-08
SM013 M 17 15-Sep-08
SF017 F 17 01-Jan-10 Y
SM018 M 17 01-Jan-10 Y
SM021 M 17 11-May-11
SF024 F 17 01-Jan-10 Y
SF034 F 17 05-Nov-12
SF038 F 17 05-Nov-12
SM039 M 17 05-Nov-12
HM069 M 17 31-Oct-03
HM092 M 17 19-Apr-05
UM020 M 18 01-Aug-11
XM003 M 19 01-Jan-12 Y
XF004 F 19 01-Jan-12 Y
XF005 F 19 01-Jan-12 Y
XM006 M 19 01-Jan-12 Y
XM007 M 19 01-Jan-12 Y
XF008 F 19 01-Jan-13 Y
XM009 M 19 01-Jan-14 Y
XF010 F 19 01-Jan-14 Y
XF012 F 19 01-Jan-14 Y
XF016 F 19 04-Apr-14
XM017 M 19 04-Apr-14
XM018 M 19 04-Apr-14
XF020 F 19 16-Jun-14
XM021 M 19 16-Jun-14
XF022 F 19 16-Jun-14
XM023 M 19 16-Jun-14
YM024 M 19 02-May-07
XM024 M 19 16-Jun-14
XM025 M 19 16-Jun-14
XF026 F 19 16-Jun-14
YM031 M 19 25-Jun-07
BM216 M 1B 27-Mar-04
BM410 M 1B 15-Sep-08
BM436 M 1B 25-Mar-09
BM438 M 1B 25-Mar-09
BM455 M 1B 20-Jun-09
BF473 F 1B 22-Jan-10
BF484 F 1B 07-May-10
BM500 M 1B 09-Dec-10
BF535 F 1B 02-Jul-11
BM558 M 1B 20-Apr-12
BF561 F 1B 20-Apr-12
BM564 M 1B 20-Apr-12
BF566 F 1B 20-Apr-12
BF589 F 1B 27-Jun-12
BF593 F 1B 17-Sep-12
BM620 M 1B 03-Jul-13
BF622 F 1B 03-Jul-13
BF627 F 1B 03-Jul-13
BM638 M 1B 10-Oct-13
BM643 M 1B 10-Jun-14
BF645 F 1B 10-Jun-14
BM646 M 1B 10-Jun-14
BF647 F 1B 10-Jun-14
BP653 P 1B 25-Jul-14
BP654 P 1B 25-Jul-14
HM117 M 1H 17-May-06
HF125 F 1H 30-Nov-06
HF178 F 1H 14-Oct-08
HM180 M 1H 14-Oct-08
HF182 F 1H 12-Mar-09
HM195 M 1H 18-Dec-09
HM216 M 1H 10-Nov-10
HM217 M 1H 10-Nov-10
HF220 F 1H 10-Nov-10
HM222 M 1H 10-Nov-10
HM223 M 1H 10-Nov-10
HF240 F 1H 23-Apr-12
HM241 M 1H 23-Apr-12
HF242 F 1H 23-Apr-12
HM246 M 1H 23-Apr-12
HF248 F 1H 27-Jun-12
HF260 F 1H 06-Jun-13
HF261 F 1H 06-Jun-13
HM275 M 1H 05-Oct-13
HF276 F 1H 11-Apr-14
HF285 F 1H 18-Jun-14
TF121 F 2 01-Jan-04 Y
TF125 F 2 01-Jan-04 Y
TM233 M 2 30-Jul-08
TM236 M 2 02-Oct-08
TF249 F 2 02-Oct-08
TM272 M 2 02-Feb-10
TM279 M 2 15-Apr-10
TM283 M 2 24-Jun-10
TF284 F 2 24-Jun-10
TF285 F 2 24-Jun-10
TM286 M 2 24-Jun-10
TF297 F 2 21-Apr-12
TF298 F 2 21-Apr-12
TF299 F 2 21-Apr-12
TM300 M 2 21-Apr-12
TM304 M 2 21-Apr-12
TM307 M 2 21-Apr-12
TM312 M 2 21-Apr-12
TM317 M 2 06-Jul-12
TF319 F 2 06-Jul-12
TF321 F 2 06-Jul-12
TF322 F 2 06-Jul-12
TM323 M 2 06-Jul-12
TF334 F 2 26-Jan-13
TM335 M 2 26-Jan-13
TM363 M 2 28-Sep-13
TF372 F 2 25-Jul-14
TM373 M 2 25-Jul-14
TF374 F 2 25-Jul-14
TF376 F 2 25-Jul-14
TF377 F 2 25-Jul-14
TM378 M 2 25-Jul-14
TM379 M 2 25-Jul-14
TM380 M 2 25-Jul-14
TF381 F 2 25-Jul-14
TM382 M 2 25-Jul-14
TM383 M 2 25-Jul-14
VM096 M 21 09-Oct-08
VM135 M 21 15-Oct-12
VM136 M 21 15-Oct-12
VF139 F 21 01-Jan-12 Y
VF140 F 21 01-Jan-12 Y
VF141 F 21 01-Jan-12 Y
VF142 F 21 01-Jan-12 Y
VF143 F 21 01-Jan-12 Y
VF152 F 21 05-May-14
VF153 F 21 05-May-14
VF154 F 21 05-May-14
VM155 M 21 05-May-14
VF156 F 21 05-May-14
FM176 M 4B 01-Jan-11 Y
FM178 M 4B 01-Jan-11 Y
FM188 M 4B 07-Apr-11
FM191 M 4B 07-Apr-11
FF196 F 4B 28-Oct-11
FF206 F 4B 01-Jan-12 Y
FF207 F 4B 01-Jan-12 Y
FF208 F 4B 01-Jan-12 Y
FF209 F 4B 01-Jan-12 Y
MM002 M 4E 01-Jan-12 Y
MM004 M 4E 01-Jan-12 Y
MM007 M 4E 20-Jun-14
FF165 F 4E 10-Jan-10
FF187 F 4E 07-Apr-11
FF190 F 4E 07-Apr-11
GM049 M 7A 22-Oct-07
GM060 M 7A 05-May-09
GM061 M 7A 05-May-09
GM065 M 7A 23-Jul-09
GM080 M 7A 26-Apr-10
GM082 M 7A 26-Apr-10
GM087 M 7A 28-Nov-10
GM089 M 7A 28-Nov-10
GM090 M 7A 06-Apr-11
GF092 F 7A 06-Apr-11
GF093 F 7A 06-Apr-11
GF096 F 7A 12-Jul-11
GF100 F 7A 22-Oct-11
GM105 M 7A 16-Jun-12
GF106 F 7A 16-Jun-12
GM112 M 7A 01-Dec-12
GM115 M 7A 01-Dec-12
GM117 M 7A 22-Apr-13
......@@ -74,8 +74,9 @@
(define (insert-mongooses db table l)
(map
(lambda (i)
(msg (length i))
(let ((pack (car (db-all-where db table "pack" (list "name" "varchar" (list-ref i 2)))))
(date (string-split (list-ref i 3) '(#\/))))
(date (string-split (list-ref i 3) '(#\-))))
(msg i)
(insert-entity db table "mongoose" "sys"
(list
......@@ -83,7 +84,7 @@
(ktv "gender" "varchar"
(if (equal? (list-ref i 1) "F") "Female" "Male"))
(ktv "pack-id" "varchar" (ktv-get pack "unique_id"))
(ktv "litter-code" "varchar" (if (eq? (length i) 5) (list-ref i 4) ""))
(ktv "litter-code" "varchar" "")
(ktv "chip-code" "varchar" "")
(ktv "dob" "varchar" (string-append
(list-ref date 2) "-"
......@@ -107,5 +108,5 @@
(define (write-db db table path)
(insert-packs db table (list "11" "14" "15" "17" "18" "1B" "1H" "2" "4B" "4E" "7A"))
(insert-packs db table (list "11" "14" "15" "17" "18" "19" "1B" "1H" "2" "21" "4B" "4E" "7A"))
(insert-csv db table path))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment