-
Notifications
You must be signed in to change notification settings - Fork 154
/
structure.sql
17849 lines (11816 loc) · 458 KB
/
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
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.7
-- Dumped by pg_dump version 9.5.7
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: postgis; Type: SCHEMA; Schema: -; Owner: -
--
CREATE SCHEMA postgis;
SET search_path = public, pg_catalog;
--
-- Name: compute_outgoing_payment_list_cache(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION compute_outgoing_payment_list_cache() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
new_id INTEGER DEFAULT NULL;
old_id INTEGER DEFAULT NULL;
BEGIN
IF TG_OP <> 'DELETE' THEN
new_id := NEW.list_id;
END IF;
IF TG_OP <> 'INSERT' THEN
old_id := OLD.list_id;
END IF;
UPDATE outgoing_payment_lists
SET cached_payment_count = payments.count,
cached_total_sum = payments.total
FROM (
SELECT outgoing_payments.list_id AS list_id,
SUM(outgoing_payments.amount) AS total,
COUNT(outgoing_payments.id) AS count
FROM outgoing_payments
GROUP BY outgoing_payments.list_id
) AS payments
WHERE payments.list_id = id
AND ((new_id IS NOT NULL AND id = new_id)
OR (old_id IS NOT NULL AND id = old_id));
RETURN NEW;
END
$$;
--
-- Name: compute_partial_lettering(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION compute_partial_lettering() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
new_letter varchar DEFAULT NULL;
old_letter varchar DEFAULT NULL;
new_account_id integer DEFAULT NULL;
old_account_id integer DEFAULT NULL;
BEGIN
IF TG_OP <> 'DELETE' THEN
IF NEW.letter IS NOT NULL THEN
new_letter := substring(NEW.letter from '[A-z]*');
END IF;
IF NEW.account_id IS NOT NULL THEN
new_account_id := NEW.account_id;
END IF;
END IF;
IF TG_OP <> 'INSERT' THEN
IF OLD.letter IS NOT NULL THEN
old_letter := substring(OLD.letter from '[A-z]*');
END IF;
IF OLD.account_id IS NOT NULL THEN
old_account_id := OLD.account_id;
END IF;
END IF;
UPDATE journal_entry_items
SET letter = (CASE
WHEN modified_letter_groups.balance <> 0
THEN modified_letter_groups.letter || '*'
ELSE modified_letter_groups.letter
END)
FROM (SELECT new_letter AS letter,
account_id AS account_id,
SUM(debit) - SUM(credit) AS balance
FROM journal_entry_items
WHERE account_id = new_account_id
AND letter SIMILAR TO (COALESCE(new_letter, '') || '\*?')
AND new_letter IS NOT NULL
AND new_account_id IS NOT NULL
GROUP BY account_id
UNION ALL
SELECT old_letter AS letter,
account_id AS account_id,
SUM(debit) - SUM(credit) AS balance
FROM journal_entry_items
WHERE account_id = old_account_id
AND letter SIMILAR TO (COALESCE(old_letter, '') || '\*?')
AND old_letter IS NOT NULL
AND old_account_id IS NOT NULL
GROUP BY account_id) AS modified_letter_groups
WHERE modified_letter_groups.account_id = journal_entry_items.account_id
AND journal_entry_items.letter SIMILAR TO (modified_letter_groups.letter || '\*?');
RETURN NEW;
END;
$$;
--
-- Name: synchronize_jei_with_entry(); Type: FUNCTION; Schema: public; Owner: -
--
CREATE FUNCTION synchronize_jei_with_entry() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
synced_entry_id integer DEFAULT NULL;
BEGIN
IF TG_NARGS <> 0 THEN
IF TG_ARGV[0] = 'jei' THEN
synced_entry_id := NEW.entry_id;
END IF;
IF TG_ARGV[0] = 'entry' THEN
synced_entry_id := NEW.id;
END IF;
END IF;
UPDATE journal_entry_items AS jei
SET state = entries.state,
printed_on = entries.printed_on,
journal_id = entries.journal_id,
financial_year_id = entries.financial_year_id,
entry_number = entries.number,
real_currency = entries.real_currency,
real_currency_rate = entries.real_currency_rate
FROM journal_entries AS entries
WHERE jei.entry_id = synced_entry_id
AND entries.id = synced_entry_id
AND synced_entry_id IS NOT NULL
AND (jei.state <> entries.state
OR jei.printed_on <> entries.printed_on
OR jei.journal_id <> entries.journal_id
OR jei.financial_year_id <> entries.financial_year_id
OR jei.entry_number <> entries.number
OR jei.real_currency <> entries.real_currency
OR jei.real_currency_rate <> entries.real_currency_rate);
RETURN NEW;
END;
$$;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: account_balances; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE account_balances (
id integer NOT NULL,
account_id integer NOT NULL,
financial_year_id integer NOT NULL,
global_debit numeric(19,4) DEFAULT 0.0 NOT NULL,
global_credit numeric(19,4) DEFAULT 0.0 NOT NULL,
global_balance numeric(19,4) DEFAULT 0.0 NOT NULL,
global_count integer DEFAULT 0 NOT NULL,
local_debit numeric(19,4) DEFAULT 0.0 NOT NULL,
local_credit numeric(19,4) DEFAULT 0.0 NOT NULL,
local_balance numeric(19,4) DEFAULT 0.0 NOT NULL,
local_count integer DEFAULT 0 NOT NULL,
currency character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: account_balances_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE account_balances_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: account_balances_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE account_balances_id_seq OWNED BY account_balances.id;
--
-- Name: accounts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE accounts (
id integer NOT NULL,
number character varying NOT NULL,
name character varying NOT NULL,
label character varying NOT NULL,
debtor boolean DEFAULT false NOT NULL,
last_letter character varying,
description text,
reconcilable boolean DEFAULT false NOT NULL,
usages text,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
custom_fields jsonb
);
--
-- Name: accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE accounts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE accounts_id_seq OWNED BY accounts.id;
--
-- Name: activities; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activities (
id integer NOT NULL,
name character varying NOT NULL,
description text,
family character varying NOT NULL,
nature character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
with_supports boolean NOT NULL,
with_cultivation boolean NOT NULL,
support_variety character varying,
cultivation_variety character varying,
size_indicator_name character varying,
size_unit_name character varying,
suspended boolean DEFAULT false NOT NULL,
production_cycle character varying NOT NULL,
production_campaign character varying,
custom_fields jsonb,
use_countings boolean DEFAULT false NOT NULL,
use_gradings boolean DEFAULT false NOT NULL,
measure_grading_items_count boolean DEFAULT false NOT NULL,
measure_grading_net_mass boolean DEFAULT false NOT NULL,
grading_net_mass_unit_name character varying,
measure_grading_sizes boolean DEFAULT false NOT NULL,
grading_sizes_indicator_name character varying,
grading_sizes_unit_name character varying,
production_system_name character varying,
use_seasons boolean DEFAULT false,
use_tactics boolean DEFAULT false
);
--
-- Name: activity_budgets; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_budgets (
id integer NOT NULL,
activity_id integer NOT NULL,
campaign_id integer NOT NULL,
currency character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_productions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_productions (
id integer NOT NULL,
support_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
usage character varying NOT NULL,
size_value numeric(19,4) NOT NULL,
size_indicator_name character varying NOT NULL,
size_unit_name character varying,
activity_id integer NOT NULL,
cultivable_zone_id integer,
irrigated boolean DEFAULT false NOT NULL,
nitrate_fixing boolean DEFAULT false NOT NULL,
support_shape postgis.geometry(MultiPolygon,4326),
support_nature character varying,
started_on date,
stopped_on date,
state character varying,
rank_number integer NOT NULL,
campaign_id integer,
custom_fields jsonb,
season_id integer,
tactic_id integer
);
--
-- Name: campaigns; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE campaigns (
id integer NOT NULL,
name character varying NOT NULL,
description text,
harvest_year integer,
closed boolean DEFAULT false NOT NULL,
closed_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activities_campaigns; Type: VIEW; Schema: public; Owner: -
--
CREATE VIEW activities_campaigns AS
SELECT DISTINCT c.id AS campaign_id,
a.id AS activity_id
FROM (activities a
LEFT JOIN campaigns c ON ((((a.id, c.id) IN ( SELECT ab.activity_id,
ab.campaign_id
FROM activity_budgets ab
WHERE ((ab.campaign_id = c.id) AND (ab.activity_id = a.id)))) OR ((a.id, c.id) IN ( SELECT ap.activity_id,
ap.campaign_id
FROM activity_productions ap
WHERE ((ap.campaign_id = c.id) AND (ap.activity_id = a.id)))))));
--
-- Name: activities_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activities_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activities_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activities_id_seq OWNED BY activities.id;
--
-- Name: intervention_parameters; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE intervention_parameters (
id integer NOT NULL,
intervention_id integer NOT NULL,
product_id integer,
variant_id integer,
quantity_population numeric(19,4),
working_zone postgis.geometry(MultiPolygon,4326),
reference_name character varying NOT NULL,
"position" integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
event_participation_id integer,
outcoming_product_id integer,
type character varying,
new_container_id integer,
new_group_id integer,
new_variant_id integer,
quantity_handler character varying,
quantity_value numeric(19,4),
quantity_unit_name character varying,
quantity_indicator_name character varying,
group_id integer,
new_name character varying,
component_id integer,
assembly_id integer,
currency character varying,
unit_pretax_stock_amount numeric(19,4) DEFAULT 0.0 NOT NULL,
dead boolean DEFAULT false NOT NULL,
identification_number character varying
);
--
-- Name: interventions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE interventions (
id integer NOT NULL,
issue_id integer,
prescription_id integer,
procedure_name character varying NOT NULL,
state character varying NOT NULL,
started_at timestamp without time zone NOT NULL,
stopped_at timestamp without time zone NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
event_id integer,
number character varying,
description text,
working_duration integer NOT NULL,
whole_duration integer NOT NULL,
actions character varying,
custom_fields jsonb,
nature character varying NOT NULL,
request_intervention_id integer,
trouble_encountered boolean DEFAULT false NOT NULL,
trouble_description text,
accounted_at timestamp without time zone,
currency character varying,
journal_entry_id integer,
request_compliant boolean
);
--
-- Name: target_distributions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE target_distributions (
id integer NOT NULL,
target_id integer NOT NULL,
activity_production_id integer NOT NULL,
activity_id integer NOT NULL,
started_at timestamp without time zone,
stopped_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activities_interventions; Type: VIEW; Schema: public; Owner: -
--
CREATE VIEW activities_interventions AS
SELECT DISTINCT interventions.id AS intervention_id,
activities.id AS activity_id
FROM ((((activities
JOIN activity_productions ON ((activity_productions.activity_id = activities.id)))
JOIN target_distributions ON ((target_distributions.activity_production_id = activity_productions.id)))
JOIN intervention_parameters ON ((target_distributions.target_id = intervention_parameters.product_id)))
JOIN interventions ON ((intervention_parameters.intervention_id = interventions.id)))
ORDER BY interventions.id;
--
-- Name: activity_budget_items; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_budget_items (
id integer NOT NULL,
variant_id integer,
direction character varying NOT NULL,
amount numeric(19,4) DEFAULT 0.0,
unit_amount numeric(19,4) DEFAULT 0.0,
quantity numeric(19,4) DEFAULT 0.0,
variant_indicator character varying,
variant_unit character varying,
computation_method character varying NOT NULL,
currency character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
unit_population numeric(19,4),
unit_currency character varying NOT NULL,
activity_budget_id integer NOT NULL
);
--
-- Name: activity_budget_items_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_budget_items_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_budget_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_budget_items_id_seq OWNED BY activity_budget_items.id;
--
-- Name: activity_budgets_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_budgets_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_budgets_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_budgets_id_seq OWNED BY activity_budgets.id;
--
-- Name: activity_distributions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_distributions (
id integer NOT NULL,
activity_id integer NOT NULL,
affectation_percentage numeric(19,4) NOT NULL,
main_activity_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_distributions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_distributions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_distributions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_distributions_id_seq OWNED BY activity_distributions.id;
--
-- Name: activity_inspection_calibration_natures; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_inspection_calibration_natures (
id integer NOT NULL,
scale_id integer NOT NULL,
marketable boolean DEFAULT false NOT NULL,
minimal_value numeric(19,4) NOT NULL,
maximal_value numeric(19,4) NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_inspection_calibration_natures_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_inspection_calibration_natures_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_inspection_calibration_natures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_inspection_calibration_natures_id_seq OWNED BY activity_inspection_calibration_natures.id;
--
-- Name: activity_inspection_calibration_scales; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_inspection_calibration_scales (
id integer NOT NULL,
activity_id integer NOT NULL,
size_indicator_name character varying NOT NULL,
size_unit_name character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_inspection_calibration_scales_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_inspection_calibration_scales_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_inspection_calibration_scales_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_inspection_calibration_scales_id_seq OWNED BY activity_inspection_calibration_scales.id;
--
-- Name: activity_inspection_point_natures; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_inspection_point_natures (
id integer NOT NULL,
activity_id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
name character varying NOT NULL,
category character varying NOT NULL
);
--
-- Name: activity_inspection_point_natures_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_inspection_point_natures_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_inspection_point_natures_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_inspection_point_natures_id_seq OWNED BY activity_inspection_point_natures.id;
--
-- Name: activity_productions_campaigns; Type: VIEW; Schema: public; Owner: -
--
CREATE VIEW activity_productions_campaigns AS
SELECT DISTINCT c.id AS campaign_id,
ap.id AS activity_production_id
FROM ((activity_productions ap
JOIN activities a ON ((ap.activity_id = a.id)))
LEFT JOIN campaigns c ON (((c.id = ap.campaign_id) OR ((c.id IS NOT NULL) AND ((a.production_cycle)::text = 'perennial'::text) AND ((((a.production_campaign)::text = 'at_cycle_start'::text) AND (((ap.stopped_on IS NULL) AND ((c.harvest_year)::double precision >= date_part('year'::text, ap.started_on))) OR ((ap.stopped_on IS NOT NULL) AND (date_part('year'::text, ap.started_on) <= (c.harvest_year)::double precision) AND ((c.harvest_year)::double precision < date_part('year'::text, ap.stopped_on))))) OR (((a.production_campaign)::text = 'at_cycle_end'::text) AND (((ap.stopped_on IS NULL) AND ((c.harvest_year)::double precision > date_part('year'::text, ap.started_on))) OR ((ap.stopped_on IS NOT NULL) AND (date_part('year'::text, ap.started_on) < (c.harvest_year)::double precision) AND ((c.harvest_year)::double precision <= date_part('year'::text, ap.stopped_on))))))))))
ORDER BY c.id;
--
-- Name: activity_productions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_productions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_productions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_productions_id_seq OWNED BY activity_productions.id;
--
-- Name: activity_productions_interventions; Type: VIEW; Schema: public; Owner: -
--
CREATE VIEW activity_productions_interventions AS
SELECT DISTINCT interventions.id AS intervention_id,
target_distributions.activity_production_id
FROM (((activities
JOIN target_distributions ON ((target_distributions.activity_id = activities.id)))
JOIN intervention_parameters ON ((target_distributions.target_id = intervention_parameters.product_id)))
JOIN interventions ON ((intervention_parameters.intervention_id = interventions.id)))
ORDER BY interventions.id;
--
-- Name: activity_seasons; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_seasons (
id integer NOT NULL,
activity_id integer NOT NULL,
name character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_seasons_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_seasons_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_seasons_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_seasons_id_seq OWNED BY activity_seasons.id;
--
-- Name: activity_tactics; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE activity_tactics (
id integer NOT NULL,
activity_id integer NOT NULL,
name character varying NOT NULL,
planned_on date,
mode_delta integer,
mode character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: activity_tactics_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE activity_tactics_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: activity_tactics_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE activity_tactics_id_seq OWNED BY activity_tactics.id;
--
-- Name: affairs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE affairs (
id integer NOT NULL,
number character varying NOT NULL,
closed boolean DEFAULT false NOT NULL,
closed_at timestamp without time zone,
third_id integer NOT NULL,
currency character varying NOT NULL,
debit numeric(19,4) DEFAULT 0.0 NOT NULL,
credit numeric(19,4) DEFAULT 0.0 NOT NULL,
accounted_at timestamp without time zone,
journal_entry_id integer,
deals_count integer DEFAULT 0 NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
cash_session_id integer,
responsible_id integer,
dead_line_at timestamp without time zone,
name character varying,
description text,
pretax_amount numeric(19,4) DEFAULT 0.0,
origin character varying,
type character varying,
state character varying,
probability_percentage numeric(19,4) DEFAULT 0.0,
letter character varying
);
--
-- Name: affairs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE affairs_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: affairs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE affairs_id_seq OWNED BY affairs.id;
--
-- Name: alert_phases; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE alert_phases (
id integer NOT NULL,
alert_id integer NOT NULL,
started_at timestamp without time zone NOT NULL,
level integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: alert_phases_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE alert_phases_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: alert_phases_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE alert_phases_id_seq OWNED BY alert_phases.id;
--
-- Name: alerts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE alerts (
id integer NOT NULL,
sensor_id integer,
nature character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL
);
--
-- Name: alerts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE alerts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: alerts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE alerts_id_seq OWNED BY alerts.id;
--
-- Name: analyses; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE analyses (
id integer NOT NULL,
number character varying NOT NULL,
nature character varying NOT NULL,
reference_number character varying,
product_id integer,
sampler_id integer,
analyser_id integer,
description text,
geolocation postgis.geometry(Point,4326),
sampled_at timestamp without time zone NOT NULL,
analysed_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
creator_id integer,
updater_id integer,
lock_version integer DEFAULT 0 NOT NULL,
host_id integer,
sensor_id integer,
sampling_temporal_mode character varying DEFAULT 'instant'::character varying NOT NULL,
stopped_at timestamp without time zone,
retrieval_status character varying DEFAULT 'ok'::character varying NOT NULL,
retrieval_message character varying,
custom_fields jsonb
);
--
-- Name: analyses_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--