1
|
Installation:
|
2
|
Install: make install
|
3
|
WARNING: This will delete the current public schema of your VegBIEN DB!
|
4
|
Uninstall: make uninstall
|
5
|
WARNING: This will delete your entire VegBIEN DB!
|
6
|
This includes all archived imports and staging tables.
|
7
|
|
8
|
Maintenance:
|
9
|
Important: Whenever you install a system update that affects PostgreSQL or
|
10
|
any of its dependencies, such as libc, you should restart the PostgreSQL
|
11
|
server. Otherwise, you may get strange errors like "the database system
|
12
|
is in recovery mode" which go away upon reimport.
|
13
|
|
14
|
Data import:
|
15
|
On local machine:
|
16
|
make test by_col=1
|
17
|
See note under Testing below
|
18
|
On vegbiendev:
|
19
|
svn up
|
20
|
make inputs/upload
|
21
|
For each newly-uploaded datasource: make inputs/<datasrc>/reinstall
|
22
|
Update the schemas: make schemas/reinstall
|
23
|
WARNING: This will delete the current public schema of your VegBIEN DB!
|
24
|
To save it: make schemas/rotate
|
25
|
Start column-based import: . bin/import_all by_col=1
|
26
|
To use row-based import: . bin/import_all
|
27
|
To stop all running imports: . bin/stop_imports
|
28
|
WARNING: Do NOT run import_all in the background, or the jobs it creates
|
29
|
won't be owned by your shell.
|
30
|
Note that import_all will several hours to import the NCBI backbone and
|
31
|
TNRS names before returning control to the shell.
|
32
|
Wait (overnight) for the import to finish
|
33
|
On local machine: make inputs/download-logs
|
34
|
tail inputs/{.,}*/*/logs/*.r<revision>[.-]*log.sql
|
35
|
Check that every input's log ends in "Encountered 0 error(s)"
|
36
|
If many do not, fix the bug and discard the current (partial) import:
|
37
|
make schemas/public/reinstall
|
38
|
Otherwise, continue
|
39
|
Determine the import name:
|
40
|
bin/import_name inputs/{.,}*/*/logs/*.r<revision>[.-]*log.sql
|
41
|
Archive the last import: make schemas/rename/public.<import_name>
|
42
|
Delete previous imports so they won't bloat the full DB backup:
|
43
|
make backups/vegbien.<version>.backup/remove
|
44
|
make backups/TNRS.backup-remake &
|
45
|
make backups/vegbien.<version>.backup/test &
|
46
|
env public=public.<version> bin/export_analytical_db &
|
47
|
make backups/upload
|
48
|
On jupiter:
|
49
|
cd /data/dev/aaronmk/VegBIEN.backups
|
50
|
For each newly-archived backup:
|
51
|
make <backup>.md5/test
|
52
|
Check that "OK" is printed next to the filename
|
53
|
On nimoy:
|
54
|
cd /home/bien/svn/
|
55
|
svn up
|
56
|
make backups/analytical_aggregate.public.<version>.csv/download
|
57
|
make backups/analytical_aggregate.public.<version>.csv.md5/test
|
58
|
Check that "OK" is printed next to the filename
|
59
|
In the bien_web DB:
|
60
|
Create the analytical_aggregate_r<revision> table using its schema
|
61
|
in schemas/vegbien.my.sql
|
62
|
env table=analytical_aggregate_r<revision> bin/publish_analytical_db \
|
63
|
backups/analytical_aggregate.public.<version>.csv
|
64
|
If desired, record the import times in inputs/import.stats.xls:
|
65
|
Open inputs/import.stats.xls
|
66
|
Insert a copy of the leftmost Column-based column group before it
|
67
|
Update the import date in the upper-right corner
|
68
|
./bin/import_times inputs/{.,}*/*/logs/*.r<revision>[.-]*log.sql
|
69
|
Paste the output over the # Rows/Time columns, making sure that the
|
70
|
row counts match up with the previous import's row counts
|
71
|
If the row counts do not match up, insert or reorder rows as needed
|
72
|
until they do
|
73
|
Commit: svn ci -m "inputs/import.stats.xls: Updated import times"
|
74
|
To remake analytical DB: env public=... bin/make_analytical_db &
|
75
|
public should be set to the current import's schema name
|
76
|
To view progress:
|
77
|
tail -f inputs/analytical_db/logs/make_analytical_db.log.sql
|
78
|
|
79
|
Backups:
|
80
|
Archived imports:
|
81
|
Back up: make backups/public.<date>.backup &
|
82
|
Note: To back up the last import, you must archive it first:
|
83
|
make schemas/rotate
|
84
|
Test: make backups/public.<date>.backup/test &
|
85
|
Restore: make backups/public.<date>.backup/restore &
|
86
|
Remove: make backups/public.<date>.backup/remove
|
87
|
Download: make backups/download
|
88
|
TNRS cache:
|
89
|
Back up: make backups/TNRS.backup-remake &
|
90
|
Restore:
|
91
|
yes|make inputs/.TNRS/uninstall
|
92
|
make backups/TNRS.backup/restore &
|
93
|
yes|make schemas/public/reinstall
|
94
|
Must come after TNRS restore to recreate tnrs_input_name view
|
95
|
Full DB:
|
96
|
Back up: make backups/vegbien.<date>.backup &
|
97
|
Test: make backups/vegbien.<date>.backup/test &
|
98
|
Restore: make backups/vegbien.<date>.backup/restore &
|
99
|
Download: make backups/download
|
100
|
Import logs:
|
101
|
Download: make inputs/download-logs
|
102
|
|
103
|
Datasource setup:
|
104
|
Add a new datasource: make inputs/<datasrc>/add
|
105
|
<datasrc> may not contain spaces, and should be abbreviated.
|
106
|
If the datasource is a herbarium, <datasrc> should be the herbarium code
|
107
|
as defined by the Index Herbariorum <http://sweetgum.nybg.org/ih/>
|
108
|
For MySQL inputs (exports and live DB connections):
|
109
|
For .sql exports:
|
110
|
Place the original .sql file in _src/ (*not* in _MySQL/)
|
111
|
Create a database for the MySQL export in phpMyAdmin
|
112
|
mysql -p database <inputs/<datasrc>/_src/export.sql
|
113
|
mkdir inputs/<datasrc>/_MySQL/
|
114
|
cp -p lib/MySQL.{data,schema}.sql.make inputs/<datasrc>/_MySQL/
|
115
|
Edit _MySQL/*.make for the DB connection
|
116
|
For a .sql export, use your local MySQL DB
|
117
|
Install the export according to Install the staging tables below
|
118
|
Add input data for each table present in the datasource:
|
119
|
For .sql exports, you must use the name of the table in the DB export
|
120
|
For CSV files, you can use any name. It's recommended to use a table
|
121
|
name from <https://projects.nceas.ucsb.edu/nceas/projects/bien/wiki/VegCSV#Suggested-table-names>
|
122
|
Note that if this table will be joined together with another table, its
|
123
|
name must end in ".src"
|
124
|
make inputs/<datasrc>/<table>/add
|
125
|
Important: DO NOT just create an empty directory named <table>!
|
126
|
This command also creates necessary subdirs, such as logs/.
|
127
|
If the table is in a .sql export: make inputs/<datasrc>/<table>/install
|
128
|
Otherwise, place the CSV(s) for the table in
|
129
|
inputs/<datasrc>/<table>/ OR place a query joining other tables
|
130
|
together in inputs/<datasrc>/<table>/create.sql
|
131
|
Important: When exporting relational databases to CSVs, you MUST ensure
|
132
|
that embedded quotes are escaped by doubling them, *not* by
|
133
|
preceding them with a "\" as is the default in phpMyAdmin
|
134
|
If there are multiple part files for a table, and the header is repeated
|
135
|
in each part, make sure each header is EXACTLY the same.
|
136
|
(If the headers are not the same, the CSV concatenation script
|
137
|
assumes the part files don't have individual headers and treats the
|
138
|
subsequent headers as data rows.)
|
139
|
Add <table> to inputs/<datasrc>/import_order.txt before other tables
|
140
|
that depend on it
|
141
|
Install the staging tables:
|
142
|
make inputs/<datasrc>/reinstall quiet=1 &
|
143
|
To view progress: tail -f inputs/<datasrc>/<table>/logs/install.log.sql
|
144
|
View the logs: tail -n +1 inputs/<datasrc>/*/logs/install.log.sql
|
145
|
tail provides a header line with the filename
|
146
|
+1 starts at the first line, to show the whole file
|
147
|
For every file with an error 'column "..." specified more than once':
|
148
|
Add a header override file "+header.<ext>" in <table>/:
|
149
|
Note: The leading "+" should sort it before the flat files.
|
150
|
"_" unfortunately sorts *after* capital letters in ASCII.
|
151
|
Create a text file containing the header line of the flat files
|
152
|
Add an ! at the beginning of the line
|
153
|
This signals cat_csv that this is a header override.
|
154
|
For empty names, use their 0-based column # (by convention)
|
155
|
For duplicate names, add a distinguishing suffix
|
156
|
For long names that collided, rename them to <= 63 chars long
|
157
|
Do NOT make readability changes in this step; that is what the
|
158
|
map spreadsheets (below) are for.
|
159
|
Save
|
160
|
If you made any changes, re-run the install command above
|
161
|
Auto-create the map spreadsheets: make inputs/<datasrc>/
|
162
|
Map each table's columns:
|
163
|
In each <table>/ subdir, for each "via map" map.csv:
|
164
|
Open the map in a spreadsheet editor
|
165
|
Open the "core map" /mappings/Veg+-VegBIEN.csv
|
166
|
In each row of the via map, set the right column to a value from the
|
167
|
left column of the core map
|
168
|
Save
|
169
|
Regenerate the derived maps: make inputs/<datasrc>/
|
170
|
Accept the test cases:
|
171
|
make inputs/<datasrc>/test
|
172
|
When prompted to "Accept new test output", enter y and press ENTER
|
173
|
If you instead get errors, do one of the following for each one:
|
174
|
- If the error was due to a bug, fix it
|
175
|
- Add a SQL function that filters or transforms the invalid data
|
176
|
- Make an empty mapping for the columns that produced the error.
|
177
|
Put something in the Comments column of the map spreadsheet to
|
178
|
prevent the automatic mapper from auto-removing the mapping.
|
179
|
When accepting tests, it's helpful to use WinMerge
|
180
|
(see WinMerge setup below for configuration)
|
181
|
make inputs/<datasrc>/test by_col=1
|
182
|
If you get errors this time, this always indicates a bug, usually in
|
183
|
the VegBIEN unique constraints or column-based import itself
|
184
|
Add newly-created files: make inputs/<datasrc>/add
|
185
|
Commit: svn ci -m "Added inputs/<datasrc>/" inputs/<datasrc>/
|
186
|
Update vegbiendev:
|
187
|
On vegbiendev: svn up
|
188
|
On local machine: make inputs/upload
|
189
|
On vegbiendev:
|
190
|
Follow the steps under Install the staging tables above
|
191
|
make inputs/<datasrc>/test
|
192
|
|
193
|
Datasource refreshing:
|
194
|
VegBank:
|
195
|
make inputs/VegBank/vegbank.sql-remake
|
196
|
make inputs/VegBank/reinstall quiet=1 &
|
197
|
|
198
|
Schema changes:
|
199
|
Remember to update the following files with any renamings:
|
200
|
schemas/filter_ERD.csv
|
201
|
mappings/VegCore-VegBIEN.csv
|
202
|
mappings/verify.*.sql
|
203
|
Regenerate schema from installed DB: make schemas/remake
|
204
|
Reinstall DB from schema: make schemas/reinstall
|
205
|
WARNING: This will delete the current public schema of your VegBIEN DB!
|
206
|
Reinstall staging tables: . bin/reinstall_all
|
207
|
Sync ERD with vegbien.sql schema:
|
208
|
Run make schemas/vegbien.my.sql
|
209
|
Open schemas/vegbien.ERD.mwb in MySQLWorkbench
|
210
|
Go to File > Export > Synchronize With SQL CREATE Script...
|
211
|
For Input File, select schemas/vegbien.my.sql
|
212
|
Click Continue
|
213
|
In the changes list, select each table with an arrow next to it
|
214
|
Click Update Model
|
215
|
Click Continue
|
216
|
Note: The generated SQL script will be empty because we are syncing in
|
217
|
the opposite direction
|
218
|
Click Execute
|
219
|
Reposition any lines that have been reset
|
220
|
Add any new tables by dragging them from the Catalog in the left sidebar
|
221
|
to the diagram
|
222
|
Remove any deleted tables by right-clicking the table's diagram element,
|
223
|
selecting Delete '<table name>', and clicking Delete
|
224
|
Save
|
225
|
If desired, update the graphical ERD exports (see below)
|
226
|
Update graphical ERD exports:
|
227
|
Go to File > Export > Export as PNG...
|
228
|
Select schemas/vegbien.ERD.png and click Save
|
229
|
Go to File > Export > Export as SVG...
|
230
|
Select schemas/vegbien.ERD.svg and click Save
|
231
|
Go to File > Export > Export as Single Page PDF...
|
232
|
Select schemas/vegbien.ERD.1_pg.pdf and click Save
|
233
|
Go to File > Print...
|
234
|
In the lower left corner, click PDF > Save as PDF...
|
235
|
Set the Title and Author to ""
|
236
|
Select schemas/vegbien.ERD.pdf and click Save
|
237
|
Refactoring tips:
|
238
|
To rename a table:
|
239
|
In vegbien.sql, do the following:
|
240
|
Replace regexp (?<=_|\b)<old>(?=_|\b) with <new>
|
241
|
This is necessary because the table name is *everywhere*
|
242
|
Search for <new>
|
243
|
Manually change back any replacements inside comments
|
244
|
To rename a column:
|
245
|
Rename the column: ALTER TABLE <table> RENAME <old> TO <new>;
|
246
|
Recreate any foreign key for the column, removing CONSTRAINT <name>
|
247
|
This resets the foreign key name using the new column name
|
248
|
Creating a poster of the ERD:
|
249
|
Determine the poster size:
|
250
|
Measure the line height (from the bottom of one line to the bottom
|
251
|
of another): 16.3cm/24 lines = 0.679cm
|
252
|
Measure the height of the ERD: 35.4cm*2 = 70.8cm
|
253
|
Zoom in as far as possible
|
254
|
Measure the height of a capital letter: 3.5mm
|
255
|
Measure the line height: 8.5mm
|
256
|
Calculate the text's fraction of the line height: 3.5mm/8.5mm = 0.41
|
257
|
Calculate the text height: 0.679cm*0.41 = 0.28cm
|
258
|
Calculate the text height's fraction of the ERD height:
|
259
|
0.28cm/70.8cm = 0.0040
|
260
|
Measure the text height on the *VegBank* ERD poster: 5.5mm = 0.55cm
|
261
|
Calculate the VegBIEN poster height to make the text the same size:
|
262
|
0.55cm/0.0040 = 137.5cm H; *1in/2.54cm = 54.1in H
|
263
|
The ERD aspect ratio is 11 in W x (2*8.5in H) = 11x17 portrait
|
264
|
Calculate the VegBIEN poster width: 54.1in H*11W/17H = 35.0in W
|
265
|
The minimum VegBIEN poster size is 35x54in portrait
|
266
|
Determine the cost:
|
267
|
The FedEx Kinkos near NCEAS (1030 State St, Santa Barbara, CA 93101)
|
268
|
charges the following for posters:
|
269
|
base: $7.25/sq ft
|
270
|
lamination: $3/sq ft
|
271
|
mounting on a board: $8/sq ft
|
272
|
|
273
|
Testing:
|
274
|
Mapping process: make test
|
275
|
Including column-based import: make test by_col=1
|
276
|
If the row-based and column-based imports produce different inserted
|
277
|
row counts, this usually means that a table is underconstrained
|
278
|
(the unique indexes don't cover all possible rows).
|
279
|
This can occur if you didn't use COALESCE(field, null_value) around
|
280
|
a nullable field in a unique index. See sql_gen.null_sentinels for
|
281
|
the appropriate null value to use.
|
282
|
Map spreadsheet generation: make remake
|
283
|
Missing mappings: make missing_mappings
|
284
|
Everything (for most complete coverage): make test-all
|
285
|
|
286
|
WinMerge setup:
|
287
|
Install WinMerge from <http://winmerge.org/>
|
288
|
Open WinMerge
|
289
|
Go to Edit > Options and click Compare in the left sidebar
|
290
|
Enable "Moved block detection", as described at
|
291
|
<http://manual.winmerge.org/Configuration.html#d0e5892>.
|
292
|
Set Whitespace to Ignore change, as described at
|
293
|
<http://manual.winmerge.org/Configuration.html#d0e5758>.
|
294
|
|
295
|
Documentation:
|
296
|
To generate a Redmine-formatted list of steps for column-based import:
|
297
|
make inputs/ACAD/Specimen/logs/steps.by_col.log.sql
|
298
|
To import and scrub just the test taxonomic names:
|
299
|
inputs/test_taxonomic_names/test_scrub
|
300
|
|
301
|
General:
|
302
|
To see a program's description, read its top-of-file comment
|
303
|
To see a program's usage, run it without arguments
|
304
|
To remake a directory: make <dir>/remake
|
305
|
To remake a file: make <file>-remake
|