-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.sql
457 lines (427 loc) · 7.15 KB
/
migrate.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.agrotechnology;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.agrotechnology
(SELECT
agrotechnology_ID,
nameCZ,
nameEN,
descriptionCZ,
descriptionEN,
managTyp,
note,
NULL
FROM agrotechnologies);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.assignment_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.assignment_type
(SELECT
assignmentType_ID as id,
descriptionCZ as description_cz,
descriptionEN as description_en
FROM assignmenttypes);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.crop_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.crop_type
(SELECT
cropType_ID as id,
nameCZ as name_cz,
nameEN as name_en,
descriptionCZ as description_cz,
descriptionEN as description_en
FROM croptypes);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.crop_er_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.crop_er_type
(SELECT
cropErType_ID,
nameCZ,
nameEN
FROM cropertypes);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.crop;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.crop
(SELECT
crop_ID,
cropType_ID,
cropErType_ID,
nameCZ,
nameEN,
variety,
isCatchCrop,
descriptionCZ,
descriptionEN
FROM crops);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.organization;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.organization
(SELECT
organization_ID,
`name`,
contactPerson,
contactNumber,
contactEmail,
nameCode
FROM organizations);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.wrb_soil_class;
SET FOREIGN_KEY_CHECKS=0;
INSERT IGNORE INTO rainsimulator.wrb_soil_class (
SELECT
WRBclass_ID,
WRBclassName,
WRBclassCode
FROM wrbsoilclasses
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.locality;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.locality (
SELECT
locality_ID,
organization_ID,
WRBclass_ID,
`name`,
ST_X(location),
ST_Y(location),
descriptionCZ,
descriptionEN
FROM localities
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.plot;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.plot (
SELECT
plot_ID,
locality_ID,
soilOrigin_ID,
crop_ID,
agrotechnology_ID,
`name`,
established,
plotWidth,
plotLength,
plotSlope,
noteCZ,
noteEN
FROM plots
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.project;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.project (
SELECT
project_ID,
projectName,
descriptionCZ,
descriptionEN,
fundingAgency,
projectCode
FROM
projects
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.operation_intensity;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.operation_intensity (
SELECT
operationIntensity_ID,
descriptionCZ,
descriptionEN
FROM
operationintensities
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.operation_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.operation_type (
SELECT
operationType_ID,
descriptionCZ,
descriptionEN
FROM
operationtypes
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.operation;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.operation (
SELECT
operation_ID,
operationIntensity_ID,
operationType_ID,
nameCZ,
nameEN,
operationDepth_m,
descriptionCZ,
descriptionEN,
machineryTypeCZ,
machineryTypeEN
FROM
operations
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.simulator;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.simulator (
SELECT
simulator_ID,
organization_ID,
nameCZ,
nameEN,
descriptionCZ,
descriptionEN,
reference
FROM
simulators
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.soil_sample;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.soil_sample (
SELECT
soilSample_ID,
processedAt_ID,
plot_ID,
WRBclass_ID,
locality_ID,
run_ID,
Corg,
bulkDensity,
moisture,
dateSampled,
sampleLocation,
descriptionCZ,
descriptionEN,
sampleDepth_m,
dateProcessed,
texture,
rawDataPath
FROM
soilsamples
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.sequence;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.sequence (
SELECT
sequence_ID,
simulator_ID,
plot_ID,
surfaceCover,
date,
cropBBCH,
CropConditionCZ,
CropConditionEN
FROM
sequences
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.unit;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.unit (
SELECT
unit_ID,
3,
nameCZ,
nameEN,
unit,
descriptionCZ,
descriptionEN
FROM
units
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.run_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.run_type (
SELECT
runType_ID,
runTypeCZ,
runTypeEN,
descriptionCZ,
descriptionEN
FROM
runtypes
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.run;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`run` (
SELECT
run_ID,
sequence_ID,
runType_ID,
soilSampleBulk_ID,
bulkAssignment_ID,
soilSampleTexture_ID,
textureAssignment_ID,
initMoisture,
rainIntensity,
datetime,
precedingPrecipitation,
runoffStart,
cropPictures,
plotPictures,
rawDataPath,
noteCZ,
noteEN,
pondingStart,
soilSampleCorg_ID,
CorgAssignment_ID
FROM
runs
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.measurement;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`measurement` (
SELECT
measurement_ID,
run_ID,
descriptionCZ,
descriptionEN,
noteCZ,
noteEN,
soilSample_ID,
phenomen_ID,
isTimeline
FROM
measurements
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.record_type;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`record_type` (
SELECT
recordType_ID,
recordTypeCZ,
recordTypeEN,
descriptionEN,
descriptionCZ
FROM
recordtypes
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.record;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`record` (
SELECT
record_ID,
measurement_ID,
recordType_ID,
unit_ID,
noteCZ,
noteEN,
relValX_unit_ID,
relValY_unit_ID,
relValZ_unit_ID
FROM
records
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.data;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`data` (
SELECT
data_ID,
record_ID,
time,
`value`,
relValX,
relValY,
relValZ
FROM
data
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.tillage_sequence;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`tillage_sequence` (
SELECT
tillage_ID,
agrotechnology_ID,
operation_ID,
date
FROM
tillagesequences
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.record_record;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`record_record` (
SELECT
record_ID,
derivedFrom_ID
FROM
record_record_relations
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.project_sequence;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`project_sequence` (
SELECT
project_ID,
sequence_ID
FROM
simulation_project_relations
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.project_organization;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`project_organization` (
SELECT
project_ID,
organization_ID
FROM
organization_project_relations
);
/*OK*/
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE TABLE rainsimulator.phenomenon;
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO rainsimulator.`phenomenon` (
SELECT
phenomen_ID,
nameCZ,
nameEN,
descriptionCZ,
descriptionEN,
parameterSet_model_ID,
phenomen_key
FROM
phenomena
);