-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcropio_api_structure.sql
1534 lines (1357 loc) · 48.8 KB
/
cropio_api_structure.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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'postgis')
THEN
CREATE EXTENSION postgis;
RAISE NOTICE 'PostGIS extension created.';
ELSE
RAISE NOTICE 'PostGIS extension already exists.';
END IF;
END $$;
SET search_path TO [you schema there if need], public;
CREATE TABLE additional_objects (
id integer NOT NULL,
field_group_id integer,
name character varying(255),
object_type character varying(255),
calculated_area double precision,
administrative_area_name character varying(255),
subadministrative_area_name character varying(255),
locality character varying(255),
description text,
shape geography(Geometry,4326),
simplified_shape geography(Geometry,4326),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional json DEFAULT '{}'::json NOT NULL,
geometry_type character varying(255),
additional_info character varying(255),
geo_json text
);
ALTER TABLE additional_objects ADD PRIMARY KEY (id);
CREATE TABLE agri_work_plans (
id integer NOT NULL,
work_type character varying(255) NOT NULL,
work_subtype character varying(255),
status character varying(255) DEFAULT 'draft'::character varying NOT NULL,
season integer NOT NULL,
planned_start_date date NOT NULL,
planned_end_date date NOT NULL,
planned_water_rate double precision DEFAULT 0 NOT NULL,
additional_info character varying,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
responsible_person_id integer,
planned_row_spacing double precision,
planned_depth double precision,
planned_speed double precision,
planned_plant_spacing double precision,
work_type_id integer NOT NULL,
groupable_id integer NOT NULL,
groupable_type character varying
);
ALTER TABLE agri_work_plans ADD PRIMARY KEY (id);
CREATE TABLE agri_work_plan_application_mix_items (
id integer NOT NULL,
agri_work_plan_id integer NOT NULL,
applicable_id integer NOT NULL,
applicable_type character varying(255) NOT NULL,
rate double precision DEFAULT 0 NOT NULL,
amount double precision DEFAULT 0 NOT NULL,
additional_info character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE agri_work_plan_application_mix_items ADD PRIMARY KEY (id);
CREATE TABLE agro_operations (
id integer NOT NULL,
field_id integer,
planned_start_date date,
planned_end_date date,
operation_type character varying(255),
operation_subtype character varying(255),
work_type_id integer,
status character varying(255),
actual_start_datetime timestamp without time zone,
completed_datetime timestamp without time zone,
harvested_weight double precision,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
covered_area_by_track double precision,
machine_work_area double precision,
calculated_work_area_updated_at timestamp without time zone,
additional_info character varying,
season integer NOT NULL,
planned_area double precision DEFAULT 0 NOT NULL,
completed_area double precision DEFAULT 0 NOT NULL,
agri_work_plan_id integer,
planned_water_rate double precision DEFAULT 0 NOT NULL,
fact_water_rate double precision DEFAULT 0 NOT NULL,
agri_work_id integer,
operation_number character varying,
covered_area_hourly json DEFAULT '{}'::json NOT NULL,
planned_row_spacing double precision,
planned_depth double precision,
planned_speed double precision,
custom_name character varying,
planned_plant_spacing double precision,
external_id character varying(255),
fuel_consumption double precision DEFAULT 0 NOT NULL,
fuel_consumption_per_ha double precision DEFAULT 0 NOT NULL
);
ALTER TABLE agro_operations ADD PRIMARY KEY (id);
CREATE TABLE application_mix_items (
id integer NOT NULL,
agro_operation_id integer NOT NULL,
applicable_id integer NOT NULL,
applicable_type character varying(255) NOT NULL,
planned_rate double precision DEFAULT 0 NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
fact_rate double precision DEFAULT 0 ,
planned_amount double precision DEFAULT 0 NOT NULL,
fact_amount double precision DEFAULT 0 NOT NULL
);
ALTER TABLE application_mix_items ADD PRIMARY KEY (id);
CREATE TABLE chemicals (
id integer NOT NULL,
name character varying(255) NOT NULL,
chemical_type character varying(255) NOT NULL,
units_of_measurement character varying(255) DEFAULT 'liter'::character varying NOT NULL,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional_info character varying(255),
archived boolean DEFAULT false,
external_id character varying(255)
);
ALTER TABLE chemicals ADD PRIMARY KEY (id);
CREATE TABLE crops (
id integer NOT NULL,
name character varying(255),
short_name character varying(255),
standard_name character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional_info character varying(255),
description text,
external_id character varying(255)
);
ALTER TABLE crops ADD PRIMARY KEY (id);
CREATE TABLE fertilizers (
id integer NOT NULL,
name character varying(255),
fertilizer_type character varying(255) DEFAULT 'granular'::character varying NOT NULL,
description text,
elements text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional_info character varying(255),
units_of_measurement character varying(255) DEFAULT 'kg'::character varying NOT NULL,
external_id character varying(255)
);
ALTER TABLE fertilizers ADD PRIMARY KEY (id);
CREATE TABLE field_groups (
id integer NOT NULL,
name character varying(255),
administrative_area_name character varying(255),
subadministrative_area_name character varying(255),
locality character varying(255),
description text,
additional_options text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
group_folder_id integer,
external_id character varying(255)
);
ALTER TABLE field_groups ADD PRIMARY KEY (id);
CREATE TABLE field_scout_report_threat_mapping_items (
id integer NOT NULL,
field_scout_report_id integer NOT NULL,
plant_threat_id integer,
point geography(Point,4326),
comment text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
threat_level character varying(255)
);
ALTER TABLE field_scout_report_threat_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE field_scout_reports (
id integer NOT NULL,
user_id integer NOT NULL,
field_id integer NOT NULL,
report_time timestamp without time zone NOT NULL,
growth_stage character varying(255),
photo1 character varying(255),
photo2 character varying(255),
photo3 character varying(255),
photo1_md5 character varying(255),
photo2_md5 character varying(255),
photo3_md5 character varying(255),
additional_info text,
created_by_user_at timestamp without time zone,
updated_by_user_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
growth_scale character varying(255),
photo1_lat double precision,
photo1_lon double precision,
photo2_lat double precision,
photo2_lon double precision,
photo3_lat double precision,
photo3_lon double precision,
risk_yield_decreasing boolean DEFAULT false NOT NULL,
scouting_task_id integer,
scout_report_template_id integer
);
ALTER TABLE field_scout_reports ADD PRIMARY KEY (id);
CREATE TABLE field_shapes (
id integer NOT NULL,
field_id integer,
start_time timestamp without time zone NOT NULL,
calculated_area double precision NOT NULL,
legal_area double precision,
tillable_area double precision,
simplified_shape text NOT NULL,
shape_simplified_geojson text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
end_time timestamp without time zone,
external_id character varying(255)
);
ALTER TABLE field_shapes ADD PRIMARY KEY (id);
CREATE TABLE fields (
id integer NOT NULL,
name character varying(255),
description text,
field_group_id integer,
calculated_area double precision DEFAULT 0 NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
administrative_area_name character varying(255),
subadministrative_area_name character varying(255),
locality character varying(255),
simplified_shape geography(MultiPolygon,4326),
legal_area double precision DEFAULT 0 NOT NULL,
tillable_area double precision DEFAULT 0 NOT NULL,
additional_info character varying(255),
current_shape_id integer,
external_id character varying(255)
);
ALTER TABLE fields ADD PRIMARY KEY (id);
CREATE TABLE group_folders (
id integer NOT NULL,
name character varying(255),
parent_id character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
external_id character varying(255)
);
ALTER TABLE group_folders ADD PRIMARY KEY (id);
CREATE TABLE harvest_weighings (
id integer NOT NULL,
machine_id integer NOT NULL,
field_id integer,
weighing_place_id integer NOT NULL,
departure_from_field_time timestamp without time zone,
weight double precision DEFAULT 0 NOT NULL,
weighing_time timestamp without time zone NOT NULL,
last_truck boolean DEFAULT false NOT NULL,
additional_info character varying(255),
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
track_length double precision,
seed_moisture double precision,
seed_admixture double precision,
manually_set_track_length boolean DEFAULT false NOT NULL,
created_by_user_id integer,
brutto_weight double precision,
season integer NOT NULL,
external_id character varying(255)
);
ALTER TABLE harvest_weighings ADD PRIMARY KEY (id);
CREATE TABLE historical_values (
id integer NOT NULL,
field_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
year integer NOT NULL,
product_type character varying(255) NOT NULL,
value json DEFAULT '[]'::json NOT NULL
);
ALTER TABLE historical_values ADD PRIMARY KEY (id);
CREATE TABLE history_items (
id integer NOT NULL,
field_id integer,
year integer,
variety character varying(255),
productivity double precision,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
sowing_date date,
harvesting_date date,
active boolean DEFAULT true NOT NULL,
crop_id integer,
till_type character varying(255),
additional_info character varying,
harvested_weight double precision,
yield_density double precision,
expected_yield double precision,
grain_class character varying,
grain_humidity double precision,
grain_garbage_admixture double precision,
external_id character varying(255)
);
ALTER TABLE history_items ADD PRIMARY KEY (id);
CREATE TABLE implements (
id integer NOT NULL,
manufacturer character varying(255),
model character varying(255),
name character varying(255),
year integer,
description text,
implement_type character varying(255),
registration_number character varying(255),
inventory_number character varying(255),
additional text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
chassis_serial_number character varying(255),
legal_company character varying(255),
width double precision,
official_width double precision,
additional_info character varying(255),
avatar_id integer,
min_width double precision,
max_width double precision,
variable_width boolean DEFAULT false NOT NULL,
external_id character varying(255)
);
ALTER TABLE implements ADD PRIMARY KEY (id);
CREATE TABLE machine_groups (
id integer NOT NULL,
name character varying(255),
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional_info character varying(255)
);
ALTER TABLE machine_groups ADD PRIMARY KEY (id);
CREATE TABLE machine_task_agro_operation_mapping_items (
id integer NOT NULL,
machine_task_id integer NOT NULL,
agro_operation_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE machine_task_agro_operation_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE machine_tasks (
id integer NOT NULL,
machine_id integer,
start_time timestamp without time zone,
end_time timestamp without time zone,
action_type character varying(255),
driver_id integer,
implement_id integer,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
action_subtype character varying(255),
work_for_contractors boolean DEFAULT false,
work_for_land_owners boolean DEFAULT false,
real_implement_width double precision,
total_distance double precision DEFAULT 0 NOT NULL,
work_distance double precision DEFAULT 0 NOT NULL,
covered_area double precision DEFAULT 0 NOT NULL,
work_area double precision DEFAULT 0 NOT NULL,
covered_area_hourly json DEFAULT '[]'::json NOT NULL,
work_area_hourly json DEFAULT '[]'::json NOT NULL,
additional_info character varying(255),
total_distance_hourly json DEFAULT '[]'::json NOT NULL,
work_distance_hourly json DEFAULT '[]'::json NOT NULL,
work_duration integer DEFAULT 0,
work_duration_hourly json DEFAULT '[]'::json NOT NULL,
work_timetable json DEFAULT '[]'::json NOT NULL,
season integer NOT NULL,
work_type_id integer,
status character varying(255),
stops_on_road_duration integer DEFAULT 0,
stops_on_road_duration_hourly json DEFAULT '[]'::json NOT NULL,
stops_on_road_timetable json DEFAULT '[]'::json NOT NULL,
movements_on_road_duration integer DEFAULT 0,
movements_on_road_duration_hourly json DEFAULT '[]'::json NOT NULL,
movements_on_road_timetable json DEFAULT '[]'::json NOT NULL,
fuel_consumption double precision DEFAULT 0,
fuel_consumption_per_ha double precision DEFAULT 0,
fuel_consumption_on_road double precision DEFAULT 0,
fuel_consumption_on_road_average double precision DEFAULT 0
);
ALTER TABLE machine_tasks ADD PRIMARY KEY (id);
CREATE TABLE machines (
id integer NOT NULL,
manufacturer character varying(255),
model character varying(255),
name character varying(255),
year integer,
description text,
machine_subtype character varying(255),
engine_power integer,
fuel_type character varying(255),
fuel_tank_size double precision,
fuel_consumption_norm double precision,
registration_number character varying(255),
inventory_number character varying(255),
chassis_serial_number character varying(255),
engine_serial_number character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
machine_group_id integer,
machine_type character varying(255),
legal_company character varying(255),
default_implement_id integer,
additional_info character varying(255),
avatar_id integer,
external_id character varying(255),
phone_number character varying(255)
);
ALTER TABLE machines ADD PRIMARY KEY (id);
CREATE TABLE notes (
id integer NOT NULL,
user_id integer NOT NULL,
notable_id integer NOT NULL,
notable_type character varying NOT NULL,
title character varying NOT NULL,
description text,
photo1 character varying,
photo2 character varying,
photo3 character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
created_by_user_at timestamp without time zone,
updated_by_user_at timestamp without time zone,
photo1_md5 character varying,
photo2_md5 character varying,
photo3_md5 character varying
);
ALTER TABLE notes ADD PRIMARY KEY (id);
CREATE TABLE plant_threats (
id integer NOT NULL,
name character varying NOT NULL,
code character varying,
threat_type character varying NOT NULL,
image1 character varying,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
image2 character varying,
image3 character varying
);
ALTER TABLE plant_threats ADD PRIMARY KEY (id);
CREATE TABLE satellite_images (
id integer NOT NULL,
item_type character varying(255) NOT NULL,
item_id integer NOT NULL,
image_type character varying(255),
md5 character varying(255),
date date,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
size integer
);
ALTER TABLE satellite_images ADD PRIMARY KEY (id);
CREATE TABLE seeds (
id integer NOT NULL,
name character varying(255),
crop_id integer,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
additional_info character varying(255),
units_of_measurement character varying(255) DEFAULT 'pieces'::character varying NOT NULL,
variety character varying,
reproduction_number integer,
external_id character varying(255)
);
ALTER TABLE seeds ADD PRIMARY KEY (id);
CREATE TABLE users (
id integer NOT NULL,
email character varying DEFAULT ''::character varying NOT NULL,
current_sign_in_at timestamp without time zone,
last_sign_in_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
username character varying,
admin boolean,
mobile_phone character varying,
"position" character varying,
description text,
language character varying,
time_zone character varying DEFAULT 'UTC'::character varying NOT NULL,
yield_units character varying,
avatar character varying,
driver boolean DEFAULT false NOT NULL,
dispatcher boolean DEFAULT false NOT NULL,
additional_info character varying,
status character varying DEFAULT 'user'::character varying NOT NULL,
units_table json DEFAULT '{"length":"km","area":"ha","weight":"tonn","machinery_weight":"kg","volume":"liter","tank_volume":"liter","productivity":"centner_per_ha","speed":"km_per_hour","temperature":"celsius","precipitation_level":"mm","water_rate":"liter_per_ha","fuel_consumption":"liter_per_100km","short_length":"m","depth":"cm","row_spacing":"cm","plant_spacing":"cm"}'::json,
external_id character varying(255),
rfid character varying(255)
);
ALTER TABLE users ADD PRIMARY KEY (id);
CREATE TABLE user_roles (
id integer NOT NULL,
name character varying(255) NOT NULL,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE user_roles ADD PRIMARY KEY (id);
CREATE TABLE user_role_assignments (
id integer NOT NULL,
user_id integer NOT NULL,
user_role_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE user_role_assignments ADD PRIMARY KEY (id);
CREATE TABLE user_role_permissions (
id integer NOT NULL,
user_role_id integer,
access_level character varying(255),
access_for character varying(255),
subject_type character varying(255),
subject_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
ALTER TABLE user_role_permissions ADD PRIMARY KEY (id);
CREATE TABLE weather_history_items (
id integer NOT NULL,
date character varying(255),
temperature_min decimal,
temperature_avg decimal,
temperature_max decimal,
precipitation decimal,
snow decimal,
field_group_id integer
);
ALTER TABLE weather_history_items ADD PRIMARY KEY (id);
CREATE TABLE avatars (
id integer NOT NULL,
avatar_type character varying(255),
name character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE avatars ADD PRIMARY KEY (id);
CREATE TABLE versions (
id integer NOT NULL,
item_type character varying(255) NOT NULL,
item_id integer NOT NULL,
event character varying(255) NOT NULL,
whodunnit character varying,
snapshot_before_change character varying,
object_changes character varying,
created_at timestamp without time zone NOT NULL
);
ALTER TABLE versions ADD PRIMARY KEY (id);
CREATE TABLE work_records (
id integer NOT NULL,
user_id integer NOT NULL,
start_time timestamp without time zone NOT NULL,
end_time timestamp without time zone,
work_type character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE work_records ADD PRIMARY KEY (id);
CREATE TABLE work_record_machine_region_mapping_items (
id integer NOT NULL,
work_record_id integer NOT NULL,
machine_region_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE work_record_machine_region_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE work_type_groups (
id integer NOT NULL,
name character varying(255),
standard_name character varying(255),
description character varying,
external_id character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE work_type_groups ADD PRIMARY KEY (id);
CREATE TABLE work_types (
id integer NOT NULL,
work_type_group_id integer NOT NULL,
name character varying(255),
agri boolean DEFAULT false,
application boolean DEFAULT false,
sowing boolean DEFAULT false,
harvesting boolean DEFAULT false,
soil boolean DEFAULT false,
standard_name character varying(255),
hidden boolean DEFAULT false,
description character varying,
external_id character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE work_types ADD PRIMARY KEY (id);
CREATE TABLE machine_task_field_mapping_items (
id integer NOT NULL,
machine_task_id integer NOT NULL,
field_id integer NOT NULL,
covered_area double precision DEFAULT 0 NOT NULL,
work_area double precision DEFAULT 0 NOT NULL,
covered_area_hourly json DEFAULT '[]'::json NOT NULL,
work_area_hourly json DEFAULT '[]'::json NOT NULL,
work_distance double precision DEFAULT 0 NOT NULL,
work_distance_hourly json DEFAULT '[]'::json NOT NULL,
work_duration double precision DEFAULT 0 NOT NULL,
work_duration_hourly json DEFAULT '[]'::json NOT NULL,
work_timetable json DEFAULT '[]'::json NOT NULL,
manually_defined_covered_area double precision DEFAULT 0 NOT NULL,
covered_area_by_track double precision DEFAULT 0 NOT NULL,
covered_area_by_track_hourly json DEFAULT '[]'::json NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
stops_timetable json DEFAULT '[]'::json NOT NULL,
stops_duration double precision DEFAULT 0 NOT NULL,
stops_duration_hourly json DEFAULT '[]'::json NOT NULL,
fuel_consumption double precision DEFAULT 0,
fuel_consumption_per_ha double precision DEFAULT 0,
manually_defined_fuel_consumption double precision DEFAULT 0
);
ALTER TABLE machine_task_field_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE alert_types (
id integer NOT NULL,
alert_type character varying(255),
name character varying(255),
priority character varying(255),
description character varying,
additional_info character varying,
archived boolean DEFAULT false,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE alert_types ADD PRIMARY KEY (id);
CREATE TABLE alerts (
id integer NOT NULL,
alert_type_id integer NOT NULL,
alertable_id integer NOT NULL,
event_start_time timestamp without time zone NOT NULL,
status character varying(255),
description character varying,
responsible_person_id integer,
created_by_user_id integer,
event_stop_time timestamp without time zone,
alert_closed_at timestamp without time zone,
alertable_type character varying(255),
automatic_alert_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE alerts ADD PRIMARY KEY (id);
CREATE TABLE machine_regions (
id integer NOT NULL,
name character varying(255),
ancestry character varying,
description character varying,
additional_info character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE machine_regions ADD PRIMARY KEY (id);
CREATE TABLE machine_region_mapping_items (
id integer NOT NULL,
machine_id integer NOT NULL,
machine_region_id integer NOT NULL,
date_start date NOT NULL,
date_end date,
no_date_end boolean DEFAULT false,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE machine_region_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE implement_region_mapping_items (
id integer NOT NULL,
implement_id integer NOT NULL,
machine_region_id integer NOT NULL,
date_start date NOT NULL,
date_end date,
no_date_end boolean DEFAULT false,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE implement_region_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE inventory_history_items (
id integer NOT NULL,
historyable_id integer NOT NULL,
historyable_type character varying,
event_start_at timestamp without time zone NOT NULL,
reason character varying(255),
description character varying,
available boolean DEFAULT true,
hidden boolean DEFAULT false,
event_end_at timestamp without time zone,
external_id character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE inventory_history_items ADD PRIMARY KEY (id);
CREATE TABLE automatic_alerts (
id integer NOT NULL,
alert_type_id integer NOT NULL,
automatic_alert_type character varying(255),
automatic_alert_subtype character varying(255),
name character varying(255),
active boolean DEFAULT false,
description character varying,
alert_settings json DEFAULT '{}'::json NOT NULL,
scheduled boolean DEFAULT false,
schedule_start_time timestamp without time zone,
schedule_end_time timestamp without time zone,
time_zone character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE automatic_alerts ADD PRIMARY KEY (id);
CREATE TABLE photos (
id integer NOT NULL,
photoable_id integer NOT NULL,
photoable_type character varying(255),
name character varying(255),
photo json DEFAULT '{}'::json NOT NULL,
description text,
md5 character varying,
file_size integer,
longitude double precision,
latitude double precision,
altitude double precision,
image_direction integer,
created_by_user_at timestamp without time zone NOT NULL,
additional_info character varying,
external_id character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE photos ADD PRIMARY KEY (id);
CREATE TABLE soil_tests (
id integer NOT NULL,
field_id integer NOT NULL,
made_at date NOT NULL,
elements text,
description text,
attached_file character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE soil_tests ADD PRIMARY KEY (id);
CREATE TABLE soil_test_samples (
id integer NOT NULL,
soil_test_id integer NOT NULL,
lonlat geography(Point,4326),
elements json DEFAULT '{}'::json,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE soil_test_samples ADD PRIMARY KEY (id);
CREATE TABLE maintenance_types
(
id integer NOT NULL,
maintenance_type_group_id integer NOT NULL,
name character varying,
standard_name character varying,
external_id character varying,
hidden boolean NOT NULL DEFAULT false,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE maintenance_types ADD PRIMARY KEY (id);
CREATE TABLE maintenance_type_groups
(
id integer NOT NULL,
name character varying,
standard_name character varying,
external_id character varying,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE maintenance_type_groups ADD PRIMARY KEY (id);
CREATE TABLE maintenance_records
(
id integer NOT NULL,
maintainable_id integer NOT NULL,
maintainable_type character varying(255) NOT NULL,
start_time timestamp without time zone NOT NULL,
end_time timestamp without time zone NOT NULL,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
repair_stage character varying,
mileage integer,
motohours integer,
status character varying NOT NULL DEFAULT 'planned'::character varying,
maintenance_plan_id integer
);
ALTER TABLE maintenance_records ADD PRIMARY KEY (id);
CREATE TABLE maintenance_record_rows
(
id integer NOT NULL,
maintenance_record_id integer NOT NULL,
maintenance_type_id integer NOT NULL,
repair_stage text,
description text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE maintenance_record_rows ADD PRIMARY KEY (id);
CREATE TABLE spare_part_manufacturers
(
id integer NOT NULL,
name character varying NOT NULL,
external_id character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE spare_part_manufacturers ADD PRIMARY KEY (id);
CREATE TABLE spare_parts
(
id integer NOT NULL,
spare_part_manufacturer_id bigint NOT NULL,
name character varying NOT NULL,
part_number character varying NOT NULL,
description text,
external_id character varying,
additional_info character varying,
archived boolean NOT NULL DEFAULT false,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE spare_parts ADD PRIMARY KEY (id);
CREATE TABLE maintenance_plan_row_spare_part_mapping_items
(
id integer NOT NULL,
maintenance_plan_row_id bigint NOT NULL,
spare_part_id bigint NOT NULL,
quantity integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE maintenance_plan_row_spare_part_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE maintenance_record_row_spare_part_mapping_items
(
id integer NOT NULL,
maintenance_record_row_id bigint NOT NULL,
spare_part_id bigint NOT NULL,
quantity integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
ALTER TABLE maintenance_record_row_spare_part_mapping_items ADD PRIMARY KEY (id);
CREATE TABLE maintenance_plans
(
id integer NOT NULL,
plan_type character varying NOT NULL,
name text NOT NULL,
description text,
external_id character varying,
settings jsonb DEFAULT '{}'::jsonb,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
responsible_id integer
);
ALTER TABLE maintenance_plans ADD PRIMARY KEY (id);
CREATE TABLE maintenance_plan_rows
(
id integer NOT NULL,
maintenance_plan_id integer NOT NULL,
maintenance_type_id integer NOT NULL,
mileage integer,
motohours integer,
"interval" integer,
description text,
external_id character varying,
created_at timestamp without time zone NOT NULL,