diff --git a/data/db_state/generate_dump.sh b/data/db_state/generate_dump.sh new file mode 100755 index 0000000000..7b01314e43 --- /dev/null +++ b/data/db_state/generate_dump.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Update depending on the database +PG_DATABASE="geonature2db" +PG_USER="geonatadmin" +PG_PASSWORD="geonatadmin" +HOST=localhost +PORT=5432 + +# Use to update schemas.txt +# PG_PASSWORD=$PG_PASSWORD psql -t -h $HOST -p $PORT -U $PG_USER $PG_DATABASE -c "select nspname +# from pg_catalog.pg_namespace where nspname NOT IN ('public', 'information_schema') and nspname NOT ILIKE 'pg%' ;" -o schemas.txt + +cat schemas.txt | while read schema || [[ -n $schema ]]; +do + cmd="PG_PASSWORD=$PG_PASSWORD psql -t -h $HOST -p $PORT -U $PG_USER $PG_DATABASE -c \"SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname='$schema'\"" + res=$(eval "$cmd") + if [[ ! -d $schema ]];then + mkdir $schema; + fi + for table in $res; + do + echo "Dumping ${schema}.${table}..." + PG_PASSWORD=$PG_PASSWORD pg_dump -O -x -s -t "${schema}.${table}" -U $PG_USER -h $HOST -p $PORT $PG_DATABASE > $schema/$table.sql + sed -i '/^--/d' $schema/$table.sql + sed -i '/^SELECT pg_catalog/d' $schema/$table.sql + sed -i '/SET/d' $schema/$table.sql + # Remove consecutive empty lines + sed -i '/^$/N;/\n$/D' $schema/$table.sql + + done + + +# cmd="PG_PASSWORD=geonatadmin pg_dump -n '${schema}.${}' -U geonatadmin -h localhost geonature2>${schema}.sql" + +# eval "$cmd" +done diff --git a/data/db_state/gn_commons/bib_tables_location.sql b/data/db_state/gn_commons/bib_tables_location.sql new file mode 100644 index 0000000000..461f19e4dc --- /dev/null +++ b/data/db_state/gn_commons/bib_tables_location.sql @@ -0,0 +1,25 @@ + +CREATE TABLE gn_commons.bib_tables_location ( + id_table_location integer NOT NULL, + table_desc character varying(255), + schema_name character varying(50) NOT NULL, + table_name character varying(50) NOT NULL, + pk_field character varying(50) NOT NULL, + uuid_field_name character varying(50) NOT NULL +); + +CREATE SEQUENCE gn_commons.bib_tables_location_id_table_location_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.bib_tables_location_id_table_location_seq OWNED BY gn_commons.bib_tables_location.id_table_location; + +ALTER TABLE ONLY gn_commons.bib_tables_location + ADD CONSTRAINT pk_bib_tables_location PRIMARY KEY (id_table_location); + +ALTER TABLE ONLY gn_commons.bib_tables_location + ADD CONSTRAINT unique_bib_tables_location_schema_name_table_name UNIQUE (schema_name, table_name); + diff --git a/data/db_state/gn_commons/bib_widgets.sql b/data/db_state/gn_commons/bib_widgets.sql new file mode 100644 index 0000000000..ea5d79b0f9 --- /dev/null +++ b/data/db_state/gn_commons/bib_widgets.sql @@ -0,0 +1,19 @@ + +CREATE TABLE gn_commons.bib_widgets ( + id_widget integer NOT NULL, + widget_name character varying(50) NOT NULL +); + +CREATE SEQUENCE gn_commons.bib_widgets_id_widget_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.bib_widgets_id_widget_seq OWNED BY gn_commons.bib_widgets.id_widget; + +ALTER TABLE ONLY gn_commons.bib_widgets + ADD CONSTRAINT pk_bib_widgets PRIMARY KEY (id_widget); + diff --git a/data/db_state/gn_commons/cor_field_dataset.sql b/data/db_state/gn_commons/cor_field_dataset.sql new file mode 100644 index 0000000000..2df34e5fe3 --- /dev/null +++ b/data/db_state/gn_commons/cor_field_dataset.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_commons.cor_field_dataset ( + id_field integer NOT NULL, + id_dataset integer NOT NULL +); + +ALTER TABLE ONLY gn_commons.cor_field_dataset + ADD CONSTRAINT pk_cor_field_dataset PRIMARY KEY (id_field, id_dataset); + +ALTER TABLE ONLY gn_commons.cor_field_dataset + ADD CONSTRAINT fk_cor_field_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_commons.cor_field_dataset + ADD CONSTRAINT fk_cor_field_dataset_field FOREIGN KEY (id_field) REFERENCES gn_commons.t_additional_fields(id_field) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_commons/cor_field_module.sql b/data/db_state/gn_commons/cor_field_module.sql new file mode 100644 index 0000000000..a89aa4cd2c --- /dev/null +++ b/data/db_state/gn_commons/cor_field_module.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_commons.cor_field_module ( + id_field integer NOT NULL, + id_module integer NOT NULL +); + +ALTER TABLE ONLY gn_commons.cor_field_module + ADD CONSTRAINT pk_cor_field_module PRIMARY KEY (id_field, id_module); + +ALTER TABLE ONLY gn_commons.cor_field_module + ADD CONSTRAINT fk_cor_field_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_commons.cor_field_module + ADD CONSTRAINT fk_cor_field_module_field FOREIGN KEY (id_field) REFERENCES gn_commons.t_additional_fields(id_field) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_commons/cor_field_object.sql b/data/db_state/gn_commons/cor_field_object.sql new file mode 100644 index 0000000000..16c5a6291e --- /dev/null +++ b/data/db_state/gn_commons/cor_field_object.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_commons.cor_field_object ( + id_field integer NOT NULL, + id_object integer NOT NULL +); + +ALTER TABLE ONLY gn_commons.cor_field_object + ADD CONSTRAINT pk_cor_field_object PRIMARY KEY (id_field, id_object); + +ALTER TABLE ONLY gn_commons.cor_field_object + ADD CONSTRAINT fk_cor_field_obj_field FOREIGN KEY (id_field) REFERENCES gn_commons.t_additional_fields(id_field) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_commons.cor_field_object + ADD CONSTRAINT fk_cor_field_object FOREIGN KEY (id_object) REFERENCES gn_permissions.t_objects(id_object) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_commons/cor_module_dataset.sql b/data/db_state/gn_commons/cor_module_dataset.sql new file mode 100644 index 0000000000..23b2227ab7 --- /dev/null +++ b/data/db_state/gn_commons/cor_module_dataset.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_commons.cor_module_dataset ( + id_module integer NOT NULL, + id_dataset integer NOT NULL +); + +COMMENT ON TABLE gn_commons.cor_module_dataset IS 'Define which datasets can be used in modules'; + +ALTER TABLE ONLY gn_commons.cor_module_dataset + ADD CONSTRAINT pk_cor_module_dataset PRIMARY KEY (id_module, id_dataset); + +ALTER TABLE ONLY gn_commons.cor_module_dataset + ADD CONSTRAINT fk_cor_module_dataset_id_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_commons.cor_module_dataset + ADD CONSTRAINT fk_cor_module_dataset_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_commons/t_additional_fields.sql b/data/db_state/gn_commons/t_additional_fields.sql new file mode 100644 index 0000000000..ec9cf8eec1 --- /dev/null +++ b/data/db_state/gn_commons/t_additional_fields.sql @@ -0,0 +1,37 @@ + +CREATE TABLE gn_commons.t_additional_fields ( + id_field integer NOT NULL, + field_name character varying(255) NOT NULL, + field_label character varying(50) NOT NULL, + required boolean DEFAULT false NOT NULL, + description text, + id_widget integer NOT NULL, + quantitative boolean DEFAULT false, + unity character varying(50), + additional_attributes jsonb, + code_nomenclature_type character varying(255), + field_values jsonb, + multiselect boolean, + id_list integer, + api character varying(250), + exportable boolean DEFAULT true, + field_order integer, + default_value text +); + +CREATE SEQUENCE gn_commons.t_additional_fields_id_field_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_additional_fields_id_field_seq OWNED BY gn_commons.t_additional_fields.id_field; + +ALTER TABLE ONLY gn_commons.t_additional_fields + ADD CONSTRAINT pk_t_additional_fields PRIMARY KEY (id_field); + +ALTER TABLE ONLY gn_commons.t_additional_fields + ADD CONSTRAINT fk_t_additional_fields_id_widget FOREIGN KEY (id_widget) REFERENCES gn_commons.bib_widgets(id_widget) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_commons/t_history_actions.sql b/data/db_state/gn_commons/t_history_actions.sql new file mode 100644 index 0000000000..4a042e6c18 --- /dev/null +++ b/data/db_state/gn_commons/t_history_actions.sql @@ -0,0 +1,36 @@ + +CREATE TABLE gn_commons.t_history_actions ( + id_history_action integer NOT NULL, + id_table_location integer NOT NULL, + uuid_attached_row uuid NOT NULL, + operation_type character(1), + operation_date timestamp without time zone, + table_content json, + CONSTRAINT check_t_history_actions_operation_type CHECK ((operation_type = ANY (ARRAY['I'::bpchar, 'U'::bpchar, 'D'::bpchar]))) +); + +COMMENT ON COLUMN gn_commons.t_history_actions.id_table_location IS 'FK vers la table où se trouve l''enregistrement tracé'; + +COMMENT ON COLUMN gn_commons.t_history_actions.uuid_attached_row IS 'Uuid de l''enregistrement tracé'; + +COMMENT ON COLUMN gn_commons.t_history_actions.operation_type IS 'Type d''événement tracé (Create, Update, Delete)'; + +COMMENT ON COLUMN gn_commons.t_history_actions.operation_date IS 'Date de l''événement'; + +COMMENT ON COLUMN gn_commons.t_history_actions.table_content IS 'Contenu au format json de l''événement tracé. On enregistre le NEW pour CREATE et UPDATE. LE OLD (ou rien?) pour le DELETE.'; + +CREATE SEQUENCE gn_commons.t_history_actions_id_history_action_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_history_actions_id_history_action_seq OWNED BY gn_commons.t_history_actions.id_history_action; + +ALTER TABLE ONLY gn_commons.t_history_actions + ADD CONSTRAINT pk_t_history_actions PRIMARY KEY (id_history_action); + +ALTER TABLE ONLY gn_commons.t_history_actions + ADD CONSTRAINT fk_t_history_actions_bib_tables_location FOREIGN KEY (id_table_location) REFERENCES gn_commons.bib_tables_location(id_table_location) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_commons/t_medias.sql b/data/db_state/gn_commons/t_medias.sql new file mode 100644 index 0000000000..7df6dc3b5c --- /dev/null +++ b/data/db_state/gn_commons/t_medias.sql @@ -0,0 +1,52 @@ + +CREATE TABLE gn_commons.t_medias ( + id_media integer NOT NULL, + unique_id_media uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_nomenclature_media_type integer NOT NULL, + id_table_location integer NOT NULL, + uuid_attached_row uuid, + title_fr character varying(255), + title_en character varying(255), + title_it character varying(255), + title_es character varying(255), + title_de character varying(255), + media_url character varying(255), + media_path character varying(255), + author character varying(100), + description_fr text, + description_en text, + description_it text, + description_es text, + description_de text, + is_public boolean DEFAULT true NOT NULL, + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now() +); + +COMMENT ON COLUMN gn_commons.t_medias.id_nomenclature_media_type IS 'Correspondance nomenclature GEONATURE = TYPE_MEDIA (117)'; + +CREATE SEQUENCE gn_commons.t_medias_id_media_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_medias_id_media_seq OWNED BY gn_commons.t_medias.id_media; + +ALTER TABLE gn_commons.t_medias + ADD CONSTRAINT check_t_medias_media_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_media_type, 'TYPE_MEDIA'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_commons.t_medias + ADD CONSTRAINT pk_t_medias PRIMARY KEY (id_media); + +CREATE TRIGGER tri_log_changes_t_medias AFTER INSERT OR DELETE OR UPDATE ON gn_commons.t_medias FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_meta_dates_change_t_medias BEFORE INSERT OR UPDATE ON gn_commons.t_medias FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY gn_commons.t_medias + ADD CONSTRAINT fk_t_medias_bib_tables_location FOREIGN KEY (id_table_location) REFERENCES gn_commons.bib_tables_location(id_table_location) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_commons.t_medias + ADD CONSTRAINT fk_t_medias_media_type FOREIGN KEY (id_nomenclature_media_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_commons/t_mobile_apps.sql b/data/db_state/gn_commons/t_mobile_apps.sql new file mode 100644 index 0000000000..3650c979d0 --- /dev/null +++ b/data/db_state/gn_commons/t_mobile_apps.sql @@ -0,0 +1,29 @@ + +CREATE TABLE gn_commons.t_mobile_apps ( + id_mobile_app integer NOT NULL, + app_code character varying(30), + relative_path_apk character varying(255), + url_apk character varying(255), + package character varying(255), + version_code character varying(10), + url_settings character varying +); + +COMMENT ON COLUMN gn_commons.t_mobile_apps.app_code IS 'Code de l''application mobile. Pas de FK vers t_modules car une application mobile ne correspond pas forcement à un module GN'; + +CREATE SEQUENCE gn_commons.t_mobile_apps_id_mobile_app_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_mobile_apps_id_mobile_app_seq OWNED BY gn_commons.t_mobile_apps.id_mobile_app; + +ALTER TABLE ONLY gn_commons.t_mobile_apps + ADD CONSTRAINT pk_t_moobile_apps PRIMARY KEY (id_mobile_app); + +ALTER TABLE ONLY gn_commons.t_mobile_apps + ADD CONSTRAINT unique_t_mobile_apps_app_code UNIQUE (app_code); + diff --git a/data/db_state/gn_commons/t_modules.sql b/data/db_state/gn_commons/t_modules.sql new file mode 100644 index 0000000000..b809b92f86 --- /dev/null +++ b/data/db_state/gn_commons/t_modules.sql @@ -0,0 +1,52 @@ + +CREATE TABLE gn_commons.t_modules ( + id_module integer NOT NULL, + module_code character varying(50) NOT NULL, + module_label character varying(255) NOT NULL, + module_picto character varying(255), + module_desc text, + module_group character varying(50), + module_path character varying(255), + module_external_url character varying(255), + module_target character varying(10), + module_comment text, + active_frontend boolean NOT NULL, + active_backend boolean NOT NULL, + module_doc_url character varying(255), + module_order integer, + type character varying(255) DEFAULT 'base'::character varying NOT NULL, + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + ng_module character varying(500), + CONSTRAINT check_urls_not_null CHECK (((module_path IS NOT NULL) OR (module_external_url IS NOT NULL))) +); + +COMMENT ON COLUMN gn_commons.t_modules.id_module IS 'PK mais aussi FK vers la table "utilisateurs.t_applications". ATTENTION de ne pas utiliser l''identifiant d''une application existante dans cette table et qui ne serait pas un module de GeoNature'; + +COMMENT ON COLUMN gn_commons.t_modules.module_path IS 'url relative vers le module - si module interne'; + +COMMENT ON COLUMN gn_commons.t_modules.module_external_url IS 'url absolue vers le module - si module externe (active_frontend = false)'; + +COMMENT ON COLUMN gn_commons.t_modules.module_target IS 'Value = NULL ou "blank". On peux ainsi référencer des modules externes et les ouvrir dans un nouvel onglet.'; + +CREATE SEQUENCE gn_commons.t_modules_id_module_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_modules_id_module_seq OWNED BY gn_commons.t_modules.id_module; + +ALTER TABLE ONLY gn_commons.t_modules + ADD CONSTRAINT pk_t_modules PRIMARY KEY (id_module); + +ALTER TABLE ONLY gn_commons.t_modules + ADD CONSTRAINT unique_t_modules_module_code UNIQUE (module_code); + +ALTER TABLE ONLY gn_commons.t_modules + ADD CONSTRAINT unique_t_modules_module_path UNIQUE (module_path); + +CREATE TRIGGER tri_meta_dates_change_t_modules BEFORE INSERT OR UPDATE ON gn_commons.t_modules FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + diff --git a/data/db_state/gn_commons/t_parameters.sql b/data/db_state/gn_commons/t_parameters.sql new file mode 100644 index 0000000000..765ba5e3d4 --- /dev/null +++ b/data/db_state/gn_commons/t_parameters.sql @@ -0,0 +1,32 @@ + +CREATE TABLE gn_commons.t_parameters ( + id_parameter integer NOT NULL, + id_organism integer, + parameter_name character varying(100) NOT NULL, + parameter_desc text, + parameter_value text NOT NULL, + parameter_extra_value character varying(255) +); + +COMMENT ON TABLE gn_commons.t_parameters IS 'Allow to manage content configuration depending on organism or not (CRUD depending on privileges).'; + +CREATE SEQUENCE gn_commons.t_parameters_id_parameter_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_parameters_id_parameter_seq OWNED BY gn_commons.t_parameters.id_parameter; + +ALTER TABLE ONLY gn_commons.t_parameters + ADD CONSTRAINT pk_t_parameters PRIMARY KEY (id_parameter); + +ALTER TABLE ONLY gn_commons.t_parameters + ADD CONSTRAINT unique_t_parameters_id_organism_parameter_name UNIQUE (id_organism, parameter_name); + +CREATE UNIQUE INDEX i_unique_t_parameters_parameter_name_with_id_organism_null ON gn_commons.t_parameters USING btree (parameter_name) WHERE (id_organism IS NULL); + +ALTER TABLE ONLY gn_commons.t_parameters + ADD CONSTRAINT fk_t_parameters_bib_organismes FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_commons/t_places.sql b/data/db_state/gn_commons/t_places.sql new file mode 100644 index 0000000000..4496cfd862 --- /dev/null +++ b/data/db_state/gn_commons/t_places.sql @@ -0,0 +1,32 @@ + +CREATE TABLE gn_commons.t_places ( + id_place integer NOT NULL, + id_role integer NOT NULL, + place_name character varying(100), + place_geom public.geometry +); + +COMMENT ON COLUMN gn_commons.t_places.id_place IS 'Clé primaire autoincrémente de la table t_places'; + +COMMENT ON COLUMN gn_commons.t_places.id_role IS 'Clé étrangère vers la table utilisateurs.t_roles, chaque lieu est associé à un utilisateur'; + +COMMENT ON COLUMN gn_commons.t_places.place_name IS 'Nom du lieu'; + +COMMENT ON COLUMN gn_commons.t_places.place_geom IS 'Géométrie du lieu'; + +CREATE SEQUENCE gn_commons.t_places_id_place_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_places_id_place_seq OWNED BY gn_commons.t_places.id_place; + +ALTER TABLE ONLY gn_commons.t_places + ADD CONSTRAINT pk_t_places PRIMARY KEY (id_place); + +ALTER TABLE ONLY gn_commons.t_places + ADD CONSTRAINT fk_t_places_t_roles FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_commons/t_validations.sql b/data/db_state/gn_commons/t_validations.sql new file mode 100644 index 0000000000..8cbb24d254 --- /dev/null +++ b/data/db_state/gn_commons/t_validations.sql @@ -0,0 +1,46 @@ + +CREATE TABLE gn_commons.t_validations ( + id_validation integer NOT NULL, + uuid_attached_row uuid NOT NULL, + id_nomenclature_valid_status integer, + validation_auto boolean DEFAULT true NOT NULL, + id_validator integer, + validation_comment text, + validation_date timestamp without time zone +); + +COMMENT ON COLUMN gn_commons.t_validations.uuid_attached_row IS 'Uuid de l''enregistrement validé'; + +COMMENT ON COLUMN gn_commons.t_validations.id_nomenclature_valid_status IS 'Correspondance nomenclature INPN = statut_valid (101)'; + +COMMENT ON COLUMN gn_commons.t_validations.id_validator IS 'Fk vers l''id_role (utilisateurs.t_roles) du validateur'; + +COMMENT ON COLUMN gn_commons.t_validations.validation_comment IS 'Commentaire concernant la validation'; + +COMMENT ON COLUMN gn_commons.t_validations.validation_date IS 'Date de la validation'; + +CREATE SEQUENCE gn_commons.t_validations_id_validation_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_commons.t_validations_id_validation_seq OWNED BY gn_commons.t_validations.id_validation; + +ALTER TABLE gn_commons.t_validations + ADD CONSTRAINT check_t_validations_valid_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_valid_status, 'STATUT_VALID'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_commons.t_validations + ADD CONSTRAINT pk_t_validations PRIMARY KEY (id_validation); + +CREATE INDEX i_t_validations_uuid_attached_row ON gn_commons.t_validations USING btree (uuid_attached_row); + +CREATE TRIGGER tri_insert_synthese_update_validation_status AFTER INSERT ON gn_commons.t_validations FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_update_synthese_validation_status(); + +ALTER TABLE ONLY gn_commons.t_validations + ADD CONSTRAINT fk_t_validations_t_roles FOREIGN KEY (id_validator) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_commons.t_validations + ADD CONSTRAINT fk_t_validations_valid_status FOREIGN KEY (id_nomenclature_valid_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_imports/bib_destinations.sql b/data/db_state/gn_imports/bib_destinations.sql new file mode 100644 index 0000000000..bd708baf25 --- /dev/null +++ b/data/db_state/gn_imports/bib_destinations.sql @@ -0,0 +1,28 @@ + +CREATE TABLE gn_imports.bib_destinations ( + id_destination integer NOT NULL, + id_module integer, + code character varying(64), + label character varying(128), + table_name character varying(64) +); + +CREATE SEQUENCE gn_imports.bib_destinations_id_destination_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.bib_destinations_id_destination_seq OWNED BY gn_imports.bib_destinations.id_destination; + +ALTER TABLE ONLY gn_imports.bib_destinations + ADD CONSTRAINT bib_destinations_code_key UNIQUE (code); + +ALTER TABLE ONLY gn_imports.bib_destinations + ADD CONSTRAINT bib_destinations_pkey PRIMARY KEY (id_destination); + +ALTER TABLE ONLY gn_imports.bib_destinations + ADD CONSTRAINT bib_destinations_id_module_fkey FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/bib_entities.sql b/data/db_state/gn_imports/bib_entities.sql new file mode 100644 index 0000000000..8e9630095f --- /dev/null +++ b/data/db_state/gn_imports/bib_entities.sql @@ -0,0 +1,36 @@ + +CREATE TABLE gn_imports.bib_entities ( + id_entity integer NOT NULL, + id_destination integer, + code character varying(16), + label character varying(64), + "order" integer, + validity_column character varying(64), + destination_table_schema character varying(63), + destination_table_name character varying(63), + id_unique_column integer, + id_parent integer +); + +CREATE SEQUENCE gn_imports.bib_entities_id_entity_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.bib_entities_id_entity_seq OWNED BY gn_imports.bib_entities.id_entity; + +ALTER TABLE ONLY gn_imports.bib_entities + ADD CONSTRAINT bib_entities_pkey PRIMARY KEY (id_entity); + +ALTER TABLE ONLY gn_imports.bib_entities + ADD CONSTRAINT bib_entities_id_destination_fkey FOREIGN KEY (id_destination) REFERENCES gn_imports.bib_destinations(id_destination) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.bib_entities + ADD CONSTRAINT bib_entities_id_parent_fkey FOREIGN KEY (id_parent) REFERENCES gn_imports.bib_entities(id_entity); + +ALTER TABLE ONLY gn_imports.bib_entities + ADD CONSTRAINT bib_entities_id_unique_column_fkey FOREIGN KEY (id_unique_column) REFERENCES gn_imports.bib_fields(id_field); + diff --git a/data/db_state/gn_imports/bib_errors_types.sql b/data/db_state/gn_imports/bib_errors_types.sql new file mode 100644 index 0000000000..ade668bd6f --- /dev/null +++ b/data/db_state/gn_imports/bib_errors_types.sql @@ -0,0 +1,25 @@ + +CREATE TABLE gn_imports.bib_errors_types ( + id_error integer NOT NULL, + error_type character varying(100) NOT NULL, + name character varying(255) NOT NULL, + description text, + error_level character varying(25) +); + +CREATE SEQUENCE gn_imports.t_user_errors_id_error_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.t_user_errors_id_error_seq OWNED BY gn_imports.bib_errors_types.id_error; + +ALTER TABLE ONLY gn_imports.bib_errors_types + ADD CONSTRAINT pk_user_errors PRIMARY KEY (id_error); + +ALTER TABLE ONLY gn_imports.bib_errors_types + ADD CONSTRAINT t_user_errors_name_key UNIQUE (name); + diff --git a/data/db_state/gn_imports/bib_fields.sql b/data/db_state/gn_imports/bib_fields.sql new file mode 100644 index 0000000000..e56355b820 --- /dev/null +++ b/data/db_state/gn_imports/bib_fields.sql @@ -0,0 +1,50 @@ + +CREATE TABLE gn_imports.bib_fields ( + id_field integer NOT NULL, + name_field character varying(100) NOT NULL, + fr_label character varying(100) NOT NULL, + eng_label character varying(100), + type_field character varying(50), + mandatory boolean NOT NULL, + autogenerated boolean NOT NULL, + display boolean NOT NULL, + mnemonique character varying, + source_field character varying, + dest_field character varying, + multi boolean DEFAULT false NOT NULL, + id_destination integer NOT NULL, + mandatory_conditions character varying[], + optional_conditions character varying[] +); + +COMMENT ON COLUMN gn_imports.bib_fields.mandatory_conditions IS 'Contient la liste de champs qui rendent le champ obligatoire.'; + +COMMENT ON COLUMN gn_imports.bib_fields.optional_conditions IS 'Contient la liste de champs qui rendent le champ optionnel.'; + +CREATE SEQUENCE gn_imports.dict_fields_id_field_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.dict_fields_id_field_seq OWNED BY gn_imports.bib_fields.id_field; + +ALTER TABLE gn_imports.bib_fields + ADD CONSTRAINT mandatory_conditions_field_exists CHECK (gn_imports.isinnamefields((mandatory_conditions)::text[], id_destination)) NOT VALID; + +ALTER TABLE gn_imports.bib_fields + ADD CONSTRAINT optional_conditions_field_exists CHECK (gn_imports.isinnamefields((optional_conditions)::text[], id_destination)) NOT VALID; + +ALTER TABLE ONLY gn_imports.bib_fields + ADD CONSTRAINT pk_dict_fields_id_theme PRIMARY KEY (id_field); + +ALTER TABLE ONLY gn_imports.bib_fields + ADD CONSTRAINT unicity_bib_fields_dest_name_field UNIQUE (id_destination, name_field); + +ALTER TABLE ONLY gn_imports.bib_fields + ADD CONSTRAINT bib_fields_id_destination_fkey FOREIGN KEY (id_destination) REFERENCES gn_imports.bib_destinations(id_destination) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.bib_fields + diff --git a/data/db_state/gn_imports/bib_themes.sql b/data/db_state/gn_imports/bib_themes.sql new file mode 100644 index 0000000000..e535396f5c --- /dev/null +++ b/data/db_state/gn_imports/bib_themes.sql @@ -0,0 +1,23 @@ + +CREATE TABLE gn_imports.bib_themes ( + id_theme integer NOT NULL, + name_theme character varying(100) NOT NULL, + fr_label_theme character varying(100) NOT NULL, + eng_label_theme character varying(100), + desc_theme character varying(1000), + order_theme integer NOT NULL +); + +CREATE SEQUENCE gn_imports.dict_themes_id_theme_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.dict_themes_id_theme_seq OWNED BY gn_imports.bib_themes.id_theme; + +ALTER TABLE ONLY gn_imports.bib_themes + ADD CONSTRAINT pk_dict_themes_id_theme PRIMARY KEY (id_theme); + diff --git a/data/db_state/gn_imports/cor_entity_field.sql b/data/db_state/gn_imports/cor_entity_field.sql new file mode 100644 index 0000000000..901288e64f --- /dev/null +++ b/data/db_state/gn_imports/cor_entity_field.sql @@ -0,0 +1,22 @@ + +CREATE TABLE gn_imports.cor_entity_field ( + id_entity integer NOT NULL, + id_field integer NOT NULL, + desc_field character varying(1000), + id_theme integer NOT NULL, + order_field integer NOT NULL, + comment character varying +); + +ALTER TABLE ONLY gn_imports.cor_entity_field + ADD CONSTRAINT cor_entity_field_pkey PRIMARY KEY (id_entity, id_field); + +ALTER TABLE ONLY gn_imports.cor_entity_field + ADD CONSTRAINT cor_entity_field_id_entity_fkey FOREIGN KEY (id_entity) REFERENCES gn_imports.bib_entities(id_entity) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.cor_entity_field + ADD CONSTRAINT cor_entity_field_id_field_fkey FOREIGN KEY (id_field) REFERENCES gn_imports.bib_fields(id_field) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.cor_entity_field + ADD CONSTRAINT cor_entity_field_id_theme_fkey FOREIGN KEY (id_theme) REFERENCES gn_imports.bib_themes(id_theme); + diff --git a/data/db_state/gn_imports/cor_role_import.sql b/data/db_state/gn_imports/cor_role_import.sql new file mode 100644 index 0000000000..5860caad99 --- /dev/null +++ b/data/db_state/gn_imports/cor_role_import.sql @@ -0,0 +1,18 @@ + +CREATE TABLE gn_imports.cor_role_import ( + id_role integer NOT NULL, + id_import integer NOT NULL +); + +ALTER TABLE ONLY gn_imports.cor_role_import + ADD CONSTRAINT pk_cor_role_import PRIMARY KEY (id_role, id_import); + +ALTER TABLE ONLY gn_imports.cor_role_import + ADD CONSTRAINT fk_cor_role_import_import FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.cor_role_import + ADD CONSTRAINT fk_cor_role_import_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.cor_role_import + ADD CONSTRAINT fk_utilisateurs_t_roles FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/cor_role_mapping.sql b/data/db_state/gn_imports/cor_role_mapping.sql new file mode 100644 index 0000000000..040bc7525c --- /dev/null +++ b/data/db_state/gn_imports/cor_role_mapping.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_imports.cor_role_mapping ( + id_role integer NOT NULL, + id_mapping integer NOT NULL +); + +ALTER TABLE ONLY gn_imports.cor_role_mapping + ADD CONSTRAINT pk_cor_role_mapping PRIMARY KEY (id_role, id_mapping); + +ALTER TABLE ONLY gn_imports.cor_role_mapping + ADD CONSTRAINT fk_gn_imports_t_mappings_id_mapping FOREIGN KEY (id_mapping) REFERENCES gn_imports.t_mappings(id) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.cor_role_mapping + ADD CONSTRAINT fk_utilisateurs_t_roles FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/matching_fields.sql b/data/db_state/gn_imports/matching_fields.sql new file mode 100644 index 0000000000..756031084d --- /dev/null +++ b/data/db_state/gn_imports/matching_fields.sql @@ -0,0 +1,30 @@ + +CREATE TABLE gn_imports.matching_fields ( + id_matching_field integer NOT NULL, + source_field text, + source_default_value text, + target_field text NOT NULL, + target_field_type text, + field_comments text, + id_matching_table integer NOT NULL, + CONSTRAINT check_source_exists CHECK (((source_field IS NOT NULL) OR (source_default_value IS NOT NULL))) +); + +COMMENT ON COLUMN gn_imports.matching_fields.source_default_value IS 'Valeur par défaut à insérer si la valeur attendue dans le champ de la table de destination n''existe pas dans la table source'; + +CREATE SEQUENCE gn_imports.matching_fields_id_matching_field_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.matching_fields_id_matching_field_seq OWNED BY gn_imports.matching_fields.id_matching_field; + +ALTER TABLE ONLY gn_imports.matching_fields + ADD CONSTRAINT pk_matching_fields PRIMARY KEY (id_matching_field); + +ALTER TABLE ONLY gn_imports.matching_fields + ADD CONSTRAINT fk_matching_fields_matching_tables FOREIGN KEY (id_matching_table) REFERENCES gn_imports.matching_tables(id_matching_table) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_imports/matching_geoms.sql b/data/db_state/gn_imports/matching_geoms.sql new file mode 100644 index 0000000000..49d260b2bd --- /dev/null +++ b/data/db_state/gn_imports/matching_geoms.sql @@ -0,0 +1,30 @@ + +CREATE TABLE gn_imports.matching_geoms ( + id_matching_geom integer NOT NULL, + source_x_field text, + source_y_field text, + source_geom_field text, + source_geom_format text, + source_srid integer, + target_geom_field text, + target_geom_srid integer, + geom_comments text, + id_matching_table integer NOT NULL +); + +CREATE SEQUENCE gn_imports.matching_geoms_id_matching_geom_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.matching_geoms_id_matching_geom_seq OWNED BY gn_imports.matching_geoms.id_matching_geom; + +ALTER TABLE ONLY gn_imports.matching_geoms + ADD CONSTRAINT pk_matching_synthese PRIMARY KEY (id_matching_geom); + +ALTER TABLE ONLY gn_imports.matching_geoms + ADD CONSTRAINT fk_matching_geoms_matching_tables FOREIGN KEY (id_matching_table) REFERENCES gn_imports.matching_tables(id_matching_table) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_imports/matching_tables.sql b/data/db_state/gn_imports/matching_tables.sql new file mode 100644 index 0000000000..7252c4aff4 --- /dev/null +++ b/data/db_state/gn_imports/matching_tables.sql @@ -0,0 +1,23 @@ + +CREATE TABLE gn_imports.matching_tables ( + id_matching_table integer NOT NULL, + source_schema text NOT NULL, + source_table text NOT NULL, + target_schema text NOT NULL, + target_table text NOT NULL, + matching_comments text +); + +CREATE SEQUENCE gn_imports.matching_tables_id_matching_table_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.matching_tables_id_matching_table_seq OWNED BY gn_imports.matching_tables.id_matching_table; + +ALTER TABLE ONLY gn_imports.matching_tables + ADD CONSTRAINT pk_matching_tables PRIMARY KEY (id_matching_table); + diff --git a/data/db_state/gn_imports/t_contentmappings.sql b/data/db_state/gn_imports/t_contentmappings.sql new file mode 100644 index 0000000000..6bc9147c76 --- /dev/null +++ b/data/db_state/gn_imports/t_contentmappings.sql @@ -0,0 +1,12 @@ + +CREATE TABLE gn_imports.t_contentmappings ( + id integer NOT NULL, + "values" json +); + +ALTER TABLE ONLY gn_imports.t_contentmappings + ADD CONSTRAINT t_contentmappings_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY gn_imports.t_contentmappings + ADD CONSTRAINT t_contentmappings_id_fkey FOREIGN KEY (id) REFERENCES gn_imports.t_mappings(id) ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/t_fieldmappings.sql b/data/db_state/gn_imports/t_fieldmappings.sql new file mode 100644 index 0000000000..521864376d --- /dev/null +++ b/data/db_state/gn_imports/t_fieldmappings.sql @@ -0,0 +1,12 @@ + +CREATE TABLE gn_imports.t_fieldmappings ( + id integer NOT NULL, + "values" json +); + +ALTER TABLE ONLY gn_imports.t_fieldmappings + ADD CONSTRAINT t_fieldmappings_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY gn_imports.t_fieldmappings + ADD CONSTRAINT t_fieldmappings_id_fkey FOREIGN KEY (id) REFERENCES gn_imports.t_mappings(id) ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/t_imports.sql b/data/db_state/gn_imports/t_imports.sql new file mode 100644 index 0000000000..03899d4acd --- /dev/null +++ b/data/db_state/gn_imports/t_imports.sql @@ -0,0 +1,52 @@ + +CREATE TABLE gn_imports.t_imports ( + id_import integer NOT NULL, + format_source_file character varying(10), + srid integer, + separator character varying, + encoding character varying, + full_file_name character varying(255), + id_dataset integer, + date_create_import timestamp without time zone DEFAULT now(), + date_update_import timestamp without time zone DEFAULT now(), + date_end_import timestamp without time zone, + source_count integer, + uuid_autogenerated boolean, + altitude_autogenerated boolean, + date_min_data timestamp without time zone, + date_max_data timestamp without time zone, + processed boolean DEFAULT false NOT NULL, + need_fix boolean DEFAULT false, + fix_comment text, + detected_encoding character varying, + source_file bytea, + columns character varying[], + fieldmapping json, + contentmapping json, + detected_separator character varying, + task_id character varying(155), + erroneous_rows integer[], + loaded boolean DEFAULT false NOT NULL, + id_destination integer NOT NULL, + statistics json DEFAULT '{}'::jsonb NOT NULL +); + +CREATE SEQUENCE gn_imports.t_imports_id_import_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.t_imports_id_import_seq OWNED BY gn_imports.t_imports.id_import; + +ALTER TABLE ONLY gn_imports.t_imports + ADD CONSTRAINT pk_gn_imports_t_imports PRIMARY KEY (id_import); + +ALTER TABLE ONLY gn_imports.t_imports + ADD CONSTRAINT fk_gn_meta_t_datasets FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.t_imports + ADD CONSTRAINT t_imports_id_destination_fkey FOREIGN KEY (id_destination) REFERENCES gn_imports.bib_destinations(id_destination) ON DELETE RESTRICT; + diff --git a/data/db_state/gn_imports/t_imports_occhab.sql b/data/db_state/gn_imports/t_imports_occhab.sql new file mode 100644 index 0000000000..428652296c --- /dev/null +++ b/data/db_state/gn_imports/t_imports_occhab.sql @@ -0,0 +1,117 @@ + +CREATE TABLE gn_imports.t_imports_occhab ( + id_import integer NOT NULL, + line_no integer NOT NULL, + station_valid boolean DEFAULT false, + habitat_valid boolean DEFAULT false, + id_station integer, + id_station_source character varying, + src_unique_id_sinp_station character varying, + unique_id_sinp_station uuid, + src_unique_dataset_id character varying, + unique_dataset_id uuid, + id_dataset integer, + src_date_min character varying, + date_min timestamp without time zone, + src_date_max character varying, + date_max timestamp without time zone, + observers_txt character varying, + station_name character varying, + src_id_nomenclature_exposure character varying, + id_nomenclature_exposure integer, + src_altitude_min character varying, + altitude_min integer, + src_altitude_max character varying, + altitude_max integer, + src_depth_min character varying, + depth_min integer, + src_depth_max character varying, + depth_max integer, + src_area character varying, + area integer, + src_id_nomenclature_area_surface_calculation character varying, + id_nomenclature_area_surface_calculation integer, + comment character varying, + "src_WKT" character varying, + src_latitude character varying, + src_longitude character varying, + geom_local public.geometry, + geom_4326 public.geometry(Geometry,4326), + src_precision character varying, + "precision" integer, + src_id_digitiser character varying, + id_digitiser integer, + src_numerization_scale character varying, + numerization_scale character varying(15), + src_id_nomenclature_geographic_object character varying, + id_nomenclature_geographic_object integer, + station_line_no integer, + src_id_habitat character varying, + id_habitat integer, + src_unique_id_sinp_hab character varying, + unique_id_sinp_hab uuid, + src_cd_hab character varying, + cd_hab integer, + nom_cite character varying, + src_id_nomenclature_determination_type character varying, + id_nomenclature_determination_type integer, + determiner character varying, + src_id_nomenclature_collection_technique character varying, + id_nomenclature_collection_technique integer, + src_recovery_percentage character varying, + recovery_percentage integer, + src_id_nomenclature_abundance character varying, + id_nomenclature_abundance integer, + technical_precision character varying, + src_unique_id_sinp_grp_occtax character varying, + unique_id_sinp_grp_occtax uuid, + src_unique_id_sinp_grp_phyto character varying, + unique_id_sinp_grp_phyto uuid, + src_id_nomenclature_sensitivity character varying, + id_nomenclature_sensitivity integer, + src_id_nomenclature_community_interest character varying, + id_nomenclature_community_interest integer, + src_id_nomenclature_type_mosaique_habitat character varying, + id_nomenclature_type_mosaique_habitat integer +); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_pkey PRIMARY KEY (id_import, line_no); + +CREATE INDEX idx_t_imports_occhab_geom_4326 ON gn_imports.t_imports_occhab USING gist (geom_4326); + +CREATE INDEX idx_t_imports_occhab_geom_local ON gn_imports.t_imports_occhab USING gist (geom_local); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_import_fkey FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_import_station_line_no_fkey FOREIGN KEY (id_import, station_line_no) REFERENCES gn_imports.t_imports_occhab(id_import, line_no); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_abundance_fkey FOREIGN KEY (id_nomenclature_abundance) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_area_surface_calculation_fkey FOREIGN KEY (id_nomenclature_area_surface_calculation) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_collection_technique_fkey FOREIGN KEY (id_nomenclature_collection_technique) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_community_interest_fkey FOREIGN KEY (id_nomenclature_community_interest) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_determination_type_fkey FOREIGN KEY (id_nomenclature_determination_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_exposure_fkey FOREIGN KEY (id_nomenclature_exposure) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_geographic_object_fkey FOREIGN KEY (id_nomenclature_geographic_object) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_sensitivity_fkey FOREIGN KEY (id_nomenclature_sensitivity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_occhab + ADD CONSTRAINT t_imports_occhab_id_nomenclature_type_mosaique_habitat_fkey FOREIGN KEY (id_nomenclature_type_mosaique_habitat) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/gn_imports/t_imports_synthese.sql b/data/db_state/gn_imports/t_imports_synthese.sql new file mode 100644 index 0000000000..6883561d4b --- /dev/null +++ b/data/db_state/gn_imports/t_imports_synthese.sql @@ -0,0 +1,196 @@ + +CREATE TABLE gn_imports.t_imports_synthese ( + id_import integer NOT NULL, + line_no integer NOT NULL, + valid boolean, + "src_WKT" character varying, + src_codecommune character varying, + src_codedepartement character varying, + src_codemaille character varying, + src_hour_max character varying, + src_hour_min character varying, + src_latitude character varying, + src_longitude character varying, + src_unique_id_sinp character varying, + src_unique_id_sinp_grp character varying, + src_id_nomenclature_geo_object_nature character varying, + src_id_nomenclature_grp_typ character varying, + src_id_nomenclature_obs_technique character varying, + src_id_nomenclature_bio_status character varying, + src_id_nomenclature_bio_condition character varying, + src_id_nomenclature_naturalness character varying, + src_id_nomenclature_valid_status character varying, + src_id_nomenclature_exist_proof character varying, + src_id_nomenclature_diffusion_level character varying, + src_id_nomenclature_life_stage character varying, + src_id_nomenclature_sex character varying, + src_id_nomenclature_obj_count character varying, + src_id_nomenclature_type_count character varying, + src_id_nomenclature_sensitivity character varying, + src_id_nomenclature_observation_status character varying, + src_id_nomenclature_blurring character varying, + src_id_nomenclature_source_status character varying, + src_id_nomenclature_info_geo_type character varying, + src_id_nomenclature_behaviour character varying, + src_id_nomenclature_biogeo_status character varying, + src_id_nomenclature_determination_method character varying, + src_count_min character varying, + src_count_max character varying, + src_cd_nom character varying, + src_cd_hab character varying, + src_altitude_min character varying, + src_altitude_max character varying, + src_depth_min character varying, + src_depth_max character varying, + src_precision character varying, + src_id_area_attachment character varying, + src_date_min character varying, + src_date_max character varying, + src_id_digitiser character varying, + src_meta_validation_date character varying, + src_meta_create_date character varying, + src_meta_update_date character varying, + extra_fields public.hstore, + unique_id_sinp uuid, + unique_id_sinp_grp uuid, + entity_source_pk_value character varying, + grp_method character varying(255), + id_nomenclature_geo_object_nature integer, + id_nomenclature_grp_typ integer, + id_nomenclature_obs_technique integer, + id_nomenclature_bio_status integer, + id_nomenclature_bio_condition integer, + id_nomenclature_naturalness integer, + id_nomenclature_valid_status integer, + id_nomenclature_exist_proof integer, + id_nomenclature_diffusion_level integer, + id_nomenclature_life_stage integer, + id_nomenclature_sex integer, + id_nomenclature_obj_count integer, + id_nomenclature_type_count integer, + id_nomenclature_sensitivity integer, + id_nomenclature_observation_status integer, + id_nomenclature_blurring integer, + id_nomenclature_source_status integer, + id_nomenclature_info_geo_type integer, + id_nomenclature_behaviour integer, + id_nomenclature_biogeo_status integer, + id_nomenclature_determination_method integer, + reference_biblio character varying, + count_min integer, + count_max integer, + cd_nom integer, + cd_hab integer, + nom_cite character varying, + meta_v_taxref character varying, + digital_proof text, + non_digital_proof text, + altitude_min integer, + altitude_max integer, + depth_min integer, + depth_max integer, + place_name character varying, + the_geom_4326 public.geometry(Geometry,4326), + the_geom_point public.geometry(Geometry,4326), + the_geom_local public.geometry, + "precision" integer, + date_min timestamp without time zone, + date_max timestamp without time zone, + validator character varying, + validation_comment character varying, + observers character varying, + determiner character varying, + id_digitiser integer, + comment_context text, + comment_description text, + additional_data jsonb, + meta_validation_date timestamp without time zone, + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone, + id_area_attachment integer, + src_unique_dataset_id character varying, + unique_dataset_id uuid, + id_dataset integer +); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_pkey PRIMARY KEY (id_import, line_no); + +CREATE INDEX idx_t_imports_synthese_the_geom_4326 ON gn_imports.t_imports_synthese USING gist (the_geom_4326); + +CREATE INDEX idx_t_imports_synthese_the_geom_local ON gn_imports.t_imports_synthese USING gist (the_geom_local); + +CREATE INDEX idx_t_imports_synthese_the_geom_point ON gn_imports.t_imports_synthese USING gist (the_geom_point); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_area_attachment_fkey FOREIGN KEY (id_area_attachment) REFERENCES ref_geo.l_areas(id_area); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_digitiser_fkey FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_import_fkey FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_behaviour_fkey FOREIGN KEY (id_nomenclature_behaviour) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_bio_condition_fkey FOREIGN KEY (id_nomenclature_bio_condition) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_bio_status_fkey FOREIGN KEY (id_nomenclature_bio_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_biogeo_status_fkey FOREIGN KEY (id_nomenclature_biogeo_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_blurring_fkey FOREIGN KEY (id_nomenclature_blurring) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_determination_method_fkey FOREIGN KEY (id_nomenclature_determination_method) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_diffusion_level_fkey FOREIGN KEY (id_nomenclature_diffusion_level) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_exist_proof_fkey FOREIGN KEY (id_nomenclature_exist_proof) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_geo_object_nature_fkey FOREIGN KEY (id_nomenclature_geo_object_nature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_grp_typ_fkey FOREIGN KEY (id_nomenclature_grp_typ) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_info_geo_type_fkey FOREIGN KEY (id_nomenclature_info_geo_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_life_stage_fkey FOREIGN KEY (id_nomenclature_life_stage) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_naturalness_fkey FOREIGN KEY (id_nomenclature_naturalness) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_obj_count_fkey FOREIGN KEY (id_nomenclature_obj_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_obs_technique_fkey FOREIGN KEY (id_nomenclature_obs_technique) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_observation_status_fkey FOREIGN KEY (id_nomenclature_observation_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_sensitivity_fkey FOREIGN KEY (id_nomenclature_sensitivity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_sex_fkey FOREIGN KEY (id_nomenclature_sex) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_source_status_fkey FOREIGN KEY (id_nomenclature_source_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_type_count_fkey FOREIGN KEY (id_nomenclature_type_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_imports.t_imports_synthese + ADD CONSTRAINT t_imports_synthese_id_nomenclature_valid_status_fkey FOREIGN KEY (id_nomenclature_valid_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/gn_imports/t_mappings.sql b/data/db_state/gn_imports/t_mappings.sql new file mode 100644 index 0000000000..8832834de9 --- /dev/null +++ b/data/db_state/gn_imports/t_mappings.sql @@ -0,0 +1,30 @@ + +CREATE TABLE gn_imports.t_mappings ( + id integer NOT NULL, + label character varying(255) NOT NULL, + type character varying(10) NOT NULL, + active boolean DEFAULT true NOT NULL, + public boolean DEFAULT false NOT NULL, + id_destination integer NOT NULL, + CONSTRAINT check_mapping_type_in_t_mappings CHECK (((type)::text = ANY ((ARRAY['FIELD'::character varying, 'CONTENT'::character varying])::text[]))) +); + +CREATE SEQUENCE gn_imports.t_mappings_id_mapping_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.t_mappings_id_mapping_seq OWNED BY gn_imports.t_mappings.id; + +ALTER TABLE ONLY gn_imports.t_mappings + ADD CONSTRAINT pk_t_mappings PRIMARY KEY (id); + +ALTER TABLE ONLY gn_imports.t_mappings + ADD CONSTRAINT t_mappings_un UNIQUE (label, type); + +ALTER TABLE ONLY gn_imports.t_mappings + ADD CONSTRAINT t_mappings_id_destination_fkey FOREIGN KEY (id_destination) REFERENCES gn_imports.bib_destinations(id_destination) ON DELETE CASCADE; + diff --git a/data/db_state/gn_imports/t_user_errors.sql b/data/db_state/gn_imports/t_user_errors.sql new file mode 100644 index 0000000000..895046643a --- /dev/null +++ b/data/db_state/gn_imports/t_user_errors.sql @@ -0,0 +1,37 @@ + +CREATE TABLE gn_imports.t_user_errors ( + id_user_error integer NOT NULL, + id_import integer NOT NULL, + id_error integer NOT NULL, + column_error character varying(100) NOT NULL, + id_rows integer[], + comment text, + id_entity integer +); + +CREATE SEQUENCE gn_imports.t_user_error_list_id_user_error_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_imports.t_user_error_list_id_user_error_seq OWNED BY gn_imports.t_user_errors.id_user_error; + +ALTER TABLE ONLY gn_imports.t_user_errors + ADD CONSTRAINT pk_t_user_error_list PRIMARY KEY (id_user_error); + +CREATE UNIQUE INDEX t_user_errors_entity_un ON gn_imports.t_user_errors USING btree (id_import, id_entity, id_error, column_error) WHERE (id_entity IS NOT NULL); + +CREATE UNIQUE INDEX t_user_errors_un ON gn_imports.t_user_errors USING btree (id_import, id_error, column_error) WHERE (id_entity IS NULL); + +ALTER TABLE ONLY gn_imports.t_user_errors + ADD CONSTRAINT fk_t_user_error_list_id_error FOREIGN KEY (id_error) REFERENCES gn_imports.bib_errors_types(id_error) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.t_user_errors + ADD CONSTRAINT fk_t_user_error_list_id_import FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_imports.t_user_errors + ADD CONSTRAINT t_user_errors_id_entity_fkey FOREIGN KEY (id_entity) REFERENCES gn_imports.bib_entities(id_entity) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_meta/cor_acquisition_framework_actor.sql b/data/db_state/gn_meta/cor_acquisition_framework_actor.sql new file mode 100644 index 0000000000..0a52ae1a01 --- /dev/null +++ b/data/db_state/gn_meta/cor_acquisition_framework_actor.sql @@ -0,0 +1,48 @@ + +CREATE TABLE gn_meta.cor_acquisition_framework_actor ( + id_cafa integer NOT NULL, + id_acquisition_framework integer NOT NULL, + id_role integer, + id_organism integer, + id_nomenclature_actor_role integer NOT NULL, + CONSTRAINT check_id_role_not_group CHECK ((NOT gn_commons.role_is_group(id_role))), + CONSTRAINT check_is_actor_in_cor_acquisition_framework_actor CHECK (((id_role IS NOT NULL) OR (id_organism IS NOT NULL))) +); + +COMMENT ON TABLE gn_meta.cor_acquisition_framework_actor IS 'A acquisition framework must have a principal actor "acteurPrincipal" and can have 0 or n other actor "acteurAutre". Implement 1.3.10 SINP metadata standard : Contact principal pour le cadre d''acquisition (Règle : RoleActeur prendra la valeur 1) - OBLIGATOIRE. Autres contacts pour le cadre d''acquisition (exemples : maître d''oeuvre, d''ouvrage...).- RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.cor_acquisition_framework_actor.id_nomenclature_actor_role IS 'Correspondance standard SINP = roleActeur : Rôle de l''acteur tel que défini dans la nomenclature RoleActeurValue - OBLIGATOIRE'; + +CREATE SEQUENCE gn_meta.cor_acquisition_framework_actor_id_cafa_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.cor_acquisition_framework_actor_id_cafa_seq OWNED BY gn_meta.cor_acquisition_framework_actor.id_cafa; + +ALTER TABLE gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT check_cor_acquisition_framework_actor CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_actor_role, 'ROLE_ACTEUR'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT check_is_unique_cor_acquisition_framework_actor_organism UNIQUE (id_acquisition_framework, id_organism, id_nomenclature_actor_role); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT check_is_unique_cor_acquisition_framework_actor_role UNIQUE (id_acquisition_framework, id_role, id_nomenclature_actor_role); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT pk_cor_acquisition_framework_actor PRIMARY KEY (id_cafa); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT fk_cor_acquisition_framework_actor_id_acquisition_framework FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT fk_cor_acquisition_framework_actor_id_nomenclature_actor_role FOREIGN KEY (id_nomenclature_actor_role) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT fk_cor_acquisition_framework_actor_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_actor + ADD CONSTRAINT fk_cor_acquisition_framework_actor_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_meta/cor_acquisition_framework_objectif.sql b/data/db_state/gn_meta/cor_acquisition_framework_objectif.sql new file mode 100644 index 0000000000..d5dffdad0b --- /dev/null +++ b/data/db_state/gn_meta/cor_acquisition_framework_objectif.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_meta.cor_acquisition_framework_objectif ( + id_acquisition_framework integer NOT NULL, + id_nomenclature_objectif integer NOT NULL +); + +COMMENT ON TABLE gn_meta.cor_acquisition_framework_objectif IS 'A acquisition framework can have 1 or n "objectif". Implement 1.3.10 SINP metadata standard : Objectif du cadre d''acquisition, tel que défini par la nomenclature TypeDispositifValue - OBLIGATOIRE'; + +ALTER TABLE gn_meta.cor_acquisition_framework_objectif + ADD CONSTRAINT check_cor_acquisition_framework_objectif CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_objectif, 'CA_OBJECTIFS'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_objectif + ADD CONSTRAINT pk_cor_acquisition_framework_objectif PRIMARY KEY (id_acquisition_framework, id_nomenclature_objectif); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_objectif + ADD CONSTRAINT fk_cor_acquisition_framework_objectif_id_acquisition_framework FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_objectif + ADD CONSTRAINT fk_cor_acquisition_framework_objectif_id_nomenclature_objectif FOREIGN KEY (id_nomenclature_objectif) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/cor_acquisition_framework_publication.sql b/data/db_state/gn_meta/cor_acquisition_framework_publication.sql new file mode 100644 index 0000000000..fa0525db62 --- /dev/null +++ b/data/db_state/gn_meta/cor_acquisition_framework_publication.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_meta.cor_acquisition_framework_publication ( + id_acquisition_framework integer NOT NULL, + id_publication integer NOT NULL +); + +COMMENT ON TABLE gn_meta.cor_acquisition_framework_publication IS 'A acquisition framework can have 0 or n "publication". Implement 1.3.10 SINP metadata standard : Référence(s) bibliographique(s) éventuelle(s) concernant le cadre d''acquisition - RECOMMANDE'; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_publication + ADD CONSTRAINT pk_cor_acquisition_framework_publication PRIMARY KEY (id_acquisition_framework, id_publication); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_publication + ADD CONSTRAINT fk_cor_acquisition_framework_publication_id_acquisition_framewo FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_publication + ADD CONSTRAINT fk_cor_acquisition_framework_publication_id_publication FOREIGN KEY (id_publication) REFERENCES gn_meta.sinp_datatype_publications(id_publication) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_meta/cor_acquisition_framework_territory.sql b/data/db_state/gn_meta/cor_acquisition_framework_territory.sql new file mode 100644 index 0000000000..f0998c24bc --- /dev/null +++ b/data/db_state/gn_meta/cor_acquisition_framework_territory.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_meta.cor_acquisition_framework_territory ( + id_acquisition_framework integer NOT NULL, + id_nomenclature_territory integer NOT NULL +); + +COMMENT ON TABLE gn_meta.cor_acquisition_framework_territory IS 'A acquisition_framework must have 1 or n "territoire". Implement 1.3.10 SINP metadata standard : Cible géographique du jeu de données, ou zone géographique visée par le jeu. Défini par une valeur dans la nomenclature TerritoireValue. - OBLIGATOIRE'; + +ALTER TABLE gn_meta.cor_acquisition_framework_territory + ADD CONSTRAINT check_cor_af_territory CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_territory, 'TERRITOIRE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_territory + ADD CONSTRAINT pk_cor_acquisition_framework_territory PRIMARY KEY (id_acquisition_framework, id_nomenclature_territory); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_territory + ADD CONSTRAINT fk_cor_af_territory_id_af FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_territory + ADD CONSTRAINT fk_cor_af_territory_id_nomenclature_territory FOREIGN KEY (id_nomenclature_territory) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/cor_acquisition_framework_voletsinp.sql b/data/db_state/gn_meta/cor_acquisition_framework_voletsinp.sql new file mode 100644 index 0000000000..9d9724122d --- /dev/null +++ b/data/db_state/gn_meta/cor_acquisition_framework_voletsinp.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_meta.cor_acquisition_framework_voletsinp ( + id_acquisition_framework integer NOT NULL, + id_nomenclature_voletsinp integer NOT NULL +); + +COMMENT ON TABLE gn_meta.cor_acquisition_framework_voletsinp IS 'A acquisition framework can have 0 or n "voletSINP". Implement 1.3.10 SINP metadata standard : Volet du SINP concerné par le dispositif de collecte, tel que défini dans la nomenclature voletSINPValue - FACULTATIF'; + +ALTER TABLE gn_meta.cor_acquisition_framework_voletsinp + ADD CONSTRAINT check_cor_acquisition_framework_voletsinp CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_voletsinp, 'VOLET_SINP'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_voletsinp + ADD CONSTRAINT pk_cor_acquisition_framework_voletsinp PRIMARY KEY (id_acquisition_framework, id_nomenclature_voletsinp); + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_voletsinp + ADD CONSTRAINT fk_cor_acquisition_framework_voletsinp_id_acquisition_framework FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_acquisition_framework_voletsinp + ADD CONSTRAINT fk_cor_acquisition_framework_voletsinp_id_nomenclature_voletsin FOREIGN KEY (id_nomenclature_voletsinp) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/cor_dataset_actor.sql b/data/db_state/gn_meta/cor_dataset_actor.sql new file mode 100644 index 0000000000..15a117e0d2 --- /dev/null +++ b/data/db_state/gn_meta/cor_dataset_actor.sql @@ -0,0 +1,48 @@ + +CREATE TABLE gn_meta.cor_dataset_actor ( + id_cda integer NOT NULL, + id_dataset integer NOT NULL, + id_role integer, + id_organism integer, + id_nomenclature_actor_role integer NOT NULL, + CONSTRAINT check_id_role_not_group CHECK ((NOT gn_commons.role_is_group(id_role))), + CONSTRAINT check_is_actor_in_cor_dataset_actor CHECK (((id_role IS NOT NULL) OR (id_organism IS NOT NULL))) +); + +COMMENT ON TABLE gn_meta.cor_dataset_actor IS 'A dataset must have 1 or n actor ""pointContactJdd"". Implement 1.3.10 SINP metadata standard : Point de contact principal pour les données du jeu de données, et autres éventuels contacts (fournisseur ou producteur). (Règle : Un contact au moins devra avoir roleActeur à 1 - Les autres types possibles pour roleActeur sont 5 et 6 (fournisseur et producteur)) - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.cor_dataset_actor.id_nomenclature_actor_role IS 'Correspondance standard SINP = roleActeur : Rôle de l''acteur tel que défini dans la nomenclature RoleActeurValue - OBLIGATOIRE'; + +CREATE SEQUENCE gn_meta.cor_dataset_actor_id_cda_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.cor_dataset_actor_id_cda_seq OWNED BY gn_meta.cor_dataset_actor.id_cda; + +ALTER TABLE gn_meta.cor_dataset_actor + ADD CONSTRAINT check_cor_dataset_actor CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_actor_role, 'ROLE_ACTEUR'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT check_is_unique_cor_dataset_actor_organism UNIQUE (id_dataset, id_organism, id_nomenclature_actor_role); + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT check_is_unique_cor_dataset_actor_role UNIQUE (id_dataset, id_role, id_nomenclature_actor_role); + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT pk_cor_dataset_actor PRIMARY KEY (id_cda); + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT fk_cor_dataset_actor_id_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT fk_cor_dataset_actor_id_nomenclature_actor_role FOREIGN KEY (id_nomenclature_actor_role) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT fk_dataset_actor_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_dataset_actor + ADD CONSTRAINT fk_dataset_actor_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_meta/cor_dataset_protocol.sql b/data/db_state/gn_meta/cor_dataset_protocol.sql new file mode 100644 index 0000000000..168ce460ff --- /dev/null +++ b/data/db_state/gn_meta/cor_dataset_protocol.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_meta.cor_dataset_protocol ( + id_dataset integer NOT NULL, + id_protocol integer NOT NULL +); + +COMMENT ON TABLE gn_meta.cor_dataset_protocol IS 'A dataset can have 0 or n "protocole". Implement 1.3.10 SINP metadata standard : Protocole(s) rattaché(s) au jeu de données (protocole de synthèse et/ou de collecte). On se rapportera au type "Protocole Type". - RECOMMANDE'; + +ALTER TABLE ONLY gn_meta.cor_dataset_protocol + ADD CONSTRAINT pk_cor_dataset_protocol PRIMARY KEY (id_dataset, id_protocol); + +ALTER TABLE ONLY gn_meta.cor_dataset_protocol + ADD CONSTRAINT fk_cor_dataset_protocol_id_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_dataset_protocol + ADD CONSTRAINT fk_cor_dataset_protocol_id_protocol FOREIGN KEY (id_protocol) REFERENCES gn_meta.sinp_datatype_protocols(id_protocol) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/cor_dataset_territory.sql b/data/db_state/gn_meta/cor_dataset_territory.sql new file mode 100644 index 0000000000..100a00394e --- /dev/null +++ b/data/db_state/gn_meta/cor_dataset_territory.sql @@ -0,0 +1,23 @@ + +CREATE TABLE gn_meta.cor_dataset_territory ( + id_dataset integer NOT NULL, + id_nomenclature_territory integer NOT NULL, + territory_desc text +); + +COMMENT ON TABLE gn_meta.cor_dataset_territory IS 'A dataset must have 1 or n "territoire". Implement 1.3.10 SINP metadata standard : Cible géographique du jeu de données, ou zone géographique visée par le jeu. Défini par une valeur dans la nomenclature TerritoireValue. - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.cor_dataset_territory.territory_desc IS 'Correspondance standard SINP = precisionGeographique : Précisions sur le territoire visé - FACULTATIF'; + +ALTER TABLE gn_meta.cor_dataset_territory + ADD CONSTRAINT check_cor_dataset_territory CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_territory, 'TERRITOIRE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.cor_dataset_territory + ADD CONSTRAINT pk_cor_dataset_territory PRIMARY KEY (id_dataset, id_nomenclature_territory); + +ALTER TABLE ONLY gn_meta.cor_dataset_territory + ADD CONSTRAINT fk_cor_dataset_territory_id_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_meta.cor_dataset_territory + ADD CONSTRAINT fk_cor_dataset_territory_id_nomenclature_territory FOREIGN KEY (id_nomenclature_territory) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/sinp_datatype_protocols.sql b/data/db_state/gn_meta/sinp_datatype_protocols.sql new file mode 100644 index 0000000000..72b39eb449 --- /dev/null +++ b/data/db_state/gn_meta/sinp_datatype_protocols.sql @@ -0,0 +1,42 @@ + +CREATE TABLE gn_meta.sinp_datatype_protocols ( + id_protocol integer NOT NULL, + unique_protocol_id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + protocol_name character varying(255) NOT NULL, + protocol_desc text, + id_nomenclature_protocol_type integer NOT NULL, + protocol_url character varying(255) +); + +COMMENT ON TABLE gn_meta.sinp_datatype_protocols IS 'Define a SINP datatype Types::ProtocoleType.'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.id_protocol IS 'Internal value for primary and foreign keys'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.unique_protocol_id IS 'Internal value to reference external protocol id value'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.protocol_name IS 'Correspondance standard SINP = libelle : Libellé du protocole : donne le nom du protocole en quelques mots - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.protocol_desc IS 'Correspondance standard SINP = description : Description du protocole : décrit le contenu du protocole - FACULTATIF.'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.id_nomenclature_protocol_type IS 'Correspondance standard SINP = typeProtocole : Type du protocole, tel que défini dans la nomenclature TypeProtocoleValue - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_protocols.protocol_url IS 'Correspondance standard SINP = uRL : URL d''accès à un document permettant de décrire le protocole - RECOMMANDE.'; + +CREATE SEQUENCE gn_meta.sinp_datatype_protocols_id_protocol_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.sinp_datatype_protocols_id_protocol_seq OWNED BY gn_meta.sinp_datatype_protocols.id_protocol; + +ALTER TABLE gn_meta.sinp_datatype_protocols + ADD CONSTRAINT check_sinp_datatype_protocol_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_protocol_type, 'TYPE_PROTOCOLE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.sinp_datatype_protocols + ADD CONSTRAINT pk_sinp_datatype_protocols PRIMARY KEY (id_protocol); + +ALTER TABLE ONLY gn_meta.sinp_datatype_protocols + ADD CONSTRAINT unique_sinp_datatype_protocols_uuid UNIQUE (unique_protocol_id); + diff --git a/data/db_state/gn_meta/sinp_datatype_publications.sql b/data/db_state/gn_meta/sinp_datatype_publications.sql new file mode 100644 index 0000000000..d5a2b70603 --- /dev/null +++ b/data/db_state/gn_meta/sinp_datatype_publications.sql @@ -0,0 +1,33 @@ + +CREATE TABLE gn_meta.sinp_datatype_publications ( + id_publication integer NOT NULL, + unique_publication_id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + publication_reference text NOT NULL, + publication_url text +); + +COMMENT ON TABLE gn_meta.sinp_datatype_publications IS 'Define a SINP datatype Concepts::Publication.'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_publications.id_publication IS 'Internal value for primary and foreign keys'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_publications.unique_publication_id IS 'Internal value to reference external publication id value'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_publications.publication_reference IS 'Correspondance standard SINP = referencePublication : Référence complète de la publication suivant la nomenclature ISO 690 - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.sinp_datatype_publications.publication_url IS 'Correspondance standard SINP = URLPublication : Adresse à laquelle trouver la publication - RECOMMANDE.'; + +CREATE SEQUENCE gn_meta.sinp_datatype_publications_id_publication_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.sinp_datatype_publications_id_publication_seq OWNED BY gn_meta.sinp_datatype_publications.id_publication; + +ALTER TABLE ONLY gn_meta.sinp_datatype_publications + ADD CONSTRAINT pk_sinp_datatype_publications PRIMARY KEY (id_publication); + +ALTER TABLE ONLY gn_meta.sinp_datatype_publications + ADD CONSTRAINT unique_sinp_datatype_publications_uuid UNIQUE (unique_publication_id); + diff --git a/data/db_state/gn_meta/t_acquisition_frameworks.sql b/data/db_state/gn_meta/t_acquisition_frameworks.sql new file mode 100644 index 0000000000..6752425aea --- /dev/null +++ b/data/db_state/gn_meta/t_acquisition_frameworks.sql @@ -0,0 +1,83 @@ + +CREATE TABLE gn_meta.t_acquisition_frameworks ( + id_acquisition_framework integer NOT NULL, + unique_acquisition_framework_id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + acquisition_framework_name character varying(255) NOT NULL, + acquisition_framework_desc text NOT NULL, + id_nomenclature_territorial_level integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('NIVEAU_TERRITORIAL'::character varying), + territory_desc text, + keywords text, + id_nomenclature_financing_type integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('TYPE_FINANCEMENT'::character varying), + target_description text, + ecologic_or_geologic_target text, + acquisition_framework_parent_id integer, + is_parent boolean, + opened boolean DEFAULT true, + id_digitizer integer, + acquisition_framework_start_date date NOT NULL, + acquisition_framework_end_date date, + meta_create_date timestamp without time zone NOT NULL, + meta_update_date timestamp without time zone, + initial_closing_date timestamp without time zone +); + +COMMENT ON TABLE gn_meta.t_acquisition_frameworks IS 'Define a acquisition framework that embed datasets. Implement 1.3.10 SINP metadata standard'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.id_acquisition_framework IS 'Internal value for primary and foreign keys'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.unique_acquisition_framework_id IS 'Correspondance standard SINP = identifiantCadre'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.acquisition_framework_name IS 'Correspondance standard SINP = libelle'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.acquisition_framework_desc IS 'Correspondance standard SINP = description'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.id_nomenclature_territorial_level IS 'Correspondance standard SINP = niveauTerritorial'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.keywords IS 'Correspondance standard SINP = motCle : Mot(s)-clé(s) représentatifs du cadre d''acquisition, séparés par des virgules - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.id_nomenclature_financing_type IS 'Correspondance standard SINP = typeFinancement : Type de financement pour le cadre d''acquisition, tel que défini dans la nomenclature TypeFinancementValue - RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.target_description IS 'Correspondance standard SINP = descriptionCible : Description de la cible taxonomique ou géologique pour le cadre d''acquisition. (ex : pteridophyta) - RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.ecologic_or_geologic_target IS 'Correspondance standard SINP = cibleEcologiqueOuGeologique : Cet attribut sera composé de CD_NOM de TAXREF, séparés par des points virgules, s''il s''agit de taxons, ou de CD_HAB de HABREF, séparés par des points virgules, s''il s''agit d''habitats. - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.acquisition_framework_parent_id IS 'Correspondance standard SINP = idMetaCadreParent : Indique, par le biais de l''existence d''un identifiant unique de métacadre parent, si le cadre d''acquisition ici présent est contenu dans un autre cadre d''acquisition. S''il y un cadre parent, c''est son identifiant qui doit être renseigné ici. - RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.is_parent IS 'Correspondance standard SINP = estMetaCadre : Indique si ce dispositif est un métacadre, et donc s''il contient d''autres cadres d''acquisition. Cet attribut est un booléen : 0 pour false (n''est pas un métacadre), 1 pour true (est un métacadre) - OBLIGATOIRE.'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.acquisition_framework_start_date IS 'Correspondance standard SINP = ReferenceTemporelle:dateLancement : Date de lancement du cadre d''acquisition - OBLIGATOIRE.'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.acquisition_framework_end_date IS 'Correspondance standard SINP = ReferenceTemporelle:dateCloture : Date de clôture du cadre d''acquisition. Si elle n''est pas remplie, on considère que le cadre est toujours en activité. - RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.meta_create_date IS 'Correspondance standard SINP = dateCreationMtd : Date de création de la fiche de métadonnées du cadre d''acquisition. - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_acquisition_frameworks.meta_update_date IS 'Correspondance standard SINP = dateMiseAJourMtd : Date de mise à jour de la fiche de métadonnées du cadre d''acquisition. - FACULTATIF'; + +CREATE SEQUENCE gn_meta.t_acquisition_frameworks_id_acquisition_framework_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.t_acquisition_frameworks_id_acquisition_framework_seq OWNED BY gn_meta.t_acquisition_frameworks.id_acquisition_framework; + +ALTER TABLE gn_meta.t_acquisition_frameworks + ADD CONSTRAINT check_t_acquisition_financing_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_financing_type, 'TYPE_FINANCEMENT'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_acquisition_frameworks + ADD CONSTRAINT check_t_acquisition_frameworks_territorial_level CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_territorial_level, 'NIVEAU_TERRITORIAL'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.t_acquisition_frameworks + ADD CONSTRAINT pk_t_acquisition_frameworks PRIMARY KEY (id_acquisition_framework); + +ALTER TABLE ONLY gn_meta.t_acquisition_frameworks + ADD CONSTRAINT unique_acquisition_frameworks_uuid UNIQUE (unique_acquisition_framework_id); + +CREATE UNIQUE INDEX i_unique_t_acquisition_framework_unique_id ON gn_meta.t_acquisition_frameworks USING btree (unique_acquisition_framework_id); + +CREATE TRIGGER tri_meta_dates_change_t_acquisition_frameworks BEFORE INSERT OR UPDATE ON gn_meta.t_acquisition_frameworks FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY gn_meta.t_acquisition_frameworks + ADD CONSTRAINT fk_t_acquisition_frameworks_id_digitizer FOREIGN KEY (id_digitizer) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_meta/t_bibliographical_references.sql b/data/db_state/gn_meta/t_bibliographical_references.sql new file mode 100644 index 0000000000..55201e837d --- /dev/null +++ b/data/db_state/gn_meta/t_bibliographical_references.sql @@ -0,0 +1,16 @@ + +CREATE TABLE gn_meta.t_bibliographical_references ( + id_bibliographic_reference bigint DEFAULT nextval('gn_meta.t_bibliographical_references_id_bibliographic_reference_seq'::regclass) NOT NULL, + id_acquisition_framework integer NOT NULL, + publication_url character varying, + publication_reference character varying NOT NULL +); + +COMMENT ON TABLE gn_meta.t_bibliographical_references IS 'A acquisition_framework must have 0 or n "publical references". Implement 1.3.10 SINP metadata standard : Référence(s) bibliographique(s) éventuelle(s) concernant le cadre d''acquisition. - RECOMMANDE'; + +ALTER TABLE ONLY gn_meta.t_bibliographical_references + ADD CONSTRAINT t_bibliographical_references_pkey PRIMARY KEY (id_bibliographic_reference); + +ALTER TABLE ONLY gn_meta.t_bibliographical_references + ADD CONSTRAINT t_bibliographical_references_id_acquisition_framework_fkey FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON DELETE CASCADE; + diff --git a/data/db_state/gn_meta/t_datasets.sql b/data/db_state/gn_meta/t_datasets.sql new file mode 100644 index 0000000000..aec3977390 --- /dev/null +++ b/data/db_state/gn_meta/t_datasets.sql @@ -0,0 +1,136 @@ + +CREATE TABLE gn_meta.t_datasets ( + id_dataset integer NOT NULL, + unique_dataset_id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_acquisition_framework integer NOT NULL, + dataset_name character varying(255) NOT NULL, + dataset_shortname character varying(255) NOT NULL, + dataset_desc text NOT NULL, + id_nomenclature_data_type integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('DATA_TYP'::character varying) NOT NULL, + keywords text, + marine_domain boolean NOT NULL, + terrestrial_domain boolean NOT NULL, + id_nomenclature_dataset_objectif integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('JDD_OBJECTIFS'::character varying) NOT NULL, + bbox_west real, + bbox_east real, + bbox_south real, + bbox_north real, + id_nomenclature_collecting_method integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('METHO_RECUEIL'::character varying) NOT NULL, + id_nomenclature_data_origin integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('DS_PUBLIQUE'::character varying) NOT NULL, + id_nomenclature_source_status integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('STATUT_SOURCE'::character varying) NOT NULL, + id_nomenclature_resource_type integer DEFAULT ref_nomenclatures.get_default_nomenclature_value('RESOURCE_TYP'::character varying) NOT NULL, + active boolean DEFAULT true NOT NULL, + validable boolean DEFAULT true, + id_digitizer integer, + id_taxa_list integer, + meta_create_date timestamp without time zone NOT NULL, + meta_update_date timestamp without time zone +); + +COMMENT ON TABLE gn_meta.t_datasets IS 'A dataset is a dataset or a survey and each observation is attached to a dataset. A lot allows to qualify datas to which it is attached (producer, owner, manager, gestionnaire, financer, public data yes/no). A dataset can be attached to a program. GeoNature V2 backoffice allows to manage datasets.'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_dataset IS 'Internal value for primary and foreign keys.'; + +COMMENT ON COLUMN gn_meta.t_datasets.unique_dataset_id IS 'Correspondance standard SINP = identifiantJdd : Identifiant unique du jeu de données sous la forme d''un UUID. Il devra être sous la forme d''un UUID - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_acquisition_framework IS ' Internal value for foreign keys with t_acquisition_frameworks table'; + +COMMENT ON COLUMN gn_meta.t_datasets.dataset_name IS 'Correspondance standard SINP = libelle : Nom du jeu de données (150 caractères) - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.dataset_shortname IS 'Correspondance standard SINP = libelleCourt : Libellé court (30 caractères) du jeu de données - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.dataset_desc IS 'Correspondance standard SINP = description : Description du jeu de données - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_data_type IS 'Correspondance standard SINP = typeDonnees : Type de données du jeu de données tel que défini dans la nomenclature TypeDonneesValue - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.keywords IS 'Correspondance standard SINP = motCle : Mot(s)-clé(s) représentatifs du jeu de données, séparés par des virgules - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_datasets.marine_domain IS 'Correspondance standard SINP = domaineMarin : Indique si le jeu de données concerne le domaine marin - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.terrestrial_domain IS 'Correspondance standard SINP = domaineTerrestre : Indique si le jeu de données concerne le domaine terrestre - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_dataset_objectif IS 'Correspondance standard SINP = objectifJdd : Objectif du jeu de données tel que défini par la nomenclature ObjectifJeuDonneesValue - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.bbox_west IS 'Correspondance standard SINP = empriseGeographique::borneOuest : Point le plus à l''ouest de la zone géographique délimitant le jeu de données - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_datasets.bbox_east IS 'Correspondance standard SINP = empriseGeographique::borneEst : Point le plus à l''est de la zone géographique délimitant le jeu de données - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_datasets.bbox_south IS 'Correspondance standard SINP = empriseGeographique::borneSud : Point le plus au sud de la zone géographique délimitant le jeu de données - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_datasets.bbox_north IS 'Correspondance standard SINP = empriseGeographique::borneNord : Point le plus au nord de la zone géographique délimitant le jeu de données - FACULTATIF'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_collecting_method IS 'Correspondance standard SINP = methodeRecueil : Méthode de recueil des données : Ensemble de techniques, savoir-faire et outils mobilisés pour collecter des données - RECOMMANDE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_data_origin IS 'Public, privée, etc... Dans le standard SINP cette information se situe au niveau de chaque occurrence de taxon. On considère ici qu''elle doit être homoogène pour un même jeu de données - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_source_status IS 'Terrain, littérature, etc... Dans le standard SINP cette information se situe au niveau de chaque occurrence de taxon. On considère ici qu''elle doit être homoogène pour un même jeu de données - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.id_nomenclature_resource_type IS 'jeu de données ou série de jeu de données. Dans le standard SINP cette information se situe au niveau de chaque occurrence de taxon. On considère ici qu''elle doit être homoogène pour un même jeu de données - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.meta_create_date IS 'Correspondance standard SINP = dateCreation : Date de création de la fiche de métadonnées du jeu de données, format AAAA-MM-JJ - OBLIGATOIRE'; + +COMMENT ON COLUMN gn_meta.t_datasets.meta_update_date IS 'Identifiant de la liste de taxon associé au JDD. FK: taxonomie.bib_liste'; + +CREATE SEQUENCE gn_meta.t_datasets_id_dataset_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_meta.t_datasets_id_dataset_seq OWNED BY gn_meta.t_datasets.id_dataset; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_collecting_method CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_collecting_method, 'METHO_RECUEIL'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_data_origin CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_data_origin, 'DS_PUBLIQUE'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_data_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_data_type, 'DATA_TYP'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_objectif CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_dataset_objectif, 'JDD_OBJECTIFS'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_resource_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_resource_type, 'RESOURCE_TYP'::character varying)) NOT VALID; + +ALTER TABLE gn_meta.t_datasets + ADD CONSTRAINT check_t_datasets_source_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_source_status, 'STATUT_SOURCE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT pk_t_datasets PRIMARY KEY (id_dataset); + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT unique_dataset_uuid UNIQUE (unique_dataset_id); + +CREATE INDEX i_t_datasets_id_acquisition_framework ON gn_meta.t_datasets USING btree (id_acquisition_framework); + +CREATE UNIQUE INDEX i_unique_t_datasets_unique_id ON gn_meta.t_datasets USING btree (unique_dataset_id); + +CREATE TRIGGER tri_meta_dates_change_t_datasets BEFORE INSERT OR UPDATE ON gn_meta.t_datasets FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_collecting_method FOREIGN KEY (id_nomenclature_collecting_method) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_data_origin FOREIGN KEY (id_nomenclature_data_origin) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_data_type FOREIGN KEY (id_nomenclature_data_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_id_digitizer FOREIGN KEY (id_digitizer) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_objectif FOREIGN KEY (id_nomenclature_dataset_objectif) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_resource_type FOREIGN KEY (id_nomenclature_resource_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_source_status FOREIGN KEY (id_nomenclature_source_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_meta.t_datasets + ADD CONSTRAINT fk_t_datasets_t_acquisition_frameworks FOREIGN KEY (id_acquisition_framework) REFERENCES gn_meta.t_acquisition_frameworks(id_acquisition_framework) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/bib_type_site.sql b/data/db_state/gn_monitoring/bib_type_site.sql new file mode 100644 index 0000000000..ce90990476 --- /dev/null +++ b/data/db_state/gn_monitoring/bib_type_site.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_monitoring.bib_type_site ( + id_nomenclature_type_site integer NOT NULL, + config json +); + +COMMENT ON TABLE gn_monitoring.bib_type_site IS 'Table de définition des champs associés aux types de sites'; + +ALTER TABLE ONLY gn_monitoring.bib_type_site + ADD CONSTRAINT bib_type_site_pkey PRIMARY KEY (id_nomenclature_type_site); + +ALTER TABLE gn_monitoring.bib_type_site + ADD CONSTRAINT ck_bib_type_site_id_nomenclature_type_site CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_type_site, 'TYPE_SITE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_monitoring.bib_type_site + ADD CONSTRAINT fk_t_nomenclatures_id_nomenclature_type_site FOREIGN KEY (id_nomenclature_type_site) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/gn_monitoring/cor_module_type.sql b/data/db_state/gn_monitoring/cor_module_type.sql new file mode 100644 index 0000000000..2da651cd83 --- /dev/null +++ b/data/db_state/gn_monitoring/cor_module_type.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_monitoring.cor_module_type ( + id_type_site integer NOT NULL, + id_module integer NOT NULL +); + +ALTER TABLE ONLY gn_monitoring.cor_module_type + ADD CONSTRAINT pk_cor_module_type PRIMARY KEY (id_type_site, id_module); + +ALTER TABLE ONLY gn_monitoring.cor_module_type + ADD CONSTRAINT fk_cor_module_type_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.cor_module_type + ADD CONSTRAINT fk_cor_module_type_id_nomenclature FOREIGN KEY (id_type_site) REFERENCES gn_monitoring.bib_type_site(id_nomenclature_type_site) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/cor_site_area.sql b/data/db_state/gn_monitoring/cor_site_area.sql new file mode 100644 index 0000000000..cc1a064f63 --- /dev/null +++ b/data/db_state/gn_monitoring/cor_site_area.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_monitoring.cor_site_area ( + id_base_site integer NOT NULL, + id_area integer NOT NULL +); + +ALTER TABLE ONLY gn_monitoring.cor_site_area + ADD CONSTRAINT pk_cor_site_area PRIMARY KEY (id_base_site, id_area); + +ALTER TABLE ONLY gn_monitoring.cor_site_area + ADD CONSTRAINT fk_cor_site_area_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area); + +ALTER TABLE ONLY gn_monitoring.cor_site_area + ADD CONSTRAINT fk_cor_site_area_id_base_site FOREIGN KEY (id_base_site) REFERENCES gn_monitoring.t_base_sites(id_base_site) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/cor_site_module.sql b/data/db_state/gn_monitoring/cor_site_module.sql new file mode 100644 index 0000000000..5651b0ede8 --- /dev/null +++ b/data/db_state/gn_monitoring/cor_site_module.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_monitoring.cor_site_module ( + id_base_site integer NOT NULL, + id_module integer NOT NULL +); + +ALTER TABLE ONLY gn_monitoring.cor_site_module + ADD CONSTRAINT pk_cor_site_module PRIMARY KEY (id_base_site, id_module); + +ALTER TABLE ONLY gn_monitoring.cor_site_module + ADD CONSTRAINT fk_cor_site_module_id_base_site FOREIGN KEY (id_base_site) REFERENCES gn_monitoring.t_base_sites(id_base_site) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.cor_site_module + ADD CONSTRAINT fk_cor_site_module_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/cor_site_type.sql b/data/db_state/gn_monitoring/cor_site_type.sql new file mode 100644 index 0000000000..8f957826d1 --- /dev/null +++ b/data/db_state/gn_monitoring/cor_site_type.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_monitoring.cor_site_type ( + id_type_site integer NOT NULL, + id_base_site integer NOT NULL +); + +COMMENT ON TABLE gn_monitoring.cor_site_type IS 'Table d''association entre les sites et les types de sites'; + +ALTER TABLE ONLY gn_monitoring.cor_site_type + ADD CONSTRAINT pk_cor_site_type PRIMARY KEY (id_type_site, id_base_site); + +ALTER TABLE ONLY gn_monitoring.cor_site_type + ADD CONSTRAINT fk_cor_site_type_id_base_site FOREIGN KEY (id_base_site) REFERENCES gn_monitoring.t_base_sites(id_base_site) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.cor_site_type + ADD CONSTRAINT fk_cor_site_type_id_nomenclature_type_site FOREIGN KEY (id_type_site) REFERENCES gn_monitoring.bib_type_site(id_nomenclature_type_site) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/cor_sites_group_module.sql b/data/db_state/gn_monitoring/cor_sites_group_module.sql new file mode 100644 index 0000000000..747cfdae4e --- /dev/null +++ b/data/db_state/gn_monitoring/cor_sites_group_module.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_monitoring.cor_sites_group_module ( + id_sites_group integer NOT NULL, + id_module integer NOT NULL +); + +ALTER TABLE ONLY gn_monitoring.cor_sites_group_module + ADD CONSTRAINT pk_cor_sites_group_module PRIMARY KEY (id_sites_group, id_module); + +ALTER TABLE ONLY gn_monitoring.cor_sites_group_module + ADD CONSTRAINT fk_cor_sites_group_module_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.cor_sites_group_module + ADD CONSTRAINT fk_cor_sites_group_module_id_sites_group FOREIGN KEY (id_sites_group) REFERENCES gn_monitoring.t_sites_groups(id_sites_group) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/cor_visit_observer.sql b/data/db_state/gn_monitoring/cor_visit_observer.sql new file mode 100644 index 0000000000..33f41108ff --- /dev/null +++ b/data/db_state/gn_monitoring/cor_visit_observer.sql @@ -0,0 +1,18 @@ + +CREATE TABLE gn_monitoring.cor_visit_observer ( + id_base_visit integer NOT NULL, + id_role integer NOT NULL, + unique_id_core_visit_observer uuid DEFAULT public.uuid_generate_v4() NOT NULL +); + +ALTER TABLE ONLY gn_monitoring.cor_visit_observer + ADD CONSTRAINT pk_cor_visit_observer PRIMARY KEY (id_base_visit, id_role); + +CREATE TRIGGER tri_log_changes_cor_visit_observer AFTER INSERT OR DELETE OR UPDATE ON gn_monitoring.cor_visit_observer FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +ALTER TABLE ONLY gn_monitoring.cor_visit_observer + ADD CONSTRAINT fk_cor_visit_observer_id_base_visit FOREIGN KEY (id_base_visit) REFERENCES gn_monitoring.t_base_visits(id_base_visit) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.cor_visit_observer + ADD CONSTRAINT fk_cor_visit_observer_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_base_sites.sql b/data/db_state/gn_monitoring/t_base_sites.sql new file mode 100644 index 0000000000..a89f72234d --- /dev/null +++ b/data/db_state/gn_monitoring/t_base_sites.sql @@ -0,0 +1,57 @@ + +CREATE TABLE gn_monitoring.t_base_sites ( + id_base_site integer NOT NULL, + id_inventor integer, + id_digitiser integer, + base_site_name character varying(255) NOT NULL, + base_site_description text, + base_site_code character varying(25) DEFAULT NULL::character varying, + first_use_date date, + geom public.geometry(Geometry,4326) NOT NULL, + geom_local public.geometry(Geometry,2154), + altitude_min integer, + altitude_max integer, + uuid_base_site uuid DEFAULT public.uuid_generate_v4(), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + CONSTRAINT enforce_dims_geom CHECK ((public.st_ndims(geom) = 2)), + CONSTRAINT enforce_srid_geom CHECK ((public.st_srid(geom) = 4326)) +); + +CREATE SEQUENCE gn_monitoring.t_base_sites_id_base_site_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_base_sites_id_base_site_seq OWNED BY gn_monitoring.t_base_sites.id_base_site; + +ALTER TABLE ONLY gn_monitoring.t_base_sites + ADD CONSTRAINT pk_t_base_sites PRIMARY KEY (id_base_site); + +CREATE INDEX idx_t_base_sites_geom ON gn_monitoring.t_base_sites USING gist (geom); + +CREATE INDEX idx_t_base_sites_id_inventor ON gn_monitoring.t_base_sites USING btree (id_inventor); + +CREATE TRIGGER trg_cor_site_area AFTER INSERT OR UPDATE OF geom ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION gn_monitoring.fct_trg_cor_site_area(); + +CREATE TRIGGER tri_calculate_geom_local BEFORE INSERT OR UPDATE ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_geom_local('geom', 'geom_local'); + +CREATE TRIGGER tri_insert_calculate_altitude BEFORE INSERT ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +CREATE TRIGGER tri_log_changes AFTER INSERT OR DELETE OR UPDATE ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_meta_dates_change_t_base_sites BEFORE INSERT OR UPDATE ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +CREATE TRIGGER tri_t_base_sites_calculate_alt BEFORE INSERT OR UPDATE ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +CREATE TRIGGER tri_update_calculate_altitude BEFORE UPDATE OF geom_local, geom ON gn_monitoring.t_base_sites FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +ALTER TABLE ONLY gn_monitoring.t_base_sites + ADD CONSTRAINT fk_t_base_sites_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_sites + ADD CONSTRAINT fk_t_base_sites_id_inventor FOREIGN KEY (id_inventor) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_base_visits.sql b/data/db_state/gn_monitoring/t_base_visits.sql new file mode 100644 index 0000000000..55252cd3ec --- /dev/null +++ b/data/db_state/gn_monitoring/t_base_visits.sql @@ -0,0 +1,65 @@ + +CREATE TABLE gn_monitoring.t_base_visits ( + id_base_visit integer NOT NULL, + id_base_site integer, + id_dataset integer NOT NULL, + id_module integer NOT NULL, + id_digitiser integer, + visit_date_min date NOT NULL, + visit_date_max date, + id_nomenclature_tech_collect_campanule integer DEFAULT ref_nomenclatures.get_id_nomenclature('TECHNIQUE_OBS'::character varying, '133'::character varying), + id_nomenclature_grp_typ integer DEFAULT ref_nomenclatures.get_id_nomenclature('TYP_GRP'::character varying, 'PASS'::character varying), + comments text, + uuid_base_visit uuid DEFAULT public.uuid_generate_v4(), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + observers_txt text +); + +CREATE SEQUENCE gn_monitoring.t_base_visits_id_base_visit_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_base_visits_id_base_visit_seq OWNED BY gn_monitoring.t_base_visits.id_base_visit; + +ALTER TABLE gn_monitoring.t_base_visits + ADD CONSTRAINT check_t_base_visits_id_nomenclature_grp_typ CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_grp_typ, 'TYP_GRP'::character varying)) NOT VALID; + +ALTER TABLE gn_monitoring.t_base_visits + ADD CONSTRAINT check_t_base_visits_id_nomenclature_tech_collect_campanule CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_tech_collect_campanule, 'TECHNIQUE_OBS'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT pk_t_base_visits PRIMARY KEY (id_base_visit); + +CREATE INDEX idx_t_base_visits_fk_bs_id ON gn_monitoring.t_base_visits USING btree (id_base_site); + +CREATE TRIGGER trg_delete_synthese_visits AFTER DELETE ON gn_monitoring.t_base_visits FOR EACH ROW EXECUTE FUNCTION gn_synthese.fct_trg_delete_synthese_visits(); + +CREATE TRIGGER tri_log_changes AFTER INSERT OR DELETE OR UPDATE ON gn_monitoring.t_base_visits FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_meta_dates_change_t_base_visits BEFORE INSERT OR UPDATE ON gn_monitoring.t_base_visits FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +CREATE TRIGGER tri_visite_date_max BEFORE INSERT OR UPDATE OF visit_date_min ON gn_monitoring.t_base_visits FOR EACH ROW EXECUTE FUNCTION gn_monitoring.fct_trg_visite_date_max(); + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_id_base_site FOREIGN KEY (id_base_site) REFERENCES gn_monitoring.t_base_sites(id_base_site) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_id_nomenclature_grp_typ FOREIGN KEY (id_nomenclature_grp_typ) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_id_nomenclature_tech_collect_campanule FOREIGN KEY (id_nomenclature_tech_collect_campanule) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_base_visits + ADD CONSTRAINT fk_t_base_visits_t_datasets FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_module_complements.sql b/data/db_state/gn_monitoring/t_module_complements.sql new file mode 100644 index 0000000000..7f1b054b9e --- /dev/null +++ b/data/db_state/gn_monitoring/t_module_complements.sql @@ -0,0 +1,34 @@ + +CREATE TABLE gn_monitoring.t_module_complements ( + id_module integer NOT NULL, + uuid_module_complement uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_list_observer integer, + id_list_taxonomy integer, + b_synthese boolean DEFAULT true, + taxonomy_display_field_name character varying DEFAULT 'nom_vern,lb_nom'::character varying, + b_draw_sites_group boolean, + data jsonb +); + +CREATE SEQUENCE gn_monitoring.t_module_complements_id_module_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_module_complements_id_module_seq OWNED BY gn_monitoring.t_module_complements.id_module; + +ALTER TABLE ONLY gn_monitoring.t_module_complements + ADD CONSTRAINT pk_t_module_complements PRIMARY KEY (id_module); + +ALTER TABLE ONLY gn_monitoring.t_module_complements + ADD CONSTRAINT fk_t_module_complements_id_list_observer FOREIGN KEY (id_list_observer) REFERENCES utilisateurs.t_listes(id_liste) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_module_complements + ADD CONSTRAINT fk_t_module_complements_id_list_taxonomy FOREIGN KEY (id_list_taxonomy) REFERENCES taxonomie.bib_listes(id_liste) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_module_complements + ADD CONSTRAINT fk_t_module_complements_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_observation_complements.sql b/data/db_state/gn_monitoring/t_observation_complements.sql new file mode 100644 index 0000000000..db0d40a080 --- /dev/null +++ b/data/db_state/gn_monitoring/t_observation_complements.sql @@ -0,0 +1,12 @@ + +CREATE TABLE gn_monitoring.t_observation_complements ( + id_observation integer NOT NULL, + data jsonb +); + +ALTER TABLE ONLY gn_monitoring.t_observation_complements + ADD CONSTRAINT pk_t_observation_complements PRIMARY KEY (id_observation); + +ALTER TABLE ONLY gn_monitoring.t_observation_complements + ADD CONSTRAINT fk_t_observation_complements_id_observation FOREIGN KEY (id_observation) REFERENCES gn_monitoring.t_observations(id_observation) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_observation_details.sql b/data/db_state/gn_monitoring/t_observation_details.sql new file mode 100644 index 0000000000..0629337658 --- /dev/null +++ b/data/db_state/gn_monitoring/t_observation_details.sql @@ -0,0 +1,24 @@ + +CREATE TABLE gn_monitoring.t_observation_details ( + id_observation_detail integer NOT NULL, + id_observation integer NOT NULL, + data jsonb, + uuid_observation_detail uuid DEFAULT public.uuid_generate_v4() NOT NULL +); + +CREATE SEQUENCE gn_monitoring.t_observation_details_id_observation_detail_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_observation_details_id_observation_detail_seq OWNED BY gn_monitoring.t_observation_details.id_observation_detail; + +ALTER TABLE ONLY gn_monitoring.t_observation_details + ADD CONSTRAINT pk_t_observation_details PRIMARY KEY (id_observation_detail); + +ALTER TABLE ONLY gn_monitoring.t_observation_details + ADD CONSTRAINT fk_t_observation_details_id_observation FOREIGN KEY (id_observation) REFERENCES gn_monitoring.t_observations(id_observation) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_observations.sql b/data/db_state/gn_monitoring/t_observations.sql new file mode 100644 index 0000000000..2383305492 --- /dev/null +++ b/data/db_state/gn_monitoring/t_observations.sql @@ -0,0 +1,31 @@ + +CREATE TABLE gn_monitoring.t_observations ( + id_observation integer NOT NULL, + id_base_visit integer NOT NULL, + cd_nom integer NOT NULL, + comments text, + uuid_observation uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_digitiser integer NOT NULL +); + +CREATE SEQUENCE gn_monitoring.t_observations_id_observation_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_observations_id_observation_seq OWNED BY gn_monitoring.t_observations.id_observation; + +ALTER TABLE ONLY gn_monitoring.t_observations + ADD CONSTRAINT pk_t_observations PRIMARY KEY (id_observation); + +CREATE TRIGGER trg_delete_synthese_observations AFTER DELETE ON gn_monitoring.t_observations FOR EACH ROW EXECUTE FUNCTION gn_synthese.fct_trg_delete_synthese_observations(); + +ALTER TABLE ONLY gn_monitoring.t_observations + ADD CONSTRAINT fk_t_observations_id_base_visit FOREIGN KEY (id_base_visit) REFERENCES gn_monitoring.t_base_visits(id_base_visit) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_observations + ADD CONSTRAINT fk_t_observations_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_site_complements.sql b/data/db_state/gn_monitoring/t_site_complements.sql new file mode 100644 index 0000000000..eadcb31066 --- /dev/null +++ b/data/db_state/gn_monitoring/t_site_complements.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_monitoring.t_site_complements ( + id_base_site integer NOT NULL, + id_sites_group integer, + data jsonb +); + +ALTER TABLE ONLY gn_monitoring.t_site_complements + ADD CONSTRAINT pk_t_site_complements PRIMARY KEY (id_base_site); + +ALTER TABLE ONLY gn_monitoring.t_site_complements + ADD CONSTRAINT fk_t_site_complement_id_base_site FOREIGN KEY (id_base_site) REFERENCES gn_monitoring.t_base_sites(id_base_site) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_monitoring.t_site_complements + diff --git a/data/db_state/gn_monitoring/t_sites_groups.sql b/data/db_state/gn_monitoring/t_sites_groups.sql new file mode 100644 index 0000000000..98c3da32ba --- /dev/null +++ b/data/db_state/gn_monitoring/t_sites_groups.sql @@ -0,0 +1,47 @@ + +CREATE TABLE gn_monitoring.t_sites_groups ( + id_sites_group integer NOT NULL, + sites_group_name character varying(255), + sites_group_code character varying(255), + sites_group_description text, + uuid_sites_group uuid DEFAULT public.uuid_generate_v4() NOT NULL, + comments text, + data jsonb, + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + id_digitiser integer, + geom public.geometry(Geometry,4326), + geom_local public.geometry(Geometry,2154), + altitude_min integer, + altitude_max integer, + CONSTRAINT enforce_srid_geom CHECK ((public.st_srid(geom) = 4326)) +); + +CREATE SEQUENCE gn_monitoring.t_sites_groups_id_sites_group_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_monitoring.t_sites_groups_id_sites_group_seq OWNED BY gn_monitoring.t_sites_groups.id_sites_group; + +ALTER TABLE ONLY gn_monitoring.t_sites_groups + ADD CONSTRAINT pk_t_sites_groups PRIMARY KEY (id_sites_group); + +CREATE INDEX idx_t_sites_groups_geom ON gn_monitoring.t_sites_groups USING gist (geom); + +CREATE TRIGGER tri_calculate_geom_local BEFORE INSERT OR UPDATE ON gn_monitoring.t_sites_groups FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_geom_local('geom', 'geom_local'); + +CREATE TRIGGER tri_insert_calculate_altitude BEFORE INSERT ON gn_monitoring.t_sites_groups FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +CREATE TRIGGER tri_meta_dates_change_t_sites_groups BEFORE INSERT OR UPDATE ON gn_monitoring.t_sites_groups FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +CREATE TRIGGER tri_t_sites_groups_calculate_alt BEFORE INSERT OR UPDATE ON gn_monitoring.t_sites_groups FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +CREATE TRIGGER tri_update_calculate_altitude BEFORE UPDATE OF geom_local, geom ON gn_monitoring.t_sites_groups FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom'); + +ALTER TABLE ONLY gn_monitoring.t_sites_groups + ADD CONSTRAINT fk_t_sites_groups_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_monitoring/t_visit_complements.sql b/data/db_state/gn_monitoring/t_visit_complements.sql new file mode 100644 index 0000000000..2dd14ec113 --- /dev/null +++ b/data/db_state/gn_monitoring/t_visit_complements.sql @@ -0,0 +1,12 @@ + +CREATE TABLE gn_monitoring.t_visit_complements ( + id_base_visit integer NOT NULL, + data jsonb +); + +ALTER TABLE ONLY gn_monitoring.t_visit_complements + ADD CONSTRAINT pk_t_visit_complements PRIMARY KEY (id_base_visit); + +ALTER TABLE ONLY gn_monitoring.t_visit_complements + ADD CONSTRAINT fk_t_visit_complements_id_base_visit FOREIGN KEY (id_base_visit) REFERENCES gn_monitoring.t_base_visits(id_base_visit) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_notifications/bib_notifications_categories.sql b/data/db_state/gn_notifications/bib_notifications_categories.sql new file mode 100644 index 0000000000..288bd3591f --- /dev/null +++ b/data/db_state/gn_notifications/bib_notifications_categories.sql @@ -0,0 +1,10 @@ + +CREATE TABLE gn_notifications.bib_notifications_categories ( + code character varying NOT NULL, + label character varying, + description text +); + +ALTER TABLE ONLY gn_notifications.bib_notifications_categories + ADD CONSTRAINT bib_notifications_categories_pkey PRIMARY KEY (code); + diff --git a/data/db_state/gn_notifications/bib_notifications_methods.sql b/data/db_state/gn_notifications/bib_notifications_methods.sql new file mode 100644 index 0000000000..7729878443 --- /dev/null +++ b/data/db_state/gn_notifications/bib_notifications_methods.sql @@ -0,0 +1,10 @@ + +CREATE TABLE gn_notifications.bib_notifications_methods ( + code character varying NOT NULL, + label character varying, + description text +); + +ALTER TABLE ONLY gn_notifications.bib_notifications_methods + ADD CONSTRAINT bib_notifications_methods_pkey PRIMARY KEY (code); + diff --git a/data/db_state/gn_notifications/bib_notifications_templates.sql b/data/db_state/gn_notifications/bib_notifications_templates.sql new file mode 100644 index 0000000000..aff8e7d40d --- /dev/null +++ b/data/db_state/gn_notifications/bib_notifications_templates.sql @@ -0,0 +1,16 @@ + +CREATE TABLE gn_notifications.bib_notifications_templates ( + code_category character varying NOT NULL, + code_method character varying NOT NULL, + content text +); + +ALTER TABLE ONLY gn_notifications.bib_notifications_templates + ADD CONSTRAINT bib_notifications_templates_pkey PRIMARY KEY (code_category, code_method); + +ALTER TABLE ONLY gn_notifications.bib_notifications_templates + ADD CONSTRAINT bib_notifications_templates_code_category_fkey FOREIGN KEY (code_category) REFERENCES gn_notifications.bib_notifications_categories(code); + +ALTER TABLE ONLY gn_notifications.bib_notifications_templates + ADD CONSTRAINT bib_notifications_templates_code_method_fkey FOREIGN KEY (code_method) REFERENCES gn_notifications.bib_notifications_methods(code); + diff --git a/data/db_state/gn_notifications/t_notifications.sql b/data/db_state/gn_notifications/t_notifications.sql new file mode 100644 index 0000000000..07df5c3a90 --- /dev/null +++ b/data/db_state/gn_notifications/t_notifications.sql @@ -0,0 +1,27 @@ + +CREATE TABLE gn_notifications.t_notifications ( + id_notification integer NOT NULL, + id_role integer NOT NULL, + title character varying, + content text, + url character varying, + code_status character varying, + creation_date timestamp without time zone +); + +CREATE SEQUENCE gn_notifications.t_notifications_id_notification_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_notifications.t_notifications_id_notification_seq OWNED BY gn_notifications.t_notifications.id_notification; + +ALTER TABLE ONLY gn_notifications.t_notifications + ADD CONSTRAINT t_notifications_pkey PRIMARY KEY (id_notification); + +ALTER TABLE ONLY gn_notifications.t_notifications + ADD CONSTRAINT t_notifications_id_role_fkey FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role); + diff --git a/data/db_state/gn_notifications/t_notifications_rules.sql b/data/db_state/gn_notifications/t_notifications_rules.sql new file mode 100644 index 0000000000..b0b0386a7f --- /dev/null +++ b/data/db_state/gn_notifications/t_notifications_rules.sql @@ -0,0 +1,36 @@ + +CREATE TABLE gn_notifications.t_notifications_rules ( + id integer NOT NULL, + id_role integer, + code_method character varying NOT NULL, + code_category character varying NOT NULL, + subscribed boolean DEFAULT true NOT NULL +); + +CREATE SEQUENCE gn_notifications.t_notifications_rules_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_notifications.t_notifications_rules_id_seq OWNED BY gn_notifications.t_notifications_rules.id; + +ALTER TABLE ONLY gn_notifications.t_notifications_rules + ADD CONSTRAINT t_notifications_rules_pkey PRIMARY KEY (id); + +ALTER TABLE ONLY gn_notifications.t_notifications_rules + ADD CONSTRAINT un_role_method_category UNIQUE (id_role, code_method, code_category); + +CREATE INDEX un_method_category ON gn_notifications.t_notifications_rules USING btree (code_method, code_category) WHERE (id_role IS NULL); + +ALTER TABLE ONLY gn_notifications.t_notifications_rules + ADD CONSTRAINT t_notifications_rules_code_category_fkey FOREIGN KEY (code_category) REFERENCES gn_notifications.bib_notifications_categories(code); + +ALTER TABLE ONLY gn_notifications.t_notifications_rules + ADD CONSTRAINT t_notifications_rules_code_method_fkey FOREIGN KEY (code_method) REFERENCES gn_notifications.bib_notifications_methods(code); + +ALTER TABLE ONLY gn_notifications.t_notifications_rules + ADD CONSTRAINT t_notifications_rules_id_role_fkey FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role); + diff --git a/data/db_state/gn_permissions/backup_bib_filters_type.sql b/data/db_state/gn_permissions/backup_bib_filters_type.sql new file mode 100644 index 0000000000..02d8f2141a --- /dev/null +++ b/data/db_state/gn_permissions/backup_bib_filters_type.sql @@ -0,0 +1,11 @@ + +CREATE TABLE gn_permissions.backup_bib_filters_type ( + id_filter_type integer NOT NULL, + code_filter_type character varying(50) NOT NULL, + label_filter_type character varying(255) NOT NULL, + description_filter_type text +); + +ALTER TABLE ONLY gn_permissions.backup_bib_filters_type + ADD CONSTRAINT backup_bib_filters_type_pkey PRIMARY KEY (id_filter_type); + diff --git a/data/db_state/gn_permissions/backup_cor_role_action_filter_module_object.sql b/data/db_state/gn_permissions/backup_cor_role_action_filter_module_object.sql new file mode 100644 index 0000000000..d541ba3b51 --- /dev/null +++ b/data/db_state/gn_permissions/backup_cor_role_action_filter_module_object.sql @@ -0,0 +1,28 @@ + +CREATE TABLE gn_permissions.backup_cor_role_action_filter_module_object ( + id_permission integer NOT NULL, + id_role integer NOT NULL, + id_action integer NOT NULL, + id_filter integer NOT NULL, + id_module integer NOT NULL, + id_object integer NOT NULL +); + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_cor_role_action_filter_module_object_pkey PRIMARY KEY (id_permission); + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_fk_cor_r_a_f_m_o_id_action FOREIGN KEY (id_action) REFERENCES gn_permissions.bib_actions(id_action) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_fk_cor_r_a_f_m_o_id_filter FOREIGN KEY (id_filter) REFERENCES gn_permissions.backup_t_filters(id_filter) ON DELETE CASCADE; + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_fk_cor_r_a_f_m_o_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_fk_cor_r_a_f_m_o_id_object FOREIGN KEY (id_object) REFERENCES gn_permissions.t_objects(id_object) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_permissions.backup_cor_role_action_filter_module_object + ADD CONSTRAINT backup_fk_cor_r_a_f_m_o_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_permissions/backup_t_filters.sql b/data/db_state/gn_permissions/backup_t_filters.sql new file mode 100644 index 0000000000..fc04b58bb9 --- /dev/null +++ b/data/db_state/gn_permissions/backup_t_filters.sql @@ -0,0 +1,15 @@ + +CREATE TABLE gn_permissions.backup_t_filters ( + id_filter integer NOT NULL, + label_filter character varying(255) NOT NULL, + value_filter text NOT NULL, + description_filter text, + id_filter_type integer NOT NULL +); + +ALTER TABLE ONLY gn_permissions.backup_t_filters + ADD CONSTRAINT backup_t_filters_pkey PRIMARY KEY (id_filter); + +ALTER TABLE ONLY gn_permissions.backup_t_filters + ADD CONSTRAINT backup_fk_t_filters_id_filter_type FOREIGN KEY (id_filter_type) REFERENCES gn_permissions.backup_bib_filters_type(id_filter_type) ON DELETE CASCADE; + diff --git a/data/db_state/gn_permissions/bib_actions.sql b/data/db_state/gn_permissions/bib_actions.sql new file mode 100644 index 0000000000..2b0bbd95de --- /dev/null +++ b/data/db_state/gn_permissions/bib_actions.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_permissions.bib_actions ( + id_action integer NOT NULL, + code_action character varying(50) NOT NULL, + description_action text +); + +CREATE SEQUENCE gn_permissions.t_actions_id_action_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.t_actions_id_action_seq OWNED BY gn_permissions.bib_actions.id_action; + +ALTER TABLE ONLY gn_permissions.bib_actions + ADD CONSTRAINT pk_t_actions PRIMARY KEY (id_action); + diff --git a/data/db_state/gn_permissions/bib_filters_scope.sql b/data/db_state/gn_permissions/bib_filters_scope.sql new file mode 100644 index 0000000000..3b5bd07fc8 --- /dev/null +++ b/data/db_state/gn_permissions/bib_filters_scope.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_permissions.bib_filters_scope ( + value integer NOT NULL, + label character varying, + description character varying +); + +CREATE SEQUENCE gn_permissions.bib_filters_scope_value_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.bib_filters_scope_value_seq OWNED BY gn_permissions.bib_filters_scope.value; + +ALTER TABLE ONLY gn_permissions.bib_filters_scope + ADD CONSTRAINT bib_filters_scope_pkey PRIMARY KEY (value); + diff --git a/data/db_state/gn_permissions/bib_filters_type.sql b/data/db_state/gn_permissions/bib_filters_type.sql new file mode 100644 index 0000000000..2c09b442c8 --- /dev/null +++ b/data/db_state/gn_permissions/bib_filters_type.sql @@ -0,0 +1,21 @@ + +CREATE TABLE gn_permissions.bib_filters_type ( + id_filter_type integer NOT NULL, + code_filter_type character varying(50) NOT NULL, + label_filter_type character varying(255) NOT NULL, + description_filter_type text +); + +CREATE SEQUENCE gn_permissions.bib_filters_type_id_filter_type_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.bib_filters_type_id_filter_type_seq OWNED BY gn_permissions.bib_filters_type.id_filter_type; + +ALTER TABLE ONLY gn_permissions.bib_filters_type + ADD CONSTRAINT pk_bib_filters_type PRIMARY KEY (id_filter_type); + diff --git a/data/db_state/gn_permissions/cor_object_module.sql b/data/db_state/gn_permissions/cor_object_module.sql new file mode 100644 index 0000000000..4e55668c34 --- /dev/null +++ b/data/db_state/gn_permissions/cor_object_module.sql @@ -0,0 +1,29 @@ + +CREATE TABLE gn_permissions.cor_object_module ( + id_cor_object_module integer NOT NULL, + id_object integer NOT NULL, + id_module integer NOT NULL +); + +CREATE SEQUENCE gn_permissions.cor_object_module_id_cor_object_module_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.cor_object_module_id_cor_object_module_seq OWNED BY gn_permissions.cor_object_module.id_cor_object_module; + +ALTER TABLE ONLY gn_permissions.cor_object_module + ADD CONSTRAINT pk_cor_object_module PRIMARY KEY (id_cor_object_module); + +ALTER TABLE ONLY gn_permissions.cor_object_module + ADD CONSTRAINT unique_cor_object_module UNIQUE (id_object, id_module); + +ALTER TABLE ONLY gn_permissions.cor_object_module + ADD CONSTRAINT fk_cor_object_module_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_permissions.cor_object_module + ADD CONSTRAINT fk_cor_object_module_id_object FOREIGN KEY (id_object) REFERENCES gn_permissions.t_objects(id_object) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_permissions/t_objects.sql b/data/db_state/gn_permissions/t_objects.sql new file mode 100644 index 0000000000..2965eb628e --- /dev/null +++ b/data/db_state/gn_permissions/t_objects.sql @@ -0,0 +1,23 @@ + +CREATE TABLE gn_permissions.t_objects ( + id_object integer NOT NULL, + code_object character varying(50) NOT NULL, + description_object text +); + +CREATE SEQUENCE gn_permissions.t_objects_id_object_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.t_objects_id_object_seq OWNED BY gn_permissions.t_objects.id_object; + +ALTER TABLE ONLY gn_permissions.t_objects + ADD CONSTRAINT pk_t_objects PRIMARY KEY (id_object); + +ALTER TABLE ONLY gn_permissions.t_objects + ADD CONSTRAINT unique_t_objects UNIQUE (code_object); + diff --git a/data/db_state/gn_permissions/t_permissions.sql b/data/db_state/gn_permissions/t_permissions.sql new file mode 100644 index 0000000000..72c1e382fc --- /dev/null +++ b/data/db_state/gn_permissions/t_permissions.sql @@ -0,0 +1,39 @@ + +CREATE TABLE gn_permissions.t_permissions ( + id_permission integer NOT NULL, + id_role integer NOT NULL, + id_action integer NOT NULL, + id_module integer NOT NULL, + id_object integer DEFAULT gn_permissions.get_id_object('ALL'::character varying) NOT NULL, + scope_value integer, + sensitivity_filter boolean DEFAULT false +); + +CREATE SEQUENCE gn_permissions.cor_role_action_filter_module_object_id_permission_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_permissions.cor_role_action_filter_module_object_id_permission_seq OWNED BY gn_permissions.t_permissions.id_permission; + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT pk_cor_r_a_f_m_o PRIMARY KEY (id_permission); + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT fk_cor_r_a_f_m_o_id_action FOREIGN KEY (id_action) REFERENCES gn_permissions.bib_actions(id_action) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT fk_cor_r_a_f_m_o_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT fk_cor_r_a_f_m_o_id_object FOREIGN KEY (id_object) REFERENCES gn_permissions.t_objects(id_object) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT fk_cor_r_a_f_m_o_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_permissions.t_permissions + ADD CONSTRAINT t_permissions_scope_value_fkey FOREIGN KEY (scope_value) REFERENCES gn_permissions.bib_filters_scope(value); + diff --git a/data/db_state/gn_permissions/t_permissions_available.sql b/data/db_state/gn_permissions/t_permissions_available.sql new file mode 100644 index 0000000000..799445e4f8 --- /dev/null +++ b/data/db_state/gn_permissions/t_permissions_available.sql @@ -0,0 +1,22 @@ + +CREATE TABLE gn_permissions.t_permissions_available ( + id_module integer NOT NULL, + id_object integer NOT NULL, + id_action integer NOT NULL, + label character varying, + scope_filter boolean DEFAULT false, + sensitivity_filter boolean DEFAULT false +); + +ALTER TABLE ONLY gn_permissions.t_permissions_available + ADD CONSTRAINT t_permissions_available_pkey PRIMARY KEY (id_module, id_object, id_action); + +ALTER TABLE ONLY gn_permissions.t_permissions_available + ADD CONSTRAINT t_permissions_available_id_action_fkey FOREIGN KEY (id_action) REFERENCES gn_permissions.bib_actions(id_action); + +ALTER TABLE ONLY gn_permissions.t_permissions_available + ADD CONSTRAINT t_permissions_available_id_module_fkey FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module); + +ALTER TABLE ONLY gn_permissions.t_permissions_available + ADD CONSTRAINT t_permissions_available_id_object_fkey FOREIGN KEY (id_object) REFERENCES gn_permissions.t_objects(id_object); + diff --git a/data/db_state/gn_profiles/cor_taxons_parameters.sql b/data/db_state/gn_profiles/cor_taxons_parameters.sql new file mode 100644 index 0000000000..66a009244c --- /dev/null +++ b/data/db_state/gn_profiles/cor_taxons_parameters.sql @@ -0,0 +1,14 @@ + +CREATE TABLE gn_profiles.cor_taxons_parameters ( + cd_nom integer NOT NULL, + spatial_precision integer, + temporal_precision_days integer, + active_life_stage boolean DEFAULT false +); + +ALTER TABLE ONLY gn_profiles.cor_taxons_parameters + ADD CONSTRAINT pk_taxons_parameters PRIMARY KEY (cd_nom); + +ALTER TABLE ONLY gn_profiles.cor_taxons_parameters + ADD CONSTRAINT fk_cor_taxons_parameters_cd_nom FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_profiles/t_parameters.sql b/data/db_state/gn_profiles/t_parameters.sql new file mode 100644 index 0000000000..eb971f62aa --- /dev/null +++ b/data/db_state/gn_profiles/t_parameters.sql @@ -0,0 +1,23 @@ + +CREATE TABLE gn_profiles.t_parameters ( + id_parameter integer NOT NULL, + name character varying(100) NOT NULL, + "desc" text, + value text NOT NULL +); + +COMMENT ON TABLE gn_profiles.t_parameters IS 'Define global parameters for profiles calculation'; + +CREATE SEQUENCE gn_profiles.t_parameters_id_parameter_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_profiles.t_parameters_id_parameter_seq OWNED BY gn_profiles.t_parameters.id_parameter; + +ALTER TABLE ONLY gn_profiles.t_parameters + ADD CONSTRAINT pk_parameters PRIMARY KEY (id_parameter); + diff --git a/data/db_state/gn_sensitivity/cor_sensitivity_area.sql b/data/db_state/gn_sensitivity/cor_sensitivity_area.sql new file mode 100644 index 0000000000..131d2248c0 --- /dev/null +++ b/data/db_state/gn_sensitivity/cor_sensitivity_area.sql @@ -0,0 +1,16 @@ + +CREATE TABLE gn_sensitivity.cor_sensitivity_area ( + id_sensitivity integer, + id_area integer +); + +COMMENT ON TABLE gn_sensitivity.cor_sensitivity_area IS 'Specifies where a sensitivity rule applies'; + +CREATE INDEX cor_sensitivity_area_id_sensitivity_idx ON gn_sensitivity.cor_sensitivity_area USING btree (id_sensitivity); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_area + ADD CONSTRAINT fk_cor_sensitivity_area_id_area_fkey FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_area + ADD CONSTRAINT fk_cor_sensitivity_area_id_sensitivity_fkey FOREIGN KEY (id_sensitivity) REFERENCES gn_sensitivity.t_sensitivity_rules(id_sensitivity) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_sensitivity/cor_sensitivity_area_type.sql b/data/db_state/gn_sensitivity/cor_sensitivity_area_type.sql new file mode 100644 index 0000000000..36ce433c15 --- /dev/null +++ b/data/db_state/gn_sensitivity/cor_sensitivity_area_type.sql @@ -0,0 +1,12 @@ + +CREATE TABLE gn_sensitivity.cor_sensitivity_area_type ( + id_nomenclature_sensitivity integer, + id_area_type integer +); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_area_type + ADD CONSTRAINT cor_sensitivity_area_type_id_area_type_fkey FOREIGN KEY (id_area_type) REFERENCES ref_geo.bib_areas_types(id_type); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_area_type + ADD CONSTRAINT cor_sensitivity_area_type_id_nomenclature_sensitivity_fkey FOREIGN KEY (id_nomenclature_sensitivity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/gn_sensitivity/cor_sensitivity_criteria.sql b/data/db_state/gn_sensitivity/cor_sensitivity_criteria.sql new file mode 100644 index 0000000000..3c2681c6e3 --- /dev/null +++ b/data/db_state/gn_sensitivity/cor_sensitivity_criteria.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_sensitivity.cor_sensitivity_criteria ( + id_sensitivity integer, + id_criteria integer, + id_type_nomenclature integer +); + +COMMENT ON TABLE gn_sensitivity.cor_sensitivity_criteria IS 'Specifies extra criteria for a sensitivity rule'; + +CREATE INDEX cor_sensitivity_criteria_id_sensitivity_idx ON gn_sensitivity.cor_sensitivity_criteria USING btree (id_sensitivity); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_criteria + ADD CONSTRAINT criteria_id_criteria_fkey FOREIGN KEY (id_criteria) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_criteria + ADD CONSTRAINT criteria_id_sensitivity_fkey FOREIGN KEY (id_sensitivity) REFERENCES gn_sensitivity.t_sensitivity_rules(id_sensitivity) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_sensitivity.cor_sensitivity_criteria + ADD CONSTRAINT criteria_id_type_nomenclature_fkey FOREIGN KEY (id_type_nomenclature) REFERENCES ref_nomenclatures.bib_nomenclatures_types(id_type); + diff --git a/data/db_state/gn_sensitivity/t_sensitivity_rules.sql b/data/db_state/gn_sensitivity/t_sensitivity_rules.sql new file mode 100644 index 0000000000..5274dfa399 --- /dev/null +++ b/data/db_state/gn_sensitivity/t_sensitivity_rules.sql @@ -0,0 +1,44 @@ + +CREATE TABLE gn_sensitivity.t_sensitivity_rules ( + id_sensitivity integer NOT NULL, + cd_nom integer NOT NULL, + nom_cite character varying(1000), + id_nomenclature_sensitivity integer NOT NULL, + sensitivity_duration integer NOT NULL, + sensitivity_territory character varying(1000), + id_territory character varying(50), + date_min date, + date_max date, + source character varying(250), + active boolean DEFAULT true, + comments character varying(500), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone +); + +COMMENT ON TABLE gn_sensitivity.t_sensitivity_rules IS 'List of sensitivity rules per taxon. Compilation of national and regional list. If you whant to disable one ou several rules you can set false to enable.'; + +CREATE SEQUENCE gn_sensitivity.t_sensitivity_rules_id_sensitivity_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_sensitivity.t_sensitivity_rules_id_sensitivity_seq OWNED BY gn_sensitivity.t_sensitivity_rules.id_sensitivity; + +ALTER TABLE gn_sensitivity.t_sensitivity_rules + ADD CONSTRAINT check_t_sensitivity_rules_niv_precis CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_sensitivity, 'SENSIBILITE'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_sensitivity.t_sensitivity_rules + ADD CONSTRAINT t_sensitivity_rules_pkey PRIMARY KEY (id_sensitivity); + +CREATE TRIGGER tri_meta_dates_change_t_sensitivity_rules BEFORE INSERT OR UPDATE ON gn_sensitivity.t_sensitivity_rules FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY gn_sensitivity.t_sensitivity_rules + ADD CONSTRAINT fk_t_sensitivity_rules_cd_nom FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_sensitivity.t_sensitivity_rules + ADD CONSTRAINT fk_t_sensitivity_rules_id_nomenclature_sensitivity FOREIGN KEY (id_nomenclature_sensitivity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_synthese/bib_reports_types.sql b/data/db_state/gn_synthese/bib_reports_types.sql new file mode 100644 index 0000000000..e3b365e142 --- /dev/null +++ b/data/db_state/gn_synthese/bib_reports_types.sql @@ -0,0 +1,19 @@ + +CREATE TABLE gn_synthese.bib_reports_types ( + id_type integer NOT NULL, + type character varying NOT NULL +); + +CREATE SEQUENCE gn_synthese.bib_reports_types_id_type_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_synthese.bib_reports_types_id_type_seq OWNED BY gn_synthese.bib_reports_types.id_type; + +ALTER TABLE ONLY gn_synthese.bib_reports_types + ADD CONSTRAINT bib_reports_types_pkey PRIMARY KEY (id_type); + diff --git a/data/db_state/gn_synthese/cor_area_synthese.sql b/data/db_state/gn_synthese/cor_area_synthese.sql new file mode 100644 index 0000000000..8c949e353b --- /dev/null +++ b/data/db_state/gn_synthese/cor_area_synthese.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_synthese.cor_area_synthese ( + id_synthese integer NOT NULL, + id_area integer NOT NULL +); + +ALTER TABLE ONLY gn_synthese.cor_area_synthese + ADD CONSTRAINT pk_cor_area_synthese PRIMARY KEY (id_synthese, id_area); + +CREATE INDEX i_cor_area_synthese_id_area ON gn_synthese.cor_area_synthese USING btree (id_area); + +ALTER TABLE ONLY gn_synthese.cor_area_synthese + ADD CONSTRAINT fk_cor_area_synthese_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_synthese.cor_area_synthese + ADD CONSTRAINT fk_cor_area_synthese_id_synthese FOREIGN KEY (id_synthese) REFERENCES gn_synthese.synthese(id_synthese) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_synthese/cor_observer_synthese.sql b/data/db_state/gn_synthese/cor_observer_synthese.sql new file mode 100644 index 0000000000..1b66da3ee8 --- /dev/null +++ b/data/db_state/gn_synthese/cor_observer_synthese.sql @@ -0,0 +1,17 @@ + +CREATE TABLE gn_synthese.cor_observer_synthese ( + id_synthese integer NOT NULL, + id_role integer NOT NULL +); + +ALTER TABLE ONLY gn_synthese.cor_observer_synthese + ADD CONSTRAINT pk_cor_observer_synthese PRIMARY KEY (id_synthese, id_role); + +CREATE TRIGGER trg_maj_synthese_observers_txt AFTER INSERT OR DELETE OR UPDATE ON gn_synthese.cor_observer_synthese FOR EACH ROW EXECUTE FUNCTION gn_synthese.fct_tri_maj_observers_txt(); + +ALTER TABLE ONLY gn_synthese.cor_observer_synthese + ADD CONSTRAINT fk_gn_synthese_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.cor_observer_synthese + ADD CONSTRAINT fk_gn_synthese_id_synthese FOREIGN KEY (id_synthese) REFERENCES gn_synthese.synthese(id_synthese) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_synthese/defaults_nomenclatures_value.sql b/data/db_state/gn_synthese/defaults_nomenclatures_value.sql new file mode 100644 index 0000000000..849fa012e3 --- /dev/null +++ b/data/db_state/gn_synthese/defaults_nomenclatures_value.sql @@ -0,0 +1,27 @@ + +CREATE TABLE gn_synthese.defaults_nomenclatures_value ( + mnemonique_type character varying(50) NOT NULL, + id_organism integer DEFAULT 0 NOT NULL, + regne character varying(20) DEFAULT '0'::character varying NOT NULL, + group2_inpn character varying(255) DEFAULT '0'::character varying NOT NULL, + id_nomenclature integer NOT NULL +); + +ALTER TABLE gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT check_gn_synthese_defaults_nomenclatures_value_is_nomenclature_ CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature, mnemonique_type)) NOT VALID; + +ALTER TABLE gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT check_gn_synthese_defaults_nomenclatures_value_isgroup2inpn CHECK ((taxonomie.check_is_group2inpn((group2_inpn)::text) OR ((group2_inpn)::text = '0'::text))) NOT VALID; + +ALTER TABLE gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT check_gn_synthese_defaults_nomenclatures_value_isregne CHECK ((taxonomie.check_is_regne((regne)::text) OR ((regne)::text = '0'::text))) NOT VALID; + +ALTER TABLE ONLY gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT pk_gn_synthese_defaults_nomenclatures_value PRIMARY KEY (mnemonique_type, id_organism, regne, group2_inpn); + +ALTER TABLE ONLY gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT fk_gn_synthese_defaults_nomenclatures_value_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.defaults_nomenclatures_value + ADD CONSTRAINT fk_gn_synthese_defaults_nomenclatures_value_mnemonique_type FOREIGN KEY (mnemonique_type) REFERENCES ref_nomenclatures.bib_nomenclatures_types(mnemonique) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_synthese/synthese.sql b/data/db_state/gn_synthese/synthese.sql new file mode 100644 index 0000000000..e76f0a1e8f --- /dev/null +++ b/data/db_state/gn_synthese/synthese.sql @@ -0,0 +1,275 @@ + +CREATE TABLE gn_synthese.synthese ( + id_synthese integer NOT NULL, + unique_id_sinp uuid, + unique_id_sinp_grp uuid, + id_source integer NOT NULL, + id_module integer, + entity_source_pk_value character varying, + id_dataset integer, + id_nomenclature_geo_object_nature integer DEFAULT gn_synthese.get_default_nomenclature_value('NAT_OBJ_GEO'::character varying), + id_nomenclature_grp_typ integer DEFAULT gn_synthese.get_default_nomenclature_value('TYP_GRP'::character varying), + grp_method character varying(255), + id_nomenclature_obs_technique integer DEFAULT gn_synthese.get_default_nomenclature_value('METH_OBS'::character varying), + id_nomenclature_bio_status integer DEFAULT gn_synthese.get_default_nomenclature_value('STATUT_BIO'::character varying), + id_nomenclature_bio_condition integer DEFAULT gn_synthese.get_default_nomenclature_value('ETA_BIO'::character varying), + id_nomenclature_naturalness integer DEFAULT gn_synthese.get_default_nomenclature_value('NATURALITE'::character varying), + id_nomenclature_exist_proof integer DEFAULT gn_synthese.get_default_nomenclature_value('PREUVE_EXIST'::character varying), + id_nomenclature_valid_status integer DEFAULT gn_synthese.get_default_nomenclature_value('STATUT_VALID'::character varying), + id_nomenclature_diffusion_level integer, + id_nomenclature_life_stage integer DEFAULT gn_synthese.get_default_nomenclature_value('STADE_VIE'::character varying), + id_nomenclature_sex integer DEFAULT gn_synthese.get_default_nomenclature_value('SEXE'::character varying), + id_nomenclature_obj_count integer DEFAULT gn_synthese.get_default_nomenclature_value('OBJ_DENBR'::character varying), + id_nomenclature_type_count integer DEFAULT gn_synthese.get_default_nomenclature_value('TYP_DENBR'::character varying), + id_nomenclature_sensitivity integer, + id_nomenclature_observation_status integer DEFAULT gn_synthese.get_default_nomenclature_value('STATUT_OBS'::character varying), + id_nomenclature_blurring integer DEFAULT gn_synthese.get_default_nomenclature_value('DEE_FLOU'::character varying), + id_nomenclature_source_status integer DEFAULT gn_synthese.get_default_nomenclature_value('STATUT_SOURCE'::character varying), + id_nomenclature_info_geo_type integer DEFAULT gn_synthese.get_default_nomenclature_value('TYP_INF_GEO'::character varying), + id_nomenclature_behaviour integer DEFAULT gn_synthese.get_default_nomenclature_value('OCC_COMPORTEMENT'::character varying), + id_nomenclature_biogeo_status integer DEFAULT gn_synthese.get_default_nomenclature_value('STAT_BIOGEO'::character varying), + reference_biblio character varying(5000), + count_min integer, + count_max integer, + cd_nom integer, + cd_hab integer, + nom_cite character varying(1000) NOT NULL, + meta_v_taxref character varying(50) DEFAULT gn_commons.get_default_parameter('taxref_version'::text, NULL::integer), + sample_number_proof text, + digital_proof text, + non_digital_proof text, + altitude_min integer, + altitude_max integer, + depth_min integer, + depth_max integer, + place_name character varying(500), + the_geom_4326 public.geometry(Geometry,4326), + the_geom_point public.geometry(Point,4326), + the_geom_local public.geometry(Geometry,2154), + "precision" integer, + id_area_attachment integer, + date_min timestamp without time zone NOT NULL, + date_max timestamp without time zone NOT NULL, + validator character varying(1000), + validation_comment text, + observers character varying(1000), + determiner character varying(1000), + id_digitiser integer, + id_nomenclature_determination_method integer DEFAULT gn_synthese.get_default_nomenclature_value('METH_DETERMIN'::character varying), + comment_context text, + comment_description text, + additional_data jsonb, + meta_validation_date timestamp without time zone, + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + last_action character(1), + id_import integer, + CONSTRAINT check_synthese_altitude_max CHECK ((altitude_max >= altitude_min)), + CONSTRAINT check_synthese_count_max CHECK ((count_max >= count_min)), + CONSTRAINT check_synthese_date_max CHECK ((date_max >= date_min)), + CONSTRAINT check_synthese_depth_max CHECK ((depth_max >= depth_min)), + CONSTRAINT enforce_dims_the_geom_4326 CHECK ((public.st_ndims(the_geom_4326) = 2)), + CONSTRAINT enforce_dims_the_geom_local CHECK ((public.st_ndims(the_geom_local) = 2)), + CONSTRAINT enforce_dims_the_geom_point CHECK ((public.st_ndims(the_geom_point) = 2)), + CONSTRAINT enforce_geotype_the_geom_point CHECK (((public.geometrytype(the_geom_point) = 'POINT'::text) OR (the_geom_point IS NULL))), + CONSTRAINT enforce_srid_the_geom_4326 CHECK ((public.st_srid(the_geom_4326) = 4326)), + CONSTRAINT enforce_srid_the_geom_local CHECK ((public.st_srid(the_geom_local) = 2154)), + CONSTRAINT enforce_srid_the_geom_point CHECK ((public.st_srid(the_geom_point) = 4326)) +); + +COMMENT ON TABLE gn_synthese.synthese IS 'Table de synthèse destinée à recevoir les données de tous les protocoles. Pour consultation uniquement'; + +COMMENT ON COLUMN gn_synthese.synthese.id_source IS 'Permet d''identifier la localisation de l''enregistrement correspondant dans les schémas et tables de la base'; + +COMMENT ON COLUMN gn_synthese.synthese.id_module IS 'Permet d''identifier le module qui a permis la création de l''enregistrement. Ce champ est en lien avec utilisateurs.t_applications et permet de gérer le CRUVED grace à la table utilisateurs.cor_app_privileges'; + +COMMENT ON COLUMN gn_synthese.synthese.id_nomenclature_obs_technique IS 'Correspondance champs standard occtax = obsTechnique. En raison d''un changement de nom, le code nomenclature associé reste ''METH_OBS'' '; + +COMMENT ON COLUMN gn_synthese.synthese.id_area_attachment IS 'Id area du rattachement géographique - cas des observations sans géométrie précise'; + +COMMENT ON COLUMN gn_synthese.synthese.comment_context IS 'Commentaire du releve (ou regroupement)'; + +COMMENT ON COLUMN gn_synthese.synthese.comment_description IS 'Commentaire de l''occurrence'; + +CREATE SEQUENCE gn_synthese.synthese_id_synthese_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_synthese.synthese_id_synthese_seq OWNED BY gn_synthese.synthese.id_synthese; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_bio_condition CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_condition, 'ETA_BIO'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_bio_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_status, 'STATUT_BIO'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_biogeo_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_biogeo_status, 'STAT_BIOGEO'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_blurring CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_blurring, 'DEE_FLOU'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_diffusion_level CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_diffusion_level, 'NIV_PRECIS'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_exist_proof CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_exist_proof, 'PREUVE_EXIST'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_geo_object_nature CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_geo_object_nature, 'NAT_OBJ_GEO'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_info_geo_type_id_area_attachment CHECK ((NOT (((ref_nomenclatures.get_cd_nomenclature(id_nomenclature_info_geo_type))::text = '2'::text) AND (id_area_attachment IS NULL)))) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_life_stage CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_life_stage, 'STADE_VIE'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_naturalness CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_naturalness, 'NATURALITE'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_obj_count CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_obj_count, 'OBJ_DENBR'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_obs_meth CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_obs_technique, 'METH_OBS'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_observation_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_observation_status, 'STATUT_OBS'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_sensitivity CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_sensitivity, 'SENSIBILITE'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_sex CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_sex, 'SEXE'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_source_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_source_status, 'STATUT_SOURCE'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_typ_grp CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_grp_typ, 'TYP_GRP'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_type_count CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_type_count, 'TYP_DENBR'::character varying)) NOT VALID; + +ALTER TABLE gn_synthese.synthese + ADD CONSTRAINT check_synthese_valid_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_valid_status, 'STATUT_VALID'::character varying)) NOT VALID; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT pk_synthese PRIMARY KEY (id_synthese); + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT unique_id_sinp_unique UNIQUE (unique_id_sinp); + +CREATE INDEX i_synthese_altitude_max ON gn_synthese.synthese USING btree (altitude_max); + +CREATE INDEX i_synthese_altitude_min ON gn_synthese.synthese USING btree (altitude_min); + +CREATE INDEX i_synthese_cd_nom ON gn_synthese.synthese USING btree (cd_nom); + +CREATE INDEX i_synthese_date_max ON gn_synthese.synthese USING btree (date_max DESC); + +CREATE INDEX i_synthese_date_min ON gn_synthese.synthese USING btree (date_min DESC); + +CREATE INDEX i_synthese_id_dataset ON gn_synthese.synthese USING btree (id_dataset); + +CREATE INDEX i_synthese_t_sources ON gn_synthese.synthese USING btree (id_source); + +CREATE INDEX i_synthese_the_geom_4326 ON gn_synthese.synthese USING gist (the_geom_4326); + +CREATE INDEX i_synthese_the_geom_local ON gn_synthese.synthese USING gist (the_geom_local); + +CREATE INDEX i_synthese_the_geom_point ON gn_synthese.synthese USING gist (the_geom_point); + +CREATE TRIGGER tri_insert_calculate_sensitivity AFTER INSERT ON gn_synthese.synthese REFERENCING NEW TABLE AS new FOR EACH STATEMENT EXECUTE FUNCTION gn_synthese.fct_tri_calculate_sensitivity_on_each_statement(); + +CREATE TRIGGER tri_insert_cor_area_synthese AFTER INSERT ON gn_synthese.synthese REFERENCING NEW TABLE AS new FOR EACH STATEMENT EXECUTE FUNCTION gn_synthese.fct_trig_insert_in_cor_area_synthese_on_each_statement(); + +CREATE TRIGGER tri_log_delete_synthese AFTER DELETE ON gn_synthese.synthese REFERENCING OLD TABLE AS old_table FOR EACH STATEMENT EXECUTE FUNCTION gn_synthese.fct_tri_log_delete_on_synthese(); + +CREATE TRIGGER tri_meta_dates_change_synthese BEFORE INSERT OR UPDATE ON gn_synthese.synthese FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +CREATE TRIGGER tri_update_calculate_sensitivity BEFORE UPDATE OF date_min, date_max, cd_nom, the_geom_local, id_nomenclature_bio_status, id_nomenclature_behaviour ON gn_synthese.synthese FOR EACH ROW EXECUTE FUNCTION gn_synthese.fct_tri_update_sensitivity_on_each_row(); + +CREATE TRIGGER tri_update_cor_area_synthese AFTER UPDATE OF the_geom_local, the_geom_4326 ON gn_synthese.synthese FOR EACH ROW EXECUTE FUNCTION gn_synthese.fct_trig_update_in_cor_area_synthese(); + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_cd_hab FOREIGN KEY (cd_hab) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_cd_nom FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_area_attachment FOREIGN KEY (id_area_attachment) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_dataset FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_bio_condition FOREIGN KEY (id_nomenclature_bio_condition) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_bio_status FOREIGN KEY (id_nomenclature_bio_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_biogeo_status FOREIGN KEY (id_nomenclature_biogeo_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_blurring FOREIGN KEY (id_nomenclature_blurring) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_determination_method FOREIGN KEY (id_nomenclature_determination_method) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_diffusion_level FOREIGN KEY (id_nomenclature_diffusion_level) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_exist_proof FOREIGN KEY (id_nomenclature_exist_proof) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_geo_object_nature FOREIGN KEY (id_nomenclature_geo_object_nature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_id_nomenclature_grp_typ FOREIGN KEY (id_nomenclature_grp_typ) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_info_geo_type FOREIGN KEY (id_nomenclature_info_geo_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_life_stage FOREIGN KEY (id_nomenclature_life_stage) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_obj_count FOREIGN KEY (id_nomenclature_obj_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_obs_technique FOREIGN KEY (id_nomenclature_obs_technique) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_observation_status FOREIGN KEY (id_nomenclature_observation_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_sensitivity FOREIGN KEY (id_nomenclature_sensitivity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_sex FOREIGN KEY (id_nomenclature_sex) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_source_status FOREIGN KEY (id_nomenclature_source_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_type_count FOREIGN KEY (id_nomenclature_type_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_nomenclature_valid_status FOREIGN KEY (id_nomenclature_valid_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY gn_synthese.synthese + ADD CONSTRAINT fk_synthese_id_source FOREIGN KEY (id_source) REFERENCES gn_synthese.t_sources(id_source) ON UPDATE CASCADE; + diff --git a/data/db_state/gn_synthese/t_log_synthese.sql b/data/db_state/gn_synthese/t_log_synthese.sql new file mode 100644 index 0000000000..ab5eb0426c --- /dev/null +++ b/data/db_state/gn_synthese/t_log_synthese.sql @@ -0,0 +1,20 @@ + +CREATE TABLE gn_synthese.t_log_synthese ( + id_synthese integer NOT NULL, + last_action character(1) NOT NULL, + meta_last_action_date timestamp without time zone DEFAULT now() +); + +CREATE SEQUENCE gn_synthese.t_log_synthese_id_synthese_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_synthese.t_log_synthese_id_synthese_seq OWNED BY gn_synthese.t_log_synthese.id_synthese; + +ALTER TABLE ONLY gn_synthese.t_log_synthese + ADD CONSTRAINT t_log_synthese_pkey PRIMARY KEY (id_synthese); + diff --git a/data/db_state/gn_synthese/t_reports.sql b/data/db_state/gn_synthese/t_reports.sql new file mode 100644 index 0000000000..9cd335e101 --- /dev/null +++ b/data/db_state/gn_synthese/t_reports.sql @@ -0,0 +1,33 @@ + +CREATE TABLE gn_synthese.t_reports ( + id_report integer NOT NULL, + id_synthese integer NOT NULL, + id_role integer NOT NULL, + id_type integer, + content character varying NOT NULL, + creation_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP, + deleted boolean DEFAULT false +); + +CREATE SEQUENCE gn_synthese.t_reports_id_report_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_synthese.t_reports_id_report_seq OWNED BY gn_synthese.t_reports.id_report; + +ALTER TABLE ONLY gn_synthese.t_reports + ADD CONSTRAINT t_reports_pkey PRIMARY KEY (id_report); + +ALTER TABLE ONLY gn_synthese.t_reports + ADD CONSTRAINT fk_report_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_synthese.t_reports + ADD CONSTRAINT fk_report_synthese FOREIGN KEY (id_synthese) REFERENCES gn_synthese.synthese(id_synthese) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY gn_synthese.t_reports + ADD CONSTRAINT fk_report_type FOREIGN KEY (id_type) REFERENCES gn_synthese.bib_reports_types(id_type) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/gn_synthese/t_sources.sql b/data/db_state/gn_synthese/t_sources.sql new file mode 100644 index 0000000000..fa03faa4fa --- /dev/null +++ b/data/db_state/gn_synthese/t_sources.sql @@ -0,0 +1,35 @@ + +CREATE TABLE gn_synthese.t_sources ( + id_source integer NOT NULL, + name_source character varying(255) NOT NULL, + desc_source text, + entity_source_pk_field character varying(255), + url_source character varying(255), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now(), + id_module integer +); + +CREATE SEQUENCE gn_synthese.t_sources_id_source_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE gn_synthese.t_sources_id_source_seq OWNED BY gn_synthese.t_sources.id_source; + +ALTER TABLE ONLY gn_synthese.t_sources + ADD CONSTRAINT pk_t_sources PRIMARY KEY (id_source); + +ALTER TABLE ONLY gn_synthese.t_sources + ADD CONSTRAINT unique_name_source UNIQUE (name_source); + +CREATE UNIQUE INDEX i_unique_t_sources_name_source ON gn_synthese.t_sources USING btree (name_source); + +CREATE TRIGGER tri_meta_dates_t_sources BEFORE INSERT OR UPDATE ON gn_synthese.t_sources FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY gn_synthese.t_sources + ADD CONSTRAINT t_sources_id_module_fkey FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module); + diff --git a/data/db_state/pr_occhab/cor_station_observer.sql b/data/db_state/pr_occhab/cor_station_observer.sql new file mode 100644 index 0000000000..6118a7ef2b --- /dev/null +++ b/data/db_state/pr_occhab/cor_station_observer.sql @@ -0,0 +1,29 @@ + +CREATE TABLE pr_occhab.cor_station_observer ( + id_cor_station_observer integer NOT NULL, + id_station integer NOT NULL, + id_role integer NOT NULL +); + +CREATE SEQUENCE pr_occhab.cor_station_observer_id_cor_station_observer_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occhab.cor_station_observer_id_cor_station_observer_seq OWNED BY pr_occhab.cor_station_observer.id_cor_station_observer; + +ALTER TABLE ONLY pr_occhab.cor_station_observer + ADD CONSTRAINT pk_cor_station_observer PRIMARY KEY (id_cor_station_observer); + +ALTER TABLE ONLY pr_occhab.cor_station_observer + ADD CONSTRAINT unique_cor_station_observer UNIQUE (id_station, id_role); + +ALTER TABLE ONLY pr_occhab.cor_station_observer + ADD CONSTRAINT fk_cor_station_observer_id_station FOREIGN KEY (id_station) REFERENCES pr_occhab.t_stations(id_station) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY pr_occhab.cor_station_observer + ADD CONSTRAINT fk_cor_station_observer_t_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occhab/defaults_nomenclatures_value.sql b/data/db_state/pr_occhab/defaults_nomenclatures_value.sql new file mode 100644 index 0000000000..6300f46a4b --- /dev/null +++ b/data/db_state/pr_occhab/defaults_nomenclatures_value.sql @@ -0,0 +1,19 @@ + +CREATE TABLE pr_occhab.defaults_nomenclatures_value ( + mnemonique_type character varying(255) NOT NULL, + id_organism integer DEFAULT 0 NOT NULL, + id_nomenclature integer NOT NULL +); + +ALTER TABLE ONLY pr_occhab.defaults_nomenclatures_value + ADD CONSTRAINT pk_pr_occhab_defaults_nomenclatures_value PRIMARY KEY (mnemonique_type, id_organism); + +ALTER TABLE ONLY pr_occhab.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occhab_defaults_nomenclatures_value_id_nomenclature FOREIGN KEY (id_nomenclature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occhab_defaults_nomenclatures_value_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occhab_defaults_nomenclatures_value_mnemonique_type FOREIGN KEY (mnemonique_type) REFERENCES ref_nomenclatures.bib_nomenclatures_types(mnemonique) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occhab/t_habitats.sql b/data/db_state/pr_occhab/t_habitats.sql new file mode 100644 index 0000000000..d078c44656 --- /dev/null +++ b/data/db_state/pr_occhab/t_habitats.sql @@ -0,0 +1,77 @@ + +CREATE TABLE pr_occhab.t_habitats ( + id_habitat integer NOT NULL, + id_station integer NOT NULL, + unique_id_sinp_hab uuid DEFAULT public.uuid_generate_v4(), + cd_hab integer NOT NULL, + nom_cite character varying(500) NOT NULL, + id_nomenclature_determination_type integer, + determiner character varying(500), + id_nomenclature_collection_technique integer DEFAULT pr_occhab.get_default_nomenclature_value('TECHNIQUE_COLLECT_HAB'::character varying) NOT NULL, + recovery_percentage numeric, + id_nomenclature_abundance integer, + technical_precision character varying(500), + unique_id_sinp_grp_occtax uuid, + unique_id_sinp_grp_phyto uuid, + id_nomenclature_sensitvity integer, + id_nomenclature_community_interest integer, + id_import integer +); + +CREATE SEQUENCE pr_occhab.t_habitats_id_habitat_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occhab.t_habitats_id_habitat_seq OWNED BY pr_occhab.t_habitats.id_habitat; + +ALTER TABLE pr_occhab.t_habitats + ADD CONSTRAINT check_t_habitats_abondance CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_abundance, 'ABONDANCE_HAB'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_habitats + ADD CONSTRAINT check_t_habitats_collection_techn CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_collection_technique, 'TECHNIQUE_COLLECT_HAB'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_habitats + ADD CONSTRAINT check_t_habitats_community_interest CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_community_interest, 'HAB_INTERET_COM'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_habitats + ADD CONSTRAINT check_t_habitats_determini_meth CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_determination_type, 'DETERMINATION_TYP_HAB'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_habitats + ADD CONSTRAINT check_t_habitats_sensitivity CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_sensitvity, 'SENSIBILITE'::character varying)) NOT VALID; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT pk_t_habitats PRIMARY KEY (id_habitat); + +CREATE INDEX i_t_habitats_cd_hab ON pr_occhab.t_habitats USING btree (cd_hab); + +CREATE INDEX i_t_habitats_id_station ON pr_occhab.t_habitats USING btree (id_station); + +CREATE TRIGGER tri_log_changes_delete_t_habitats_occhab AFTER DELETE ON pr_occhab.t_habitats FOR EACH ROW WHEN ((old.id_import IS NULL)) EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_log_changes_insert_t_habitats_occhab AFTER INSERT OR UPDATE ON pr_occhab.t_habitats FOR EACH ROW WHEN ((new.id_import IS NULL)) EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_nomenclature_abundance FOREIGN KEY (id_nomenclature_abundance) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_nomenclature_collection_technique FOREIGN KEY (id_nomenclature_collection_technique) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_nomenclature_community_interest FOREIGN KEY (id_nomenclature_community_interest) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_nomenclature_determination_type FOREIGN KEY (id_nomenclature_determination_type) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_nomenclature_sensitvity FOREIGN KEY (id_nomenclature_sensitvity) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT fk_t_habitats_id_station FOREIGN KEY (id_station) REFERENCES pr_occhab.t_stations(id_station) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_habitats + ADD CONSTRAINT t_habitats_id_import_fkey FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occhab/t_stations.sql b/data/db_state/pr_occhab/t_stations.sql new file mode 100644 index 0000000000..072dba57a1 --- /dev/null +++ b/data/db_state/pr_occhab/t_stations.sql @@ -0,0 +1,94 @@ + +CREATE TABLE pr_occhab.t_stations ( + id_station integer NOT NULL, + unique_id_sinp_station uuid DEFAULT public.uuid_generate_v4(), + id_dataset integer NOT NULL, + date_min timestamp without time zone DEFAULT now() NOT NULL, + date_max timestamp without time zone DEFAULT now() NOT NULL, + observers_txt character varying(500), + station_name character varying(1000), + id_nomenclature_exposure integer, + altitude_min integer, + altitude_max integer, + depth_min integer, + depth_max integer, + area bigint, + id_nomenclature_area_surface_calculation integer, + comment text, + geom_local public.geometry(Geometry,2154), + geom_4326 public.geometry(Geometry,4326) NOT NULL, + "precision" integer, + id_digitiser integer, + numerization_scale character varying(15), + id_nomenclature_geographic_object integer DEFAULT pr_occhab.get_default_nomenclature_value('NAT_OBJ_GEO'::character varying) NOT NULL, + id_station_source character varying, + id_import integer, + id_nomenclature_type_mosaique_habitat integer, + CONSTRAINT enforce_dims_geom_4326 CHECK ((public.st_ndims(geom_4326) = 2)), + CONSTRAINT enforce_dims_geom_local CHECK ((public.st_ndims(geom_local) = 2)), + CONSTRAINT enforce_srid_geom_4326 CHECK ((public.st_srid(geom_4326) = 4326)), + CONSTRAINT enforce_srid_geom_local CHECK ((public.st_srid(geom_local) = 2154)), + CONSTRAINT t_stations_altitude_max CHECK ((altitude_max >= altitude_min)), + CONSTRAINT t_stations_date_max CHECK ((date_min <= date_max)) +); + +COMMENT ON COLUMN pr_occhab.t_stations.id_nomenclature_exposure IS 'Correspondance nomenclature INPN = exposition d''un terrain, REF_NOMENCLATURES = EXPOSITION'; + +COMMENT ON COLUMN pr_occhab.t_stations.id_nomenclature_area_surface_calculation IS 'Correspondance nomenclature INPN = exposition d''un terrain, REF_NOMENCLATURES = EXPOSITION'; + +CREATE SEQUENCE pr_occhab.t_stations_id_station_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occhab.t_stations_id_station_seq OWNED BY pr_occhab.t_stations.id_station; + +ALTER TABLE pr_occhab.t_stations + ADD CONSTRAINT check_t_stations_area_method CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_area_surface_calculation, 'METHOD_CALCUL_SURFACE'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_stations + ADD CONSTRAINT check_t_stations_exposure CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_exposure, 'EXPOSITION'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_stations + ADD CONSTRAINT check_t_stations_geographic_object CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_geographic_object, 'NAT_OBJ_GEO'::character varying)) NOT VALID; + +ALTER TABLE pr_occhab.t_stations + ADD CONSTRAINT check_t_stations_type_mosaique_habitat CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_type_mosaique_habitat, 'MOSAIQUE_HAB'::character varying)) NOT VALID; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT pk_t_stations PRIMARY KEY (id_station); + +CREATE INDEX i_t_stations_id_dataset ON pr_occhab.t_stations USING btree (id_dataset); + +CREATE INDEX i_t_stations_occhab_geom_4326 ON pr_occhab.t_stations USING gist (geom_4326); + +CREATE TRIGGER tri_calculate_geom_local BEFORE INSERT OR UPDATE ON pr_occhab.t_stations FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_geom_local('geom_4326', 'geom_local'); + +CREATE TRIGGER tri_log_changes_delete_t_stations_occhab AFTER DELETE ON pr_occhab.t_stations FOR EACH ROW WHEN ((old.id_import IS NULL)) EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_log_changes_insert_t_stations_occhab AFTER INSERT OR UPDATE ON pr_occhab.t_stations FOR EACH ROW WHEN ((new.id_import IS NULL)) EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT fk_t_releves_occtax_t_datasets FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT fk_t_stations_id_digitiser FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT fk_t_stations_id_nomenclature_area_surface_calculation FOREIGN KEY (id_nomenclature_area_surface_calculation) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT fk_t_stations_id_nomenclature_exposure FOREIGN KEY (id_nomenclature_exposure) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT fk_t_stations_id_nomenclature_geographic_object FOREIGN KEY (id_nomenclature_geographic_object) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT t_stations_id_import_fkey FOREIGN KEY (id_import) REFERENCES gn_imports.t_imports(id_import) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occhab.t_stations + ADD CONSTRAINT t_stations_id_nomenclature_type_mosaique_habitat_fkey FOREIGN KEY (id_nomenclature_type_mosaique_habitat) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/pr_occtax/cor_counting_occtax.sql b/data/db_state/pr_occtax/cor_counting_occtax.sql new file mode 100644 index 0000000000..d9efb78e15 --- /dev/null +++ b/data/db_state/pr_occtax/cor_counting_occtax.sql @@ -0,0 +1,88 @@ + +CREATE TABLE pr_occtax.cor_counting_occtax ( + id_counting_occtax bigint NOT NULL, + unique_id_sinp_occtax uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_occurrence_occtax bigint NOT NULL, + id_nomenclature_life_stage integer DEFAULT pr_occtax.get_default_nomenclature_value('STADE_VIE'::character varying) NOT NULL, + id_nomenclature_sex integer DEFAULT pr_occtax.get_default_nomenclature_value('SEXE'::character varying) NOT NULL, + id_nomenclature_obj_count integer DEFAULT pr_occtax.get_default_nomenclature_value('OBJ_DENBR'::character varying) NOT NULL, + id_nomenclature_type_count integer DEFAULT pr_occtax.get_default_nomenclature_value('TYP_DENBR'::character varying), + count_min integer, + count_max integer, + additional_fields jsonb, + CONSTRAINT check_cor_counting_occtax_count_max CHECK (((count_max >= count_min) AND (count_max >= 0))), + CONSTRAINT check_cor_counting_occtax_count_min CHECK ((count_min >= 0)) +); + +COMMENT ON COLUMN pr_occtax.cor_counting_occtax.id_nomenclature_life_stage IS 'Correspondance nomenclature INPN = stade_vie (10)'; + +COMMENT ON COLUMN pr_occtax.cor_counting_occtax.id_nomenclature_sex IS 'Correspondance nomenclature INPN = sexe (9)'; + +COMMENT ON COLUMN pr_occtax.cor_counting_occtax.id_nomenclature_obj_count IS 'Correspondance nomenclature INPN = obj_denbr (6)'; + +COMMENT ON COLUMN pr_occtax.cor_counting_occtax.id_nomenclature_type_count IS 'Correspondance nomenclature INPN = typ_denbr (21)'; + +CREATE SEQUENCE pr_occtax.cor_counting_occtax_id_counting_occtax_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occtax.cor_counting_occtax_id_counting_occtax_seq OWNED BY pr_occtax.cor_counting_occtax.id_counting_occtax; + +ALTER TABLE pr_occtax.cor_counting_occtax + ADD CONSTRAINT check_cor_counting_occtax_life_stage CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_life_stage, 'STADE_VIE'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.cor_counting_occtax + ADD CONSTRAINT check_cor_counting_occtax_obj_count CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_obj_count, 'OBJ_DENBR'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.cor_counting_occtax + ADD CONSTRAINT check_cor_counting_occtax_sexe CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_sex, 'SEXE'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.cor_counting_occtax + ADD CONSTRAINT check_cor_counting_occtax_type_count CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_type_count, 'TYP_DENBR'::character varying)) NOT VALID; + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT pk_cor_counting_occtax_occtax PRIMARY KEY (id_counting_occtax); + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT unique_id_sinp_occtax_unique UNIQUE (unique_id_sinp_occtax); + +CREATE INDEX i_cor_counting_occtax_id_nomenclature_life_stage ON pr_occtax.cor_counting_occtax USING btree (id_nomenclature_life_stage); + +CREATE INDEX i_cor_counting_occtax_id_nomenclature_obj_count ON pr_occtax.cor_counting_occtax USING btree (id_nomenclature_obj_count); + +CREATE INDEX i_cor_counting_occtax_id_nomenclature_sex ON pr_occtax.cor_counting_occtax USING btree (id_nomenclature_sex); + +CREATE INDEX i_cor_counting_occtax_id_nomenclature_type_count ON pr_occtax.cor_counting_occtax USING btree (id_nomenclature_type_count); + +CREATE INDEX i_cor_counting_occtax_id_occurrence_occtax ON pr_occtax.cor_counting_occtax USING btree (id_occurrence_occtax); + +CREATE TRIGGER tri_delete_cor_counting_occtax AFTER DELETE ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_delete_counting(); + +CREATE TRIGGER tri_delete_synthese_cor_counting_occtax AFTER DELETE ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_delete_counting(); + +CREATE TRIGGER tri_insert_default_validation_status AFTER INSERT ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_add_default_validation_status(); + +CREATE TRIGGER tri_insert_synthese_cor_counting_occtax AFTER INSERT ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_insert_counting(); + +CREATE TRIGGER tri_log_changes_cor_counting_occtax AFTER INSERT OR DELETE OR UPDATE ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_update_synthese_cor_counting_occtax AFTER UPDATE ON pr_occtax.cor_counting_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_update_counting(); + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT fk_cor_counting_occtax_life_stage FOREIGN KEY (id_nomenclature_life_stage) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT fk_cor_counting_occtax_obj_count FOREIGN KEY (id_nomenclature_obj_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT fk_cor_counting_occtax_sexe FOREIGN KEY (id_nomenclature_sex) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT fk_cor_counting_occtax_typ_count FOREIGN KEY (id_nomenclature_type_count) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.cor_counting_occtax + ADD CONSTRAINT fk_cor_stage_number_id_taxon FOREIGN KEY (id_occurrence_occtax) REFERENCES pr_occtax.t_occurrences_occtax(id_occurrence_occtax) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/pr_occtax/cor_role_releves_occtax.sql b/data/db_state/pr_occtax/cor_role_releves_occtax.sql new file mode 100644 index 0000000000..f73ac8cd6e --- /dev/null +++ b/data/db_state/pr_occtax/cor_role_releves_occtax.sql @@ -0,0 +1,30 @@ + +CREATE TABLE pr_occtax.cor_role_releves_occtax ( + unique_id_cor_role_releve uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_releve_occtax bigint NOT NULL, + id_role integer NOT NULL +); + +ALTER TABLE ONLY pr_occtax.cor_role_releves_occtax + ADD CONSTRAINT pk_cor_role_releves_occtax PRIMARY KEY (id_releve_occtax, id_role); + +CREATE INDEX i_cor_role_releves_occtax_id_releve_occtax ON pr_occtax.cor_role_releves_occtax USING btree (id_releve_occtax); + +CREATE INDEX i_cor_role_releves_occtax_id_role ON pr_occtax.cor_role_releves_occtax USING btree (id_role); + +CREATE UNIQUE INDEX i_cor_role_releves_occtax_id_role_id_releve_occtax ON pr_occtax.cor_role_releves_occtax USING btree (id_role, id_releve_occtax); + +CREATE TRIGGER tri_delete_synthese_cor_role_releves_occtax AFTER DELETE ON pr_occtax.cor_role_releves_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_delete_cor_role_releve(); + +CREATE TRIGGER tri_log_changes_cor_role_releves_occtax AFTER INSERT OR DELETE OR UPDATE ON pr_occtax.cor_role_releves_occtax FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_synthese_insert_cor_role_releve AFTER INSERT ON pr_occtax.cor_role_releves_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_insert_cor_role_releve(); + +CREATE TRIGGER tri_update_synthese_cor_role_releves_occtax AFTER UPDATE ON pr_occtax.cor_role_releves_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_update_cor_role_releve(); + +ALTER TABLE ONLY pr_occtax.cor_role_releves_occtax + ADD CONSTRAINT fk_cor_role_releves_occtax_t_releves_occtax FOREIGN KEY (id_releve_occtax) REFERENCES pr_occtax.t_releves_occtax(id_releve_occtax) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY pr_occtax.cor_role_releves_occtax + ADD CONSTRAINT fk_cor_role_releves_occtax_t_roles FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occtax/defaults_nomenclatures_value.sql b/data/db_state/pr_occtax/defaults_nomenclatures_value.sql new file mode 100644 index 0000000000..b2550fb9f7 --- /dev/null +++ b/data/db_state/pr_occtax/defaults_nomenclatures_value.sql @@ -0,0 +1,30 @@ + +CREATE TABLE pr_occtax.defaults_nomenclatures_value ( + mnemonique_type character varying(255) NOT NULL, + id_organism integer DEFAULT 0 NOT NULL, + regne character varying(20) DEFAULT '0'::character varying NOT NULL, + group2_inpn character varying(255) DEFAULT '0'::character varying NOT NULL, + id_nomenclature integer NOT NULL +); + +ALTER TABLE pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT check_pr_occtax_defaults_nomenclatures_value_is_nomenclature_in CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature, mnemonique_type)) NOT VALID; + +ALTER TABLE pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT check_pr_occtax_defaults_nomenclatures_value_isgroup2inpn CHECK ((taxonomie.check_is_group2inpn((group2_inpn)::text) OR ((group2_inpn)::text = '0'::text))) NOT VALID; + +ALTER TABLE pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT check_pr_occtax_defaults_nomenclatures_value_isregne CHECK ((taxonomie.check_is_regne((regne)::text) OR ((regne)::text = '0'::text))) NOT VALID; + +ALTER TABLE ONLY pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT pk_pr_occtax_defaults_nomenclatures_value PRIMARY KEY (mnemonique_type, id_organism, regne, group2_inpn); + +ALTER TABLE ONLY pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occtax_defaults_nomenclatures_value_id_nomenclature FOREIGN KEY (id_nomenclature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occtax_defaults_nomenclatures_value_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.defaults_nomenclatures_value + ADD CONSTRAINT fk_pr_occtax_defaults_nomenclatures_value_mnemonique_type FOREIGN KEY (mnemonique_type) REFERENCES ref_nomenclatures.bib_nomenclatures_types(mnemonique) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occtax/t_occurrences_occtax.sql b/data/db_state/pr_occtax/t_occurrences_occtax.sql new file mode 100644 index 0000000000..5b02647c83 --- /dev/null +++ b/data/db_state/pr_occtax/t_occurrences_occtax.sql @@ -0,0 +1,161 @@ + +CREATE TABLE pr_occtax.t_occurrences_occtax ( + id_occurrence_occtax bigint NOT NULL, + unique_id_occurence_occtax uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_releve_occtax bigint NOT NULL, + id_nomenclature_obs_technique integer DEFAULT pr_occtax.get_default_nomenclature_value('METH_OBS'::character varying) NOT NULL, + id_nomenclature_bio_condition integer DEFAULT pr_occtax.get_default_nomenclature_value('ETA_BIO'::character varying) NOT NULL, + id_nomenclature_bio_status integer DEFAULT pr_occtax.get_default_nomenclature_value('STATUT_BIO'::character varying), + id_nomenclature_naturalness integer DEFAULT pr_occtax.get_default_nomenclature_value('NATURALITE'::character varying), + id_nomenclature_exist_proof integer DEFAULT pr_occtax.get_default_nomenclature_value('PREUVE_EXIST'::character varying), + id_nomenclature_diffusion_level integer, + id_nomenclature_observation_status integer DEFAULT pr_occtax.get_default_nomenclature_value('STATUT_OBS'::character varying), + id_nomenclature_blurring integer DEFAULT pr_occtax.get_default_nomenclature_value('DEE_FLOU'::character varying), + id_nomenclature_source_status integer DEFAULT pr_occtax.get_default_nomenclature_value('STATUT_SOURCE'::character varying), + id_nomenclature_behaviour integer DEFAULT pr_occtax.get_default_nomenclature_value('OCC_COMPORTEMENT'::character varying), + determiner character varying(255), + id_nomenclature_determination_method integer DEFAULT pr_occtax.get_default_nomenclature_value('METH_DETERMIN'::character varying), + cd_nom integer, + nom_cite character varying(255) NOT NULL, + meta_v_taxref character varying(50) DEFAULT 'SELECT gn_commons.get_default_parameter(''taxref_version'')'::character varying, + sample_number_proof text, + digital_proof text, + non_digital_proof text, + comment character varying, + additional_fields jsonb +); + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_obs_technique IS 'Correspondance champs standard occtax = obsTechnique. En raison d''un changement de nom, le code nomenclature associé reste ''METH_OBS'' '; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_bio_condition IS 'Correspondance nomenclature INPN = etat_bio'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_bio_status IS 'Correspondance nomenclature INPN = statut_bio'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_naturalness IS 'Correspondance nomenclature INPN = naturalite'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_exist_proof IS 'Correspondance nomenclature INPN = preuve_exist'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_diffusion_level IS 'Correspondance nomenclature INPN = niv_precis'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_observation_status IS 'Correspondance nomenclature INPN = statut_obs'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_blurring IS 'Correspondance nomenclature INPN = dee_flou'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_source_status IS 'Correspondance nomenclature INPN = statut_source: id = 19'; + +COMMENT ON COLUMN pr_occtax.t_occurrences_occtax.id_nomenclature_determination_method IS 'Correspondance nomenclature GEONATURE = meth_determin'; + +CREATE SEQUENCE pr_occtax.t_occurrences_occtax_id_occurrence_occtax_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occtax.t_occurrences_occtax_id_occurrence_occtax_seq OWNED BY pr_occtax.t_occurrences_occtax.id_occurrence_occtax; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_accur_level CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_diffusion_level, 'NIV_PRECIS'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_behaviour CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_behaviour, 'OCC_COMPORTEMENT'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_bio_condition CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_condition, 'ETA_BIO'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_bio_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_bio_status, 'STATUT_BIO'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_blurring CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_blurring, 'DEE_FLOU'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_determination_method CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_determination_method, 'METH_DETERMIN'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_exist_proof CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_exist_proof, 'PREUVE_EXIST'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_naturalness CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_naturalness, 'NATURALITE'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_obs_meth CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_obs_technique, 'METH_OBS'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_obs_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_observation_status, 'STATUT_OBS'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_occurrences_occtax + ADD CONSTRAINT check_t_occurrences_occtax_source_status CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_source_status, 'STATUT_SOURCE'::character varying)) NOT VALID; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT pk_t_occurrences_occtax PRIMARY KEY (id_occurrence_occtax); + +CREATE INDEX i_t_occurrences_occtax_cd_nom ON pr_occtax.t_occurrences_occtax USING btree (cd_nom); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_bio_condition ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_bio_condition); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_bio_status ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_bio_status); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_blurring ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_blurring); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_determination_method ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_determination_method); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_exist_proof ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_exist_proof); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_naturalness ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_naturalness); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_obs_technique ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_obs_technique); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_observation_status ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_observation_status); + +CREATE INDEX i_t_occurrences_occtax_id_nomenclature_source_status ON pr_occtax.t_occurrences_occtax USING btree (id_nomenclature_source_status); + +CREATE INDEX i_t_occurrences_occtax_id_releve_occtax ON pr_occtax.t_occurrences_occtax USING btree (id_releve_occtax); + +CREATE TRIGGER tri_delete_synthese_t_occurrence_occtax AFTER DELETE ON pr_occtax.t_occurrences_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_delete_occ(); + +CREATE TRIGGER tri_delete_t_occurrence_occtax AFTER DELETE ON pr_occtax.t_occurrences_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_delete_occ(); + +CREATE TRIGGER tri_log_changes_t_occurrences_occtax AFTER INSERT OR DELETE OR UPDATE ON pr_occtax.t_occurrences_occtax FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_update_synthese_t_occurrence_occtax AFTER UPDATE ON pr_occtax.t_occurrences_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_update_occ(); + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_behaviour FOREIGN KEY (id_nomenclature_behaviour) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_bio_condition FOREIGN KEY (id_nomenclature_bio_condition) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_bio_status FOREIGN KEY (id_nomenclature_bio_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_blurring FOREIGN KEY (id_nomenclature_blurring) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_determination_method FOREIGN KEY (id_nomenclature_determination_method) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_diffusion_level FOREIGN KEY (id_nomenclature_diffusion_level) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_exist_proof FOREIGN KEY (id_nomenclature_exist_proof) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_naturalness FOREIGN KEY (id_nomenclature_naturalness) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_obs_meth FOREIGN KEY (id_nomenclature_obs_technique) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_observation_status FOREIGN KEY (id_nomenclature_observation_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_source_status FOREIGN KEY (id_nomenclature_source_status) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_t_releves_occtax FOREIGN KEY (id_releve_occtax) REFERENCES pr_occtax.t_releves_occtax(id_releve_occtax) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_occurrences_occtax + ADD CONSTRAINT fk_t_occurrences_occtax_taxref FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE; + diff --git a/data/db_state/pr_occtax/t_releves_occtax.sql b/data/db_state/pr_occtax/t_releves_occtax.sql new file mode 100644 index 0000000000..a6c31162a0 --- /dev/null +++ b/data/db_state/pr_occtax/t_releves_occtax.sql @@ -0,0 +1,106 @@ + +CREATE TABLE pr_occtax.t_releves_occtax ( + id_releve_occtax bigint NOT NULL, + unique_id_sinp_grp uuid DEFAULT public.uuid_generate_v4() NOT NULL, + id_dataset integer NOT NULL, + id_digitiser integer, + observers_txt character varying(500), + id_nomenclature_tech_collect_campanule integer DEFAULT pr_occtax.get_default_nomenclature_value('TECHNIQUE_OBS'::character varying), + id_nomenclature_grp_typ integer DEFAULT pr_occtax.get_default_nomenclature_value('TYP_GRP'::character varying) NOT NULL, + grp_method character varying(255), + date_min timestamp without time zone DEFAULT now() NOT NULL, + date_max timestamp without time zone DEFAULT now() NOT NULL, + hour_min time without time zone, + hour_max time without time zone, + cd_hab integer, + altitude_min integer, + altitude_max integer, + depth_min integer, + depth_max integer, + place_name character varying(500), + meta_device_entry character varying(20), + comment text, + geom_local public.geometry(Geometry,2154), + geom_4326 public.geometry(Geometry,4326), + id_nomenclature_geo_object_nature integer DEFAULT pr_occtax.get_default_nomenclature_value('NAT_OBJ_GEO'::character varying), + "precision" integer, + additional_fields jsonb, + id_module integer NOT NULL, + CONSTRAINT check_t_releves_occtax_altitude_max CHECK ((altitude_max >= altitude_min)), + CONSTRAINT check_t_releves_occtax_date_max CHECK ((date_max >= date_min)), + CONSTRAINT check_t_releves_occtax_depth CHECK ((depth_max >= depth_min)), + CONSTRAINT check_t_releves_occtax_hour_max CHECK (((hour_min <= hour_max) OR (date_min < date_max))), + CONSTRAINT enforce_dims_geom_4326 CHECK ((public.st_ndims(geom_4326) = 2)), + CONSTRAINT enforce_dims_geom_local CHECK ((public.st_ndims(geom_local) = 2)), + CONSTRAINT enforce_srid_geom_4326 CHECK ((public.st_srid(geom_4326) = 4326)), + CONSTRAINT enforce_srid_geom_local CHECK ((public.st_srid(geom_local) = 2154)) +); + +COMMENT ON COLUMN pr_occtax.t_releves_occtax.id_nomenclature_tech_collect_campanule IS 'Correspondance nomenclature CAMPANULE = technique_obs'; + +COMMENT ON COLUMN pr_occtax.t_releves_occtax.id_nomenclature_grp_typ IS 'Correspondance nomenclature INPN = Type de regroupement'; + +CREATE SEQUENCE pr_occtax.t_releves_occtax_id_releve_occtax_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE pr_occtax.t_releves_occtax_id_releve_occtax_seq OWNED BY pr_occtax.t_releves_occtax.id_releve_occtax; + +ALTER TABLE pr_occtax.t_releves_occtax + ADD CONSTRAINT check_t_releves_occtax_geo_object_nature CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_geo_object_nature, 'NAT_OBJ_GEO'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_releves_occtax + ADD CONSTRAINT check_t_releves_occtax_obs_technique CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_tech_collect_campanule, 'TECHNIQUE_OBS'::character varying)) NOT VALID; + +ALTER TABLE pr_occtax.t_releves_occtax + ADD CONSTRAINT check_t_releves_occtax_regroupement_typ CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature_grp_typ, 'TYP_GRP'::character varying)) NOT VALID; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT pk_t_releves_occtax PRIMARY KEY (id_releve_occtax); + +CREATE INDEX i_t_releves_occtax_date_max ON pr_occtax.t_releves_occtax USING btree (date_max); + +CREATE INDEX i_t_releves_occtax_geom_4326 ON pr_occtax.t_releves_occtax USING gist (geom_4326); + +CREATE INDEX i_t_releves_occtax_geom_local ON pr_occtax.t_releves_occtax USING gist (geom_local); + +CREATE INDEX i_t_releves_occtax_id_dataset ON pr_occtax.t_releves_occtax USING btree (id_dataset); + +CREATE INDEX i_t_releves_occtax_id_nomenclature_grp_typ ON pr_occtax.t_releves_occtax USING btree (id_nomenclature_grp_typ); + +CREATE INDEX i_t_releves_occtax_id_nomenclature_tech_collect_campanule ON pr_occtax.t_releves_occtax USING btree (id_nomenclature_tech_collect_campanule); + +CREATE TRIGGER tri_calculate_altitude BEFORE INSERT OR UPDATE OF geom_4326 ON pr_occtax.t_releves_occtax FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_alt_minmax('geom_4326'); + +CREATE TRIGGER tri_calculate_geom_local BEFORE INSERT OR UPDATE OF geom_4326 ON pr_occtax.t_releves_occtax FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_trg_calculate_geom_local('geom_4326', 'geom_local'); + +CREATE TRIGGER tri_delete_synthese_t_releve_occtax AFTER DELETE ON pr_occtax.t_releves_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_delete_releve(); + +CREATE TRIGGER tri_log_changes_t_releves_occtax AFTER INSERT OR DELETE OR UPDATE ON pr_occtax.t_releves_occtax FOR EACH ROW EXECUTE FUNCTION gn_commons.fct_trg_log_changes(); + +CREATE TRIGGER tri_update_synthese_t_releve_occtax AFTER UPDATE ON pr_occtax.t_releves_occtax FOR EACH ROW EXECUTE FUNCTION pr_occtax.fct_tri_synthese_update_releve(); + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_id_module FOREIGN KEY (id_module) REFERENCES gn_commons.t_modules(id_module) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_cd_hab FOREIGN KEY (cd_hab) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_id_nomenclature_geo_object_nature FOREIGN KEY (id_nomenclature_geo_object_nature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_obs_technique_campanule FOREIGN KEY (id_nomenclature_tech_collect_campanule) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_regroupement_typ FOREIGN KEY (id_nomenclature_grp_typ) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_t_datasets FOREIGN KEY (id_dataset) REFERENCES gn_meta.t_datasets(id_dataset) ON UPDATE CASCADE; + +ALTER TABLE ONLY pr_occtax.t_releves_occtax + ADD CONSTRAINT fk_t_releves_occtax_t_roles FOREIGN KEY (id_digitiser) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_geo/bib_areas_types.sql b/data/db_state/ref_geo/bib_areas_types.sql new file mode 100644 index 0000000000..30662e44d4 --- /dev/null +++ b/data/db_state/ref_geo/bib_areas_types.sql @@ -0,0 +1,35 @@ + +CREATE TABLE ref_geo.bib_areas_types ( + id_type integer NOT NULL, + type_name character varying(200) NOT NULL, + type_code character varying(25) NOT NULL, + type_desc text, + ref_name character varying(200), + ref_version integer, + num_version character varying(50), + size_hierarchy integer +); + +COMMENT ON COLUMN ref_geo.bib_areas_types.ref_name IS 'Indique le nom du référentiel géographique utilisé pour ce type'; + +COMMENT ON COLUMN ref_geo.bib_areas_types.ref_version IS 'Indique l''année du référentiel utilisé'; + +COMMENT ON COLUMN ref_geo.bib_areas_types.size_hierarchy IS 'Diamètre moyen en mètres de ce type zone. Permet d''établir une hiérarchie des types de zone géographique. Utile pour le floutage des observations.'; + +CREATE SEQUENCE ref_geo.bib_areas_types_id_type_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.bib_areas_types_id_type_seq OWNED BY ref_geo.bib_areas_types.id_type; + +ALTER TABLE ONLY ref_geo.bib_areas_types + ADD CONSTRAINT pk_bib_areas_types PRIMARY KEY (id_type); + +ALTER TABLE ONLY ref_geo.bib_areas_types + ADD CONSTRAINT unique_bib_areas_types_type_code UNIQUE (type_code); + +CREATE UNIQUE INDEX i_unique_bib_areas_types_type_code ON ref_geo.bib_areas_types USING btree (type_code); + diff --git a/data/db_state/ref_geo/bib_linears_types.sql b/data/db_state/ref_geo/bib_linears_types.sql new file mode 100644 index 0000000000..eb79deb1f4 --- /dev/null +++ b/data/db_state/ref_geo/bib_linears_types.sql @@ -0,0 +1,29 @@ + +CREATE TABLE ref_geo.bib_linears_types ( + id_type integer NOT NULL, + type_name character varying(200) NOT NULL, + type_code character varying(25) NOT NULL, + type_desc text, + ref_name character varying(200), + ref_version integer, + num_version character varying(50), + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone +); + +CREATE SEQUENCE ref_geo.bib_linears_types_id_type_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.bib_linears_types_id_type_seq OWNED BY ref_geo.bib_linears_types.id_type; + +ALTER TABLE ONLY ref_geo.bib_linears_types + ADD CONSTRAINT bib_linears_types_type_code_key UNIQUE (type_code); + +ALTER TABLE ONLY ref_geo.bib_linears_types + ADD CONSTRAINT pk_ref_geo_bib_linears_types_id_type PRIMARY KEY (id_type); + diff --git a/data/db_state/ref_geo/bib_points_types.sql b/data/db_state/ref_geo/bib_points_types.sql new file mode 100644 index 0000000000..fd16a2f7b4 --- /dev/null +++ b/data/db_state/ref_geo/bib_points_types.sql @@ -0,0 +1,29 @@ + +CREATE TABLE ref_geo.bib_points_types ( + id_type integer NOT NULL, + type_name character varying(200) NOT NULL, + type_code character varying(25) NOT NULL, + type_desc text, + ref_name character varying(200), + ref_version integer, + num_version character varying(50), + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone +); + +CREATE SEQUENCE ref_geo.bib_points_types_id_type_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.bib_points_types_id_type_seq OWNED BY ref_geo.bib_points_types.id_type; + +ALTER TABLE ONLY ref_geo.bib_points_types + ADD CONSTRAINT bib_points_types_type_code_key UNIQUE (type_code); + +ALTER TABLE ONLY ref_geo.bib_points_types + ADD CONSTRAINT pk_ref_geo_bib_points_types_id_type PRIMARY KEY (id_type); + diff --git a/data/db_state/ref_geo/cor_areas.sql b/data/db_state/ref_geo/cor_areas.sql new file mode 100644 index 0000000000..1149418d16 --- /dev/null +++ b/data/db_state/ref_geo/cor_areas.sql @@ -0,0 +1,18 @@ + +CREATE TABLE ref_geo.cor_areas ( + id_area_group integer, + id_area integer +); + +COMMENT ON TABLE ref_geo.cor_areas IS 'Table de correspondance entre les éléments lineaires et les éléments de zonage. Non remplie par défaut'; + +CREATE INDEX ref_geo_cor_areas_id_area ON ref_geo.cor_areas USING btree (id_area); + +CREATE INDEX ref_geo_cor_areas_id_area_group ON ref_geo.cor_areas USING btree (id_area_group); + +ALTER TABLE ONLY ref_geo.cor_areas + ADD CONSTRAINT fk_ref_geo_cor_areas_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY ref_geo.cor_areas + ADD CONSTRAINT fk_ref_geo_cor_areas_id_area_group FOREIGN KEY (id_area_group) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_geo/cor_linear_area.sql b/data/db_state/ref_geo/cor_linear_area.sql new file mode 100644 index 0000000000..5d19e1f5a4 --- /dev/null +++ b/data/db_state/ref_geo/cor_linear_area.sql @@ -0,0 +1,16 @@ + +CREATE TABLE ref_geo.cor_linear_area ( + id_linear integer, + id_area integer +); + +CREATE INDEX ref_geo_cor_linear_area_id_area ON ref_geo.cor_linear_area USING btree (id_area); + +CREATE INDEX ref_geo_cor_linear_area_id_linear ON ref_geo.cor_linear_area USING btree (id_linear); + +ALTER TABLE ONLY ref_geo.cor_linear_area + ADD CONSTRAINT fk_ref_geo_cor_linear_id_area_group FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY ref_geo.cor_linear_area + ADD CONSTRAINT fk_ref_geo_cor_linear_id_lineair_group FOREIGN KEY (id_linear) REFERENCES ref_geo.l_linears(id_linear) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_geo/cor_linear_group.sql b/data/db_state/ref_geo/cor_linear_group.sql new file mode 100644 index 0000000000..5747129c93 --- /dev/null +++ b/data/db_state/ref_geo/cor_linear_group.sql @@ -0,0 +1,15 @@ + +CREATE TABLE ref_geo.cor_linear_group ( + id_group integer NOT NULL, + id_linear integer NOT NULL +); + +ALTER TABLE ONLY ref_geo.cor_linear_group + ADD CONSTRAINT pk_ref_geo_cor_linear_group PRIMARY KEY (id_group, id_linear); + +ALTER TABLE ONLY ref_geo.cor_linear_group + ADD CONSTRAINT fk_ref_geo_cor_linear_group_id_group FOREIGN KEY (id_group) REFERENCES ref_geo.t_linear_groups(id_group) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY ref_geo.cor_linear_group + ADD CONSTRAINT fk_ref_geo_cor_linear_group_id_linear FOREIGN KEY (id_linear) REFERENCES ref_geo.l_linears(id_linear) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_geo/dem.sql b/data/db_state/ref_geo/dem.sql new file mode 100644 index 0000000000..75e3040597 --- /dev/null +++ b/data/db_state/ref_geo/dem.sql @@ -0,0 +1,19 @@ + +CREATE TABLE ref_geo.dem ( + rid integer NOT NULL, + rast public.raster +); + +CREATE SEQUENCE ref_geo.dem_rid_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.dem_rid_seq OWNED BY ref_geo.dem.rid; + +ALTER TABLE ONLY ref_geo.dem + ADD CONSTRAINT pk_dem PRIMARY KEY (rid); + diff --git a/data/db_state/ref_geo/dem_vector.sql b/data/db_state/ref_geo/dem_vector.sql new file mode 100644 index 0000000000..dc8f2bf6b0 --- /dev/null +++ b/data/db_state/ref_geo/dem_vector.sql @@ -0,0 +1,22 @@ + +CREATE TABLE ref_geo.dem_vector ( + gid integer NOT NULL, + geom public.geometry(Geometry,2154), + val double precision +); + +CREATE SEQUENCE ref_geo.dem_vector_gid_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.dem_vector_gid_seq OWNED BY ref_geo.dem_vector.gid; + +ALTER TABLE ONLY ref_geo.dem_vector + ADD CONSTRAINT pk_dem_vector PRIMARY KEY (gid); + +CREATE INDEX index_dem_vector_geom ON ref_geo.dem_vector USING gist (geom); + diff --git a/data/db_state/ref_geo/l_areas.sql b/data/db_state/ref_geo/l_areas.sql new file mode 100644 index 0000000000..5d62388ada --- /dev/null +++ b/data/db_state/ref_geo/l_areas.sql @@ -0,0 +1,55 @@ + +CREATE TABLE ref_geo.l_areas ( + id_area integer NOT NULL, + id_type integer NOT NULL, + area_name character varying(250), + area_code character varying(25), + geom public.geometry(MultiPolygon,2154), + centroid public.geometry(Point,2154), + source character varying(250), + comment text, + enable boolean DEFAULT true NOT NULL, + additional_data jsonb, + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone, + geom_4326 public.geometry(MultiPolygon,4326), + CONSTRAINT enforce_geotype_l_areas_centroid CHECK (((public.geometrytype(centroid) = 'POINT'::text) OR (centroid IS NULL))), + CONSTRAINT enforce_geotype_l_areas_geom CHECK (((public.geometrytype(geom) = 'MULTIPOLYGON'::text) OR (geom IS NULL))), + CONSTRAINT enforce_srid_l_areas_centroid CHECK ((public.st_srid(centroid) = 2154)), + CONSTRAINT enforce_srid_l_areas_geom CHECK ((public.st_srid(geom) = 2154)) +); + +CREATE SEQUENCE ref_geo.l_areas_id_area_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.l_areas_id_area_seq OWNED BY ref_geo.l_areas.id_area; + +ALTER TABLE ONLY ref_geo.l_areas + ADD CONSTRAINT pk_l_areas PRIMARY KEY (id_area); + +ALTER TABLE ONLY ref_geo.l_areas + ADD CONSTRAINT unique_id_type_area_code UNIQUE (id_type, area_code); + +CREATE UNIQUE INDEX i_unique_l_areas_id_type_area_code ON ref_geo.l_areas USING btree (id_type, area_code); + +CREATE INDEX idx_l_areas_geom_4326 ON ref_geo.l_areas USING gist (geom_4326); + +CREATE INDEX index_l_areas_centroid ON ref_geo.l_areas USING gist (centroid); + +CREATE INDEX index_l_areas_geom ON ref_geo.l_areas USING gist (geom); + +CREATE TRIGGER tri_insert_cor_area_synthese AFTER INSERT ON ref_geo.l_areas REFERENCING NEW TABLE AS new FOR EACH STATEMENT EXECUTE FUNCTION gn_synthese.fct_trig_l_areas_insert_cor_area_synthese_on_each_statement(); + +CREATE TRIGGER tri_meta_dates_change_l_areas BEFORE INSERT OR UPDATE ON ref_geo.l_areas FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +CREATE TRIGGER tri_transform_geom_insert BEFORE INSERT ON ref_geo.l_areas FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_tri_transform_geom(); + +CREATE TRIGGER tri_transform_geom_update BEFORE UPDATE ON ref_geo.l_areas FOR EACH ROW EXECUTE FUNCTION ref_geo.fct_tri_transform_geom(); + +ALTER TABLE ONLY ref_geo.l_areas + ADD CONSTRAINT fk_l_areas_id_type FOREIGN KEY (id_type) REFERENCES ref_geo.bib_areas_types(id_type) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_geo/l_linears.sql b/data/db_state/ref_geo/l_linears.sql new file mode 100644 index 0000000000..8e650f0c9e --- /dev/null +++ b/data/db_state/ref_geo/l_linears.sql @@ -0,0 +1,36 @@ + +CREATE TABLE ref_geo.l_linears ( + id_linear integer NOT NULL, + id_type integer NOT NULL, + linear_name character varying(250) NOT NULL, + linear_code character varying(25) NOT NULL, + enable boolean DEFAULT true NOT NULL, + geom public.geometry(Geometry,2154), + geojson_4326 character varying, + source character varying(250), + additional_data jsonb, + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone +); + +CREATE SEQUENCE ref_geo.l_linears_id_linear_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.l_linears_id_linear_seq OWNED BY ref_geo.l_linears.id_linear; + +ALTER TABLE ONLY ref_geo.l_linears + ADD CONSTRAINT l_linears_id_type_linear_code_key UNIQUE (id_type, linear_code); + +ALTER TABLE ONLY ref_geo.l_linears + ADD CONSTRAINT pk_ref_geo_l_linears_id_linear PRIMARY KEY (id_linear); + +CREATE INDEX ref_geo_l_linears_geom_idx ON ref_geo.l_linears USING gist (geom); + +ALTER TABLE ONLY ref_geo.l_linears + ADD CONSTRAINT fk_ref_geo_l_linears_id_type FOREIGN KEY (id_type) REFERENCES ref_geo.bib_linears_types(id_type) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_geo/l_points.sql b/data/db_state/ref_geo/l_points.sql new file mode 100644 index 0000000000..725ab27f95 --- /dev/null +++ b/data/db_state/ref_geo/l_points.sql @@ -0,0 +1,34 @@ + +CREATE TABLE ref_geo.l_points ( + id_point integer NOT NULL, + id_type integer NOT NULL, + point_name character varying(250) NOT NULL, + point_code character varying(25) NOT NULL, + enable boolean DEFAULT true NOT NULL, + geom public.geometry(Geometry,2154), + geojson_4326 character varying, + source character varying(250), + additional_data jsonb, + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone +); + +CREATE SEQUENCE ref_geo.l_points_id_point_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.l_points_id_point_seq OWNED BY ref_geo.l_points.id_point; + +ALTER TABLE ONLY ref_geo.l_points + ADD CONSTRAINT l_points_id_type_point_code_key UNIQUE (id_type, point_code); + +ALTER TABLE ONLY ref_geo.l_points + ADD CONSTRAINT pk_ref_geo_l_points_id_point PRIMARY KEY (id_point); + +ALTER TABLE ONLY ref_geo.l_points + ADD CONSTRAINT fk_ref_geo_l_points_id_type FOREIGN KEY (id_type) REFERENCES ref_geo.bib_points_types(id_type) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_geo/li_grids.sql b/data/db_state/ref_geo/li_grids.sql new file mode 100644 index 0000000000..c4a750cc77 --- /dev/null +++ b/data/db_state/ref_geo/li_grids.sql @@ -0,0 +1,18 @@ + +CREATE TABLE ref_geo.li_grids ( + id_grid character varying(50) NOT NULL, + id_area integer NOT NULL, + cxmin integer, + cxmax integer, + cymin integer, + cymax integer +); + +ALTER TABLE ONLY ref_geo.li_grids + ADD CONSTRAINT pk_li_grids PRIMARY KEY (id_grid); + +CREATE INDEX index_li_grids_id_area ON ref_geo.li_grids USING btree (id_area); + +ALTER TABLE ONLY ref_geo.li_grids + ADD CONSTRAINT fk_li_grids_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_geo/li_municipalities.sql b/data/db_state/ref_geo/li_municipalities.sql new file mode 100644 index 0000000000..bf8d84b0c6 --- /dev/null +++ b/data/db_state/ref_geo/li_municipalities.sql @@ -0,0 +1,38 @@ + +CREATE TABLE ref_geo.li_municipalities ( + id_municipality character varying(25) NOT NULL, + id_area integer NOT NULL, + status character varying(50), + insee_com character varying(5), + nom_com character varying(50), + insee_arr character varying(2), + nom_dep character varying(30), + insee_dep character varying(3), + nom_reg character varying(35), + insee_reg character varying(2), + code_epci character varying(9), + plani_precision double precision, + siren_code character varying(10), + canton character varying(200), + population integer, + multican character varying(3), + cc_nom character varying(250), + cc_siren bigint, + cc_nature character varying(5), + cc_date_creation character varying(10), + cc_date_effet character varying(10), + insee_commune_nouvelle character varying(5), + meta_create_date timestamp without time zone, + meta_update_date timestamp without time zone +); + +ALTER TABLE ONLY ref_geo.li_municipalities + ADD CONSTRAINT pk_li_municipalities PRIMARY KEY (id_municipality); + +CREATE INDEX index_li_municipalities_id_area ON ref_geo.li_municipalities USING btree (id_area); + +CREATE TRIGGER tri_meta_dates_change_li_municipalities BEFORE INSERT OR UPDATE ON ref_geo.li_municipalities FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY ref_geo.li_municipalities + ADD CONSTRAINT fk_li_municipalities_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_geo/t_linear_groups.sql b/data/db_state/ref_geo/t_linear_groups.sql new file mode 100644 index 0000000000..e7f3e52c1d --- /dev/null +++ b/data/db_state/ref_geo/t_linear_groups.sql @@ -0,0 +1,23 @@ + +CREATE TABLE ref_geo.t_linear_groups ( + id_group integer NOT NULL, + name character varying(250) NOT NULL, + code character varying(25) NOT NULL +); + +CREATE SEQUENCE ref_geo.t_linear_groups_id_group_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_geo.t_linear_groups_id_group_seq OWNED BY ref_geo.t_linear_groups.id_group; + +ALTER TABLE ONLY ref_geo.t_linear_groups + ADD CONSTRAINT pk_ref_geo_linear_group_id_group PRIMARY KEY (id_group); + +ALTER TABLE ONLY ref_geo.t_linear_groups + ADD CONSTRAINT t_linear_groups_code_key UNIQUE (code); + diff --git a/data/db_state/ref_habitats/autocomplete_habitat.sql b/data/db_state/ref_habitats/autocomplete_habitat.sql new file mode 100644 index 0000000000..a0ad443199 --- /dev/null +++ b/data/db_state/ref_habitats/autocomplete_habitat.sql @@ -0,0 +1,12 @@ + +CREATE TABLE ref_habitats.autocomplete_habitat ( + cd_hab integer NOT NULL, + cd_typo integer NOT NULL, + lb_code character varying(50), + lb_nom_typo character varying(100) NOT NULL, + search_name character varying(1000) NOT NULL +); + +ALTER TABLE ONLY ref_habitats.autocomplete_habitat + ADD CONSTRAINT pk_autocomplete_habitat PRIMARY KEY (cd_hab); + diff --git a/data/db_state/ref_habitats/bib_habref_statuts.sql b/data/db_state/ref_habitats/bib_habref_statuts.sql new file mode 100644 index 0000000000..aaf343e730 --- /dev/null +++ b/data/db_state/ref_habitats/bib_habref_statuts.sql @@ -0,0 +1,13 @@ + +CREATE TABLE ref_habitats.bib_habref_statuts ( + statut character varying(1) NOT NULL, + description character varying(50) NOT NULL, + definition character varying(500) NOT NULL, + ordre integer +); + +COMMENT ON TABLE ref_habitats.bib_habref_statuts IS 'Bibliothèque des types statut d''habitat - Présence, absence ... - Table habref_status de HABREF'; + +ALTER TABLE ONLY ref_habitats.bib_habref_statuts + ADD CONSTRAINT pk_bib_habref_statuts PRIMARY KEY (statut); + diff --git a/data/db_state/ref_habitats/bib_habref_typo_rel.sql b/data/db_state/ref_habitats/bib_habref_typo_rel.sql new file mode 100644 index 0000000000..9cacdaceb7 --- /dev/null +++ b/data/db_state/ref_habitats/bib_habref_typo_rel.sql @@ -0,0 +1,17 @@ + +CREATE TABLE ref_habitats.bib_habref_typo_rel ( + cd_type_rel integer NOT NULL, + lb_type_rel character varying(200), + lb_rel character varying(1000), + corresp_hab boolean, + corresp_esp boolean, + corresp_syn boolean, + date_crea text, + date_modif text +); + +COMMENT ON TABLE ref_habitats.bib_habref_typo_rel IS 'Bibliothèque des types de relations entre habitats - Table habref_typo_rel de HABREF'; + +ALTER TABLE ONLY ref_habitats.bib_habref_typo_rel + ADD CONSTRAINT pk_bib_habref_typo_rel PRIMARY KEY (cd_type_rel); + diff --git a/data/db_state/ref_habitats/bib_list_habitat.sql b/data/db_state/ref_habitats/bib_list_habitat.sql new file mode 100644 index 0000000000..3c14174904 --- /dev/null +++ b/data/db_state/ref_habitats/bib_list_habitat.sql @@ -0,0 +1,21 @@ + +CREATE TABLE ref_habitats.bib_list_habitat ( + id_list integer NOT NULL, + list_name character varying(255) NOT NULL +); + +COMMENT ON TABLE ref_habitats.bib_list_habitat IS 'Table des listes des habitats'; + +CREATE SEQUENCE ref_habitats.bib_list_habitat_id_list_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_habitats.bib_list_habitat_id_list_seq OWNED BY ref_habitats.bib_list_habitat.id_list; + +ALTER TABLE ONLY ref_habitats.bib_list_habitat + ADD CONSTRAINT pk_bib_list_habitat PRIMARY KEY (id_list); + diff --git a/data/db_state/ref_habitats/cor_hab_source.sql b/data/db_state/ref_habitats/cor_hab_source.sql new file mode 100644 index 0000000000..9b71d67787 --- /dev/null +++ b/data/db_state/ref_habitats/cor_hab_source.sql @@ -0,0 +1,19 @@ + +CREATE TABLE ref_habitats.cor_hab_source ( + cd_hab_lien_source integer NOT NULL, + cd integer NOT NULL, + type_lien character varying(7) NOT NULL, + cd_source integer NOT NULL, + origine character varying(5), + date_crea text, + date_modif text +); + +COMMENT ON TABLE ref_habitats.cor_hab_source IS 'Table de corespondance entre une unité (cd_hab, cd_coresp_hab, cd_coresp_taxon) et une source - Table habref_lien_source de HABREF'; + +ALTER TABLE ONLY ref_habitats.cor_hab_source + ADD CONSTRAINT pk_cor_hab_source PRIMARY KEY (cd_hab_lien_source); + +ALTER TABLE ONLY ref_habitats.cor_hab_source + ADD CONSTRAINT fk_cor_cor_hab_source_cd_source FOREIGN KEY (cd_source) REFERENCES ref_habitats.habref_sources(cd_source) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_habitats/cor_habref_description.sql b/data/db_state/ref_habitats/cor_habref_description.sql new file mode 100644 index 0000000000..2a87126105 --- /dev/null +++ b/data/db_state/ref_habitats/cor_habref_description.sql @@ -0,0 +1,22 @@ + +CREATE TABLE ref_habitats.cor_habref_description ( + cd_hab_description integer NOT NULL, + cd_hab integer NOT NULL, + cd_hab_field integer NOT NULL, + cd_typo integer, + lb_code character varying(50), + lb_hab_field character varying(200), + valeurs text +); + +COMMENT ON TABLE ref_habitats.cor_habref_description IS 'Table de correspondance entre un habitat et les champs additionnels décrit dans la table typoref_fields - Table habref_description de HABREF'; + +ALTER TABLE ONLY ref_habitats.cor_habref_description + ADD CONSTRAINT pk_cor_habref_description PRIMARY KEY (cd_hab_description); + +ALTER TABLE ONLY ref_habitats.cor_habref_description + ADD CONSTRAINT fk_cor_habref_description_cd_hab FOREIGN KEY (cd_hab) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY ref_habitats.cor_habref_description + ADD CONSTRAINT fk_cor_habref_description_cd_hab_field FOREIGN KEY (cd_hab_field) REFERENCES ref_habitats.typoref_fields(cd_hab_field) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/ref_habitats/cor_habref_terr_statut.sql b/data/db_state/ref_habitats/cor_habref_terr_statut.sql new file mode 100644 index 0000000000..cfe036f9c1 --- /dev/null +++ b/data/db_state/ref_habitats/cor_habref_terr_statut.sql @@ -0,0 +1,21 @@ + +CREATE TABLE ref_habitats.cor_habref_terr_statut ( + cd_hab_ter integer NOT NULL, + cd_hab integer NOT NULL, + cd_sig_terr character varying(20) NOT NULL, + cd_statut_presence character varying(1), + date_crea text, + date_modif text +); + +COMMENT ON TABLE ref_habitats.cor_habref_terr_statut IS 'Table de descritpion des champs additionnels de chaque typologie.'; + +ALTER TABLE ONLY ref_habitats.cor_habref_terr_statut + ADD CONSTRAINT pk_cor_habref_terr_statut PRIMARY KEY (cd_hab_ter); + +ALTER TABLE ONLY ref_habitats.cor_habref_terr_statut + ADD CONSTRAINT fk_cor_habref_terr_statut_cd_hab FOREIGN KEY (cd_hab) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_habitats.cor_habref_terr_statut + ADD CONSTRAINT fk_cor_habref_terr_statut_cd_statut_presence FOREIGN KEY (cd_statut_presence) REFERENCES ref_habitats.bib_habref_statuts(statut) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_habitats/cor_list_habitat.sql b/data/db_state/ref_habitats/cor_list_habitat.sql new file mode 100644 index 0000000000..e7ea79d9f4 --- /dev/null +++ b/data/db_state/ref_habitats/cor_list_habitat.sql @@ -0,0 +1,31 @@ + +CREATE TABLE ref_habitats.cor_list_habitat ( + id_cor_list integer NOT NULL, + id_list integer NOT NULL, + cd_hab integer NOT NULL +); + +COMMENT ON TABLE ref_habitats.cor_list_habitat IS 'Habitat de chaque liste'; + +CREATE SEQUENCE ref_habitats.cor_list_habitat_id_cor_list_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_habitats.cor_list_habitat_id_cor_list_seq OWNED BY ref_habitats.cor_list_habitat.id_cor_list; + +ALTER TABLE ONLY ref_habitats.cor_list_habitat + ADD CONSTRAINT pk_cor_list_habitat PRIMARY KEY (id_cor_list); + +ALTER TABLE ONLY ref_habitats.cor_list_habitat + ADD CONSTRAINT unique_cor_list_habitat UNIQUE (id_list, cd_hab); + +ALTER TABLE ONLY ref_habitats.cor_list_habitat + ADD CONSTRAINT fk_cor_list_habitat_cd_hab FOREIGN KEY (cd_hab) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_habitats.cor_list_habitat + ADD CONSTRAINT fk_cor_list_habitat_id_list FOREIGN KEY (id_list) REFERENCES ref_habitats.bib_list_habitat(id_list) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_habitats/habref.sql b/data/db_state/ref_habitats/habref.sql new file mode 100644 index 0000000000..7348b0054c --- /dev/null +++ b/data/db_state/ref_habitats/habref.sql @@ -0,0 +1,26 @@ + +CREATE TABLE ref_habitats.habref ( + cd_hab integer NOT NULL, + fg_validite character varying(20) NOT NULL, + cd_typo integer NOT NULL, + lb_code character varying(50), + lb_hab_fr character varying(500), + lb_hab_fr_complet character varying(500), + lb_hab_en character varying(500), + lb_auteur character varying(500), + niveau integer, + lb_niveau character varying(100), + cd_hab_sup integer, + path_cd_hab character varying(2000), + france character varying(5), + lb_description character varying(4000) +); + +COMMENT ON TABLE ref_habitats.habref IS 'habref, table HABREF référentiel HABREF 4.0 INPN'; + +ALTER TABLE ONLY ref_habitats.habref + ADD CONSTRAINT pk_habref PRIMARY KEY (cd_hab); + +ALTER TABLE ONLY ref_habitats.habref + ADD CONSTRAINT fk_typoref FOREIGN KEY (cd_typo) REFERENCES ref_habitats.typoref(cd_typo) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_habitats/habref_corresp_hab.sql b/data/db_state/ref_habitats/habref_corresp_hab.sql new file mode 100644 index 0000000000..367ae0a9d3 --- /dev/null +++ b/data/db_state/ref_habitats/habref_corresp_hab.sql @@ -0,0 +1,30 @@ + +CREATE TABLE ref_habitats.habref_corresp_hab ( + cd_corresp_hab integer NOT NULL, + cd_hab_entre integer NOT NULL, + cd_hab_sortie integer, + cd_type_relation integer, + lb_condition character varying(1000), + lb_remarques character varying(4000), + validite boolean, + cd_typo_entre integer, + cd_typo_sortie integer, + date_crea text, + date_modif text, + diffusion boolean +); + +COMMENT ON TABLE ref_habitats.habref_corresp_hab IS 'Table de corespondances entres les habitats de differentes typologie'; + +ALTER TABLE ONLY ref_habitats.habref_corresp_hab + ADD CONSTRAINT pk_habref_corresp_hab PRIMARY KEY (cd_corresp_hab); + +ALTER TABLE ONLY ref_habitats.habref_corresp_hab + ADD CONSTRAINT fk_habref_corresp_hab_cd_hab_entre FOREIGN KEY (cd_hab_entre) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_habitats.habref_corresp_hab + ADD CONSTRAINT fk_habref_corresp_hab_cd_hab_sortie FOREIGN KEY (cd_hab_sortie) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_habitats.habref_corresp_hab + ADD CONSTRAINT fk_habref_corresp_hab_cd_type_rel FOREIGN KEY (cd_type_relation) REFERENCES ref_habitats.bib_habref_typo_rel(cd_type_rel) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_habitats/habref_corresp_taxon.sql b/data/db_state/ref_habitats/habref_corresp_taxon.sql new file mode 100644 index 0000000000..b7376cf328 --- /dev/null +++ b/data/db_state/ref_habitats/habref_corresp_taxon.sql @@ -0,0 +1,25 @@ + +CREATE TABLE ref_habitats.habref_corresp_taxon ( + cd_corresp_tax integer NOT NULL, + cd_hab_entre integer NOT NULL, + cd_nom integer, + cd_type_relation integer, + lb_condition character varying(1000), + lb_remarques character varying(4000), + nom_cite character varying(500), + validite boolean, + date_crea text, + date_modif text +); + +COMMENT ON TABLE ref_habitats.habref_corresp_taxon IS 'Table de corespondances entres les habitats les taxon (table taxref)'; + +ALTER TABLE ONLY ref_habitats.habref_corresp_taxon + ADD CONSTRAINT pk_habref_corresp_taxon PRIMARY KEY (cd_corresp_tax); + +ALTER TABLE ONLY ref_habitats.habref_corresp_taxon + ADD CONSTRAINT fk_habref_corresp_tax_cd_hab_entre FOREIGN KEY (cd_hab_entre) REFERENCES ref_habitats.habref(cd_hab) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_habitats.habref_corresp_taxon + ADD CONSTRAINT fk_habref_corresp_tax_cd_typ_rel FOREIGN KEY (cd_type_relation) REFERENCES ref_habitats.bib_habref_typo_rel(cd_type_rel) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_habitats/habref_sources.sql b/data/db_state/ref_habitats/habref_sources.sql new file mode 100644 index 0000000000..8a16c6f9e6 --- /dev/null +++ b/data/db_state/ref_habitats/habref_sources.sql @@ -0,0 +1,20 @@ + +CREATE TABLE ref_habitats.habref_sources ( + cd_source integer NOT NULL, + cd_doc integer, + type_source character varying(1), + auteur_source character varying(255), + date_source integer, + lb_source character varying(1000), + lb_source_complet character varying(2000), + titre character varying(1000), + link character varying(1000), + date_crea text, + date_modif text +); + +COMMENT ON TABLE ref_habitats.habref_sources IS 'Table des sources décrivant les habitats'; + +ALTER TABLE ONLY ref_habitats.habref_sources + ADD CONSTRAINT pk_habref_sources PRIMARY KEY (cd_source); + diff --git a/data/db_state/ref_habitats/typoref.sql b/data/db_state/ref_habitats/typoref.sql new file mode 100644 index 0000000000..7fe528c9dd --- /dev/null +++ b/data/db_state/ref_habitats/typoref.sql @@ -0,0 +1,43 @@ + +CREATE TABLE ref_habitats.typoref ( + cd_typo integer NOT NULL, + cd_table character varying(255), + lb_nom_typo character varying(100), + nom_jeu_donnees character varying(255), + date_creation character varying(255), + date_mise_jour_table character varying(255), + date_mise_jour_metadonnees character varying(255), + auteur_typo character varying(4000), + auteur_table character varying(4000), + territoire character varying(4000), + organisme character varying(255), + langue character varying(255), + presentation character varying(4000), + description character varying(4000), + origine character varying(4000), + ref_biblio character varying(4000), + mots_cles character varying(255), + referencement character varying(4000), + diffusion character varying(4000), + derniere_modif character varying(4000), + type_table character varying(6), + cd_typo_entre integer, + cd_typo_sortie integer, + niveau_inpn character varying(255) +); + +COMMENT ON TABLE ref_habitats.typoref IS 'typoref, table TYPOREF du référentiel HABREF 4.0'; + +CREATE SEQUENCE ref_habitats.typoref_cd_typo_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_habitats.typoref_cd_typo_seq OWNED BY ref_habitats.typoref.cd_typo; + +ALTER TABLE ONLY ref_habitats.typoref + ADD CONSTRAINT pk_typoref PRIMARY KEY (cd_typo); + diff --git a/data/db_state/ref_habitats/typoref_fields.sql b/data/db_state/ref_habitats/typoref_fields.sql new file mode 100644 index 0000000000..cca0fa8bea --- /dev/null +++ b/data/db_state/ref_habitats/typoref_fields.sql @@ -0,0 +1,17 @@ + +CREATE TABLE ref_habitats.typoref_fields ( + cd_hab_field integer NOT NULL, + cd_typo integer NOT NULL, + lb_hab_field character varying(30) NOT NULL, + format_hab_field character varying(200), + descript_hab_field character varying(3000), + ordre_hab_field integer, + length_hab_field integer, + lb_label character varying(200), + date_crea text, + date_modif text +); + +ALTER TABLE ONLY ref_habitats.typoref_fields + ADD CONSTRAINT pk_typoref_fields PRIMARY KEY (cd_hab_field); + diff --git a/data/db_state/ref_nomenclatures/bib_nomenclatures_types.sql b/data/db_state/ref_nomenclatures/bib_nomenclatures_types.sql new file mode 100644 index 0000000000..29a6484935 --- /dev/null +++ b/data/db_state/ref_nomenclatures/bib_nomenclatures_types.sql @@ -0,0 +1,41 @@ + +CREATE TABLE ref_nomenclatures.bib_nomenclatures_types ( + id_type integer NOT NULL, + mnemonique character varying(255), + label_default character varying(255) NOT NULL, + definition_default text, + label_fr character varying(255) NOT NULL, + definition_fr text, + label_en character varying(255), + definition_en text, + label_es character varying(255), + definition_es text, + label_de character varying(255), + definition_de text, + label_it character varying(255), + definition_it text, + source character varying(50), + statut character varying(20), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone DEFAULT now() +); + +COMMENT ON TABLE ref_nomenclatures.bib_nomenclatures_types IS 'Types of nomenclature (SINP, CAMPanule, GeoNature...)'; + +CREATE SEQUENCE ref_nomenclatures.bib_nomenclatures_types_id_type_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_nomenclatures.bib_nomenclatures_types_id_type_seq OWNED BY ref_nomenclatures.bib_nomenclatures_types.id_type; + +ALTER TABLE ONLY ref_nomenclatures.bib_nomenclatures_types + ADD CONSTRAINT pk_bib_nomenclatures_types PRIMARY KEY (id_type); + +ALTER TABLE ONLY ref_nomenclatures.bib_nomenclatures_types + ADD CONSTRAINT unique_bib_nomenclatures_types_mnemonique UNIQUE (mnemonique); + +CREATE TRIGGER tri_meta_dates_change_bib_nomenclatures_types BEFORE INSERT OR UPDATE ON ref_nomenclatures.bib_nomenclatures_types FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + diff --git a/data/db_state/ref_nomenclatures/cor_application_nomenclature.sql b/data/db_state/ref_nomenclatures/cor_application_nomenclature.sql new file mode 100644 index 0000000000..3947fb30c3 --- /dev/null +++ b/data/db_state/ref_nomenclatures/cor_application_nomenclature.sql @@ -0,0 +1,17 @@ + +CREATE TABLE ref_nomenclatures.cor_application_nomenclature ( + id_nomenclature integer NOT NULL, + id_application integer NOT NULL +); + +COMMENT ON TABLE ref_nomenclatures.cor_application_nomenclature IS 'Allow to create specific list per module for one nomenclature.'; + +ALTER TABLE ONLY ref_nomenclatures.cor_application_nomenclature + ADD CONSTRAINT pk_cor_application_nomenclature PRIMARY KEY (id_nomenclature, id_application); + +ALTER TABLE ONLY ref_nomenclatures.cor_application_nomenclature + ADD CONSTRAINT fk_cor_application_nomenclature_id_application FOREIGN KEY (id_application) REFERENCES utilisateurs.t_applications(id_application) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_nomenclatures.cor_application_nomenclature + ADD CONSTRAINT fk_cor_application_nomenclature_id_nomenclature FOREIGN KEY (id_nomenclature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_nomenclatures/cor_nomenclatures_relations.sql b/data/db_state/ref_nomenclatures/cor_nomenclatures_relations.sql new file mode 100644 index 0000000000..451114930f --- /dev/null +++ b/data/db_state/ref_nomenclatures/cor_nomenclatures_relations.sql @@ -0,0 +1,16 @@ + +CREATE TABLE ref_nomenclatures.cor_nomenclatures_relations ( + id_nomenclature_l integer NOT NULL, + id_nomenclature_r integer NOT NULL, + relation_type character varying(250) NOT NULL +); + +ALTER TABLE ONLY ref_nomenclatures.cor_nomenclatures_relations + ADD CONSTRAINT pk_cor_nomenclatures_relations PRIMARY KEY (id_nomenclature_l, id_nomenclature_r, relation_type); + +ALTER TABLE ONLY ref_nomenclatures.cor_nomenclatures_relations + ADD CONSTRAINT fk_cor_nomenclatures_relations_id_nomenclature_l FOREIGN KEY (id_nomenclature_l) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY ref_nomenclatures.cor_nomenclatures_relations + ADD CONSTRAINT fk_cor_nomenclatures_relations_id_nomenclature_r FOREIGN KEY (id_nomenclature_r) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + diff --git a/data/db_state/ref_nomenclatures/cor_taxref_nomenclature.sql b/data/db_state/ref_nomenclatures/cor_taxref_nomenclature.sql new file mode 100644 index 0000000000..8ebcc835a0 --- /dev/null +++ b/data/db_state/ref_nomenclatures/cor_taxref_nomenclature.sql @@ -0,0 +1,27 @@ + +CREATE TABLE ref_nomenclatures.cor_taxref_nomenclature ( + id_nomenclature integer NOT NULL, + regne character varying(255) NOT NULL, + group2_inpn character varying(255) NOT NULL, + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone, + group3_inpn character varying(255) DEFAULT 'all'::character varying NOT NULL +); + +ALTER TABLE ref_nomenclatures.cor_taxref_nomenclature + ADD CONSTRAINT check_cor_taxref_nomenclature_isgroup2inpn CHECK ((taxonomie.check_is_group2inpn((group2_inpn)::text) OR ((group2_inpn)::text = 'all'::text))) NOT VALID; + +ALTER TABLE ref_nomenclatures.cor_taxref_nomenclature + ADD CONSTRAINT check_cor_taxref_nomenclature_isgroup3inpn CHECK ((taxonomie.check_is_group3inpn((group3_inpn)::text) OR ((group3_inpn)::text = 'all'::text))) NOT VALID; + +ALTER TABLE ref_nomenclatures.cor_taxref_nomenclature + ADD CONSTRAINT check_cor_taxref_nomenclature_isregne CHECK ((taxonomie.check_is_regne((regne)::text) OR ((regne)::text = 'all'::text))) NOT VALID; + +ALTER TABLE ONLY ref_nomenclatures.cor_taxref_nomenclature + ADD CONSTRAINT pk_cor_taxref_nomenclature PRIMARY KEY (id_nomenclature, regne, group2_inpn, group3_inpn); + +CREATE TRIGGER tri_meta_dates_change_cor_taxref_nomenclature BEFORE INSERT OR UPDATE ON ref_nomenclatures.cor_taxref_nomenclature FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY ref_nomenclatures.cor_taxref_nomenclature + ADD CONSTRAINT fk_cor_taxref_nomenclature_id_nomenclature FOREIGN KEY (id_nomenclature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_nomenclatures/defaults_nomenclatures_value.sql b/data/db_state/ref_nomenclatures/defaults_nomenclatures_value.sql new file mode 100644 index 0000000000..99ffc64d09 --- /dev/null +++ b/data/db_state/ref_nomenclatures/defaults_nomenclatures_value.sql @@ -0,0 +1,22 @@ + +CREATE TABLE ref_nomenclatures.defaults_nomenclatures_value ( + mnemonique_type character varying(255) NOT NULL, + id_organism integer NOT NULL, + id_nomenclature integer NOT NULL +); + +ALTER TABLE ref_nomenclatures.defaults_nomenclatures_value + ADD CONSTRAINT check_defaults_nomenclatures_value_is_nomenclature_in_type CHECK (ref_nomenclatures.check_nomenclature_type_by_mnemonique(id_nomenclature, mnemonique_type)) NOT VALID; + +ALTER TABLE ONLY ref_nomenclatures.defaults_nomenclatures_value + ADD CONSTRAINT pk_defaults_nomenclatures_value PRIMARY KEY (mnemonique_type, id_organism); + +ALTER TABLE ONLY ref_nomenclatures.defaults_nomenclatures_value + ADD CONSTRAINT fk_defaults_nomenclatures_value_id_nomenclature FOREIGN KEY (id_nomenclature) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_nomenclatures.defaults_nomenclatures_value + ADD CONSTRAINT fk_defaults_nomenclatures_value_id_organism FOREIGN KEY (id_organism) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + +ALTER TABLE ONLY ref_nomenclatures.defaults_nomenclatures_value + ADD CONSTRAINT fk_defaults_nomenclatures_value_mnemonique_type FOREIGN KEY (mnemonique_type) REFERENCES ref_nomenclatures.bib_nomenclatures_types(mnemonique) ON UPDATE CASCADE; + diff --git a/data/db_state/ref_nomenclatures/t_nomenclatures.sql b/data/db_state/ref_nomenclatures/t_nomenclatures.sql new file mode 100644 index 0000000000..42fb0ecbcd --- /dev/null +++ b/data/db_state/ref_nomenclatures/t_nomenclatures.sql @@ -0,0 +1,52 @@ + +CREATE TABLE ref_nomenclatures.t_nomenclatures ( + id_nomenclature integer NOT NULL, + id_type integer NOT NULL, + cd_nomenclature character varying(255) NOT NULL, + mnemonique character varying(255), + label_default character varying(255) NOT NULL, + definition_default text, + label_fr character varying(255) NOT NULL, + definition_fr text, + label_en character varying(255), + definition_en text, + label_es character varying(255), + definition_es text, + label_de character varying(255), + definition_de text, + label_it character varying(255), + definition_it text, + source character varying(50), + statut character varying(20), + id_broader integer, + hierarchy character varying(255), + meta_create_date timestamp without time zone DEFAULT now(), + meta_update_date timestamp without time zone, + active boolean DEFAULT true NOT NULL +); + +CREATE SEQUENCE ref_nomenclatures.t_nomenclatures_id_nomenclature_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ref_nomenclatures.t_nomenclatures_id_nomenclature_seq OWNED BY ref_nomenclatures.t_nomenclatures.id_nomenclature; + +ALTER TABLE ONLY ref_nomenclatures.t_nomenclatures + ADD CONSTRAINT pk_t_nomenclatures PRIMARY KEY (id_nomenclature); + +ALTER TABLE ONLY ref_nomenclatures.t_nomenclatures + ADD CONSTRAINT unique_id_type_cd_nomenclature UNIQUE (id_type, cd_nomenclature); + +CREATE INDEX index_t_nomenclatures_bib_nomenclatures_types_fkey ON ref_nomenclatures.t_nomenclatures USING btree (id_type); + +CREATE TRIGGER tri_meta_dates_change_t_nomenclatures BEFORE INSERT OR UPDATE ON ref_nomenclatures.t_nomenclatures FOR EACH ROW EXECUTE FUNCTION public.fct_trg_meta_dates_change(); + +ALTER TABLE ONLY ref_nomenclatures.t_nomenclatures + ADD CONSTRAINT fk_t_nomenclatures_id_broader FOREIGN KEY (id_broader) REFERENCES ref_nomenclatures.t_nomenclatures(id_nomenclature); + +ALTER TABLE ONLY ref_nomenclatures.t_nomenclatures + ADD CONSTRAINT fk_t_nomenclatures_id_type FOREIGN KEY (id_type) REFERENCES ref_nomenclatures.bib_nomenclatures_types(id_type) ON UPDATE CASCADE; + diff --git a/data/db_state/schemas.txt b/data/db_state/schemas.txt new file mode 100644 index 0000000000..9363b0e4bd --- /dev/null +++ b/data/db_state/schemas.txt @@ -0,0 +1,16 @@ + utilisateurs + ref_geo + ref_habitats + taxonomie + ref_nomenclatures + gn_commons + gn_meta + gn_imports + gn_synthese + gn_monitoring + gn_permissions + gn_sensitivity + gn_profiles + gn_notifications + pr_occhab + pr_occtax \ No newline at end of file diff --git a/data/db_state/taxonomie/archive_bib_noms.sql b/data/db_state/taxonomie/archive_bib_noms.sql new file mode 100644 index 0000000000..9dd9919639 --- /dev/null +++ b/data/db_state/taxonomie/archive_bib_noms.sql @@ -0,0 +1,9 @@ + +CREATE TABLE taxonomie.archive_bib_noms ( + id_nom integer, + cd_nom integer, + cd_ref integer, + nom_francais character varying(1000), + comments character varying(1000) +); + diff --git a/data/db_state/taxonomie/bdc_statut.sql b/data/db_state/taxonomie/bdc_statut.sql new file mode 100644 index 0000000000..369c43f196 --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut.sql @@ -0,0 +1,49 @@ + +CREATE TABLE taxonomie.bdc_statut ( + id integer NOT NULL, + cd_nom integer NOT NULL, + cd_ref integer NOT NULL, + cd_sup integer, + cd_type_statut character varying(50) NOT NULL, + lb_type_statut character varying(250), + regroupement_type character varying(250), + code_statut character varying(250), + label_statut character varying(1000), + rq_statut text, + cd_sig character varying(100), + cd_doc integer, + lb_nom character varying(1000), + lb_auteur character varying(1000), + nom_complet_html character varying(1000), + nom_valide_html character varying(1000), + regne character varying(250), + phylum character varying(250), + classe character varying(250), + ordre character varying(250), + famille character varying(250), + group1_inpn character varying(255), + group2_inpn character varying(255), + lb_adm_tr character varying(100), + niveau_admin character varying(250), + cd_iso3166_1 character varying(50), + cd_iso3166_2 character varying(50), + full_citation text, + doc_url text, + thematique character varying(100), + type_value character varying(100) +); + +COMMENT ON TABLE taxonomie.bdc_statut IS 'Table initialement fournie par l''INPN. Contient tout les statuts sous leur forme brute'; + +CREATE SEQUENCE taxonomie.bdc_statut_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bdc_statut_id_seq OWNED BY taxonomie.bdc_statut.id; + +CREATE INDEX bdc_statut_id_idx ON taxonomie.bdc_statut USING btree (id); + diff --git a/data/db_state/taxonomie/bdc_statut_cor_text_area.sql b/data/db_state/taxonomie/bdc_statut_cor_text_area.sql new file mode 100644 index 0000000000..d68db37f63 --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_cor_text_area.sql @@ -0,0 +1,15 @@ + +CREATE TABLE taxonomie.bdc_statut_cor_text_area ( + id_text integer NOT NULL, + id_area integer NOT NULL +); + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_area + ADD CONSTRAINT bdc_statut_cor_text_area_pkey PRIMARY KEY (id_text, id_area); + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_area + ADD CONSTRAINT fk_bdc_statut_cor_text_area_id_area FOREIGN KEY (id_area) REFERENCES ref_geo.l_areas(id_area) ON UPDATE CASCADE; + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_area + ADD CONSTRAINT fk_bdc_statut_cor_text_area_id_text FOREIGN KEY (id_text) REFERENCES taxonomie.bdc_statut_text(id_text) ON UPDATE CASCADE; + diff --git a/data/db_state/taxonomie/bdc_statut_cor_text_values.sql b/data/db_state/taxonomie/bdc_statut_cor_text_values.sql new file mode 100644 index 0000000000..e3d45a46b0 --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_cor_text_values.sql @@ -0,0 +1,32 @@ + +CREATE TABLE taxonomie.bdc_statut_cor_text_values ( + id_value_text integer NOT NULL, + id_value integer NOT NULL, + id_text integer NOT NULL +); + +COMMENT ON TABLE taxonomie.bdc_statut_cor_text_values IS 'Table d''association entre les textes, les taxons et la valeur'; + +CREATE SEQUENCE taxonomie.bdc_statut_cor_text_values_id_value_text_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bdc_statut_cor_text_values_id_value_text_seq OWNED BY taxonomie.bdc_statut_cor_text_values.id_value_text; + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_values + ADD CONSTRAINT bdc_statut_cor_text_values_pkey PRIMARY KEY (id_value_text); + +CREATE INDEX idx_bsctv_id_text ON taxonomie.bdc_statut_cor_text_values USING btree (id_text); + +CREATE INDEX idx_bsctv_id_value ON taxonomie.bdc_statut_cor_text_values USING btree (id_value); + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_values + ADD CONSTRAINT tbdc_statut_cor_text_values_id_text_fkey FOREIGN KEY (id_text) REFERENCES taxonomie.bdc_statut_text(id_text) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY taxonomie.bdc_statut_cor_text_values + ADD CONSTRAINT tbdc_statut_cor_text_values_id_value_fkey FOREIGN KEY (id_value) REFERENCES taxonomie.bdc_statut_values(id_value) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/taxonomie/bdc_statut_taxons.sql b/data/db_state/taxonomie/bdc_statut_taxons.sql new file mode 100644 index 0000000000..c5f27dcd6d --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_taxons.sql @@ -0,0 +1,22 @@ + +CREATE TABLE taxonomie.bdc_statut_taxons ( + id integer NOT NULL, + id_value_text integer NOT NULL, + cd_nom integer NOT NULL, + cd_ref integer NOT NULL, + rq_statut character varying(1000) +); + +COMMENT ON TABLE taxonomie.bdc_statut_taxons IS 'Table d''association entre les textes et les taxons'; + +ALTER TABLE ONLY taxonomie.bdc_statut_taxons + ADD CONSTRAINT bdc_statut_taxons_pkey PRIMARY KEY (id); + +CREATE INDEX idx_bst_id_value_text ON taxonomie.bdc_statut_taxons USING btree (id_value_text); + +ALTER TABLE ONLY taxonomie.bdc_statut_taxons + ADD CONSTRAINT bdc_statut_taxons_cd_nom_fkey FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY taxonomie.bdc_statut_taxons + ADD CONSTRAINT bdc_statut_taxons_id_value_text_fkey FOREIGN KEY (id_value_text) REFERENCES taxonomie.bdc_statut_cor_text_values(id_value_text) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/taxonomie/bdc_statut_text.sql b/data/db_state/taxonomie/bdc_statut_text.sql new file mode 100644 index 0000000000..0e7756794a --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_text.sql @@ -0,0 +1,38 @@ + +CREATE TABLE taxonomie.bdc_statut_text ( + id_text integer NOT NULL, + cd_st_text character varying(50), + cd_type_statut character varying(50) NOT NULL, + cd_sig character varying(50), + cd_doc integer, + niveau_admin character varying(250), + cd_iso3166_1 character varying(50), + cd_iso3166_2 character varying(50), + lb_adm_tr character varying(250), + full_citation text, + doc_url text, + enable boolean DEFAULT true +); + +COMMENT ON TABLE taxonomie.bdc_statut_text IS 'Table contenant les textes et leur zone d''application'; + +CREATE SEQUENCE taxonomie.bdc_statut_text_id_text_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bdc_statut_text_id_text_seq OWNED BY taxonomie.bdc_statut_text.id_text; + +ALTER TABLE ONLY taxonomie.bdc_statut_text + ADD CONSTRAINT bdc_statut_text_pkey PRIMARY KEY (id_text); + +CREATE INDEX idx_bstxt_cd_sig ON taxonomie.bdc_statut_text USING btree (cd_sig); + +CREATE INDEX idx_bstxt_cd_type_statut ON taxonomie.bdc_statut_text USING btree (cd_type_statut); + +ALTER TABLE ONLY taxonomie.bdc_statut_text + ADD CONSTRAINT bdc_statut_text_fkey FOREIGN KEY (cd_type_statut) REFERENCES taxonomie.bdc_statut_type(cd_type_statut) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/taxonomie/bdc_statut_type.sql b/data/db_state/taxonomie/bdc_statut_type.sql new file mode 100644 index 0000000000..601960bf99 --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_type.sql @@ -0,0 +1,14 @@ + +CREATE TABLE taxonomie.bdc_statut_type ( + cd_type_statut character varying(50) NOT NULL, + lb_type_statut character varying(250), + regroupement_type character varying(250), + thematique character varying(100), + type_value character varying(100) +); + +COMMENT ON TABLE taxonomie.bdc_statut_type IS 'Table des grands type de statuts'; + +ALTER TABLE ONLY taxonomie.bdc_statut_type + ADD CONSTRAINT bdc_statut_type_pkey PRIMARY KEY (cd_type_statut); + diff --git a/data/db_state/taxonomie/bdc_statut_values.sql b/data/db_state/taxonomie/bdc_statut_values.sql new file mode 100644 index 0000000000..f7a0074a62 --- /dev/null +++ b/data/db_state/taxonomie/bdc_statut_values.sql @@ -0,0 +1,22 @@ + +CREATE TABLE taxonomie.bdc_statut_values ( + id_value integer NOT NULL, + code_statut character varying(50) NOT NULL, + label_statut character varying(250) +); + +COMMENT ON TABLE taxonomie.bdc_statut_values IS 'Table contenant la liste des valeurs possible pour les textes'; + +CREATE SEQUENCE taxonomie.bdc_statut_values_id_value_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bdc_statut_values_id_value_seq OWNED BY taxonomie.bdc_statut_values.id_value; + +ALTER TABLE ONLY taxonomie.bdc_statut_values + ADD CONSTRAINT bdc_statut_values_pkey PRIMARY KEY (id_value); + diff --git a/data/db_state/taxonomie/bib_attributs.sql b/data/db_state/taxonomie/bib_attributs.sql new file mode 100644 index 0000000000..24df751585 --- /dev/null +++ b/data/db_state/taxonomie/bib_attributs.sql @@ -0,0 +1,25 @@ + +CREATE TABLE taxonomie.bib_attributs ( + id_attribut integer DEFAULT nextval('taxonomie.bib_attributs_id_attribut_seq'::regclass) NOT NULL, + nom_attribut character varying(255) NOT NULL, + label_attribut character varying(50) NOT NULL, + liste_valeur_attribut text, + obligatoire boolean DEFAULT false NOT NULL, + desc_attribut text, + type_attribut character varying(50), + type_widget character varying(50), + regne character varying(20), + group2_inpn character varying(255), + id_theme integer NOT NULL, + ordre integer +); + +ALTER TABLE ONLY taxonomie.bib_attributs + ADD CONSTRAINT pk_bib_attributs PRIMARY KEY (id_attribut); + +ALTER TABLE ONLY taxonomie.bib_attributs + ADD CONSTRAINT unique_bib_attributs_nom_attribut UNIQUE (nom_attribut); + +ALTER TABLE ONLY taxonomie.bib_attributs + ADD CONSTRAINT bib_attributs_id_theme_fkey FOREIGN KEY (id_theme) REFERENCES taxonomie.bib_themes(id_theme); + diff --git a/data/db_state/taxonomie/bib_listes.sql b/data/db_state/taxonomie/bib_listes.sql new file mode 100644 index 0000000000..0b223e52cb --- /dev/null +++ b/data/db_state/taxonomie/bib_listes.sql @@ -0,0 +1,28 @@ + +CREATE TABLE taxonomie.bib_listes ( + id_liste integer NOT NULL, + code_liste character varying(50) NOT NULL, + nom_liste character varying(255) NOT NULL, + desc_liste text, + regne character varying(20), + group2_inpn character varying(255) +); + +CREATE SEQUENCE taxonomie.bib_listes_id_liste_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bib_listes_id_liste_seq OWNED BY taxonomie.bib_listes.id_liste; + +ALTER TABLE ONLY taxonomie.bib_listes + ADD CONSTRAINT pk_bib_listes PRIMARY KEY (id_liste); + +ALTER TABLE ONLY taxonomie.bib_listes + ADD CONSTRAINT unique_bib_listes_code_liste UNIQUE (code_liste); + +ALTER TABLE ONLY taxonomie.bib_listes + ADD CONSTRAINT unique_bib_listes_nom_liste UNIQUE (nom_liste); + diff --git a/data/db_state/taxonomie/bib_taxref_habitats.sql b/data/db_state/taxonomie/bib_taxref_habitats.sql new file mode 100644 index 0000000000..83a3562631 --- /dev/null +++ b/data/db_state/taxonomie/bib_taxref_habitats.sql @@ -0,0 +1,10 @@ + +CREATE TABLE taxonomie.bib_taxref_habitats ( + id_habitat integer NOT NULL, + nom_habitat character varying(50) NOT NULL, + desc_habitat text +); + +ALTER TABLE ONLY taxonomie.bib_taxref_habitats + ADD CONSTRAINT pk_bib_taxref_habitats PRIMARY KEY (id_habitat); + diff --git a/data/db_state/taxonomie/bib_taxref_rangs.sql b/data/db_state/taxonomie/bib_taxref_rangs.sql new file mode 100644 index 0000000000..a8449238f3 --- /dev/null +++ b/data/db_state/taxonomie/bib_taxref_rangs.sql @@ -0,0 +1,11 @@ + +CREATE TABLE taxonomie.bib_taxref_rangs ( + id_rang character(4) NOT NULL, + nom_rang character varying(50) NOT NULL, + nom_rang_en character varying(50) NOT NULL, + tri_rang integer +); + +ALTER TABLE ONLY taxonomie.bib_taxref_rangs + ADD CONSTRAINT pk_bib_taxref_rangs PRIMARY KEY (id_rang); + diff --git a/data/db_state/taxonomie/bib_taxref_statuts.sql b/data/db_state/taxonomie/bib_taxref_statuts.sql new file mode 100644 index 0000000000..446a6d7034 --- /dev/null +++ b/data/db_state/taxonomie/bib_taxref_statuts.sql @@ -0,0 +1,9 @@ + +CREATE TABLE taxonomie.bib_taxref_statuts ( + id_statut character(1) NOT NULL, + nom_statut character varying(50) NOT NULL +); + +ALTER TABLE ONLY taxonomie.bib_taxref_statuts + ADD CONSTRAINT pk_bib_taxref_statuts PRIMARY KEY (id_statut); + diff --git a/data/db_state/taxonomie/bib_themes.sql b/data/db_state/taxonomie/bib_themes.sql new file mode 100644 index 0000000000..e12cd8ddf7 --- /dev/null +++ b/data/db_state/taxonomie/bib_themes.sql @@ -0,0 +1,23 @@ + +CREATE TABLE taxonomie.bib_themes ( + id_theme integer NOT NULL, + nom_theme character varying(20), + desc_theme character varying(255), + ordre integer +); + +CREATE SEQUENCE taxonomie.bib_themes_id_theme_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.bib_themes_id_theme_seq OWNED BY taxonomie.bib_themes.id_theme; + +ALTER TABLE ONLY taxonomie.bib_themes + ADD CONSTRAINT bib_themes_pkey PRIMARY KEY (id_theme); + +ALTER TABLE ONLY taxonomie.bib_themes + ADD CONSTRAINT unique_bib_themes_nom_theme UNIQUE (nom_theme); + diff --git a/data/db_state/taxonomie/bib_types_media.sql b/data/db_state/taxonomie/bib_types_media.sql new file mode 100644 index 0000000000..2b50be46a4 --- /dev/null +++ b/data/db_state/taxonomie/bib_types_media.sql @@ -0,0 +1,10 @@ + +CREATE TABLE taxonomie.bib_types_media ( + id_type integer NOT NULL, + nom_type_media character varying(100) NOT NULL, + desc_type_media text +); + +ALTER TABLE ONLY taxonomie.bib_types_media + ADD CONSTRAINT id PRIMARY KEY (id_type); + diff --git a/data/db_state/taxonomie/cor_nom_liste.sql b/data/db_state/taxonomie/cor_nom_liste.sql new file mode 100644 index 0000000000..4e47f33c37 --- /dev/null +++ b/data/db_state/taxonomie/cor_nom_liste.sql @@ -0,0 +1,18 @@ + +CREATE TABLE taxonomie.cor_nom_liste ( + id_liste integer NOT NULL, + cd_nom integer NOT NULL +); + +ALTER TABLE ONLY taxonomie.cor_nom_liste + ADD CONSTRAINT cor_nom_liste_pkey PRIMARY KEY (cd_nom, id_liste); + +ALTER TABLE ONLY taxonomie.cor_nom_liste + ADD CONSTRAINT unique_cor_nom_liste_id_liste_cd_nom UNIQUE (id_liste, cd_nom); + +ALTER TABLE ONLY taxonomie.cor_nom_liste + ADD CONSTRAINT cor_nom_listes_bib_listes_fkey FOREIGN KEY (id_liste) REFERENCES taxonomie.bib_listes(id_liste) ON UPDATE CASCADE; + +ALTER TABLE ONLY taxonomie.cor_nom_liste + ADD CONSTRAINT cor_nom_listes_taxref_fkey FOREIGN KEY (cd_nom) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/taxonomie/cor_taxon_attribut.sql b/data/db_state/taxonomie/cor_taxon_attribut.sql new file mode 100644 index 0000000000..40891a4312 --- /dev/null +++ b/data/db_state/taxonomie/cor_taxon_attribut.sql @@ -0,0 +1,16 @@ + +CREATE TABLE taxonomie.cor_taxon_attribut ( + id_attribut integer NOT NULL, + valeur_attribut text NOT NULL, + cd_ref integer NOT NULL, + CONSTRAINT check_is_cd_ref CHECK ((cd_ref = taxonomie.find_cdref(cd_ref))) +); + +ALTER TABLE ONLY taxonomie.cor_taxon_attribut + ADD CONSTRAINT cor_taxon_attribut_pkey PRIMARY KEY (id_attribut, cd_ref); + +CREATE INDEX fki_cor_taxon_attribut ON taxonomie.cor_taxon_attribut USING btree (valeur_attribut); + +ALTER TABLE ONLY taxonomie.cor_taxon_attribut + ADD CONSTRAINT cor_taxon_attrib_bib_attrib_fkey FOREIGN KEY (id_attribut) REFERENCES taxonomie.bib_attributs(id_attribut); + diff --git a/data/db_state/taxonomie/t_medias.sql b/data/db_state/taxonomie/t_medias.sql new file mode 100644 index 0000000000..6f82577f1b --- /dev/null +++ b/data/db_state/taxonomie/t_medias.sql @@ -0,0 +1,39 @@ + +CREATE TABLE taxonomie.t_medias ( + id_media integer NOT NULL, + cd_ref integer, + titre character varying(255) NOT NULL, + url character varying(255), + chemin character varying(255), + auteur character varying(1000), + desc_media text, + date_media date, + is_public boolean DEFAULT true NOT NULL, + id_type integer NOT NULL, + source character varying(25), + licence character varying(100), + CONSTRAINT check_cd_ref_is_ref CHECK ((cd_ref = taxonomie.find_cdref(cd_ref))) +); + +CREATE SEQUENCE taxonomie.t_medias_id_media_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE taxonomie.t_medias_id_media_seq OWNED BY taxonomie.t_medias.id_media; + +ALTER TABLE ONLY taxonomie.t_medias + ADD CONSTRAINT id_media PRIMARY KEY (id_media); + +CREATE TRIGGER tri_insert_t_medias BEFORE INSERT ON taxonomie.t_medias FOR EACH ROW EXECUTE FUNCTION taxonomie.insert_t_medias(); + +CREATE TRIGGER tri_unique_type1 AFTER INSERT OR UPDATE ON taxonomie.t_medias FOR EACH ROW EXECUTE FUNCTION taxonomie.unique_type1(); + +ALTER TABLE ONLY taxonomie.t_medias + ADD CONSTRAINT fk_t_media_bib_noms FOREIGN KEY (cd_ref) REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE; + +ALTER TABLE ONLY taxonomie.t_medias + ADD CONSTRAINT fk_t_media_bib_types_media FOREIGN KEY (id_type) REFERENCES taxonomie.bib_types_media(id_type) MATCH FULL ON UPDATE CASCADE; + diff --git a/data/db_state/taxonomie/t_meta_taxref.sql b/data/db_state/taxonomie/t_meta_taxref.sql new file mode 100644 index 0000000000..9abfd3cc3a --- /dev/null +++ b/data/db_state/taxonomie/t_meta_taxref.sql @@ -0,0 +1,10 @@ + +CREATE TABLE taxonomie.t_meta_taxref ( + referencial_name character varying NOT NULL, + version integer NOT NULL, + update_date timestamp without time zone DEFAULT now() +); + +ALTER TABLE ONLY taxonomie.t_meta_taxref + ADD CONSTRAINT t_meta_taxref_pkey PRIMARY KEY (referencial_name, version); + diff --git a/data/db_state/taxonomie/taxref.sql b/data/db_state/taxonomie/taxref.sql new file mode 100644 index 0000000000..337ecddec1 --- /dev/null +++ b/data/db_state/taxonomie/taxref.sql @@ -0,0 +1,61 @@ + +CREATE TABLE taxonomie.taxref ( + cd_nom integer NOT NULL, + id_statut character(1), + id_habitat integer, + id_rang character varying(10), + regne character varying(20), + phylum character varying(50), + classe character varying(50), + ordre character varying(50), + famille character varying(50), + sous_famille character varying(50), + tribu character varying(50), + cd_taxsup integer, + cd_sup integer, + cd_ref integer, + lb_nom character varying(250), + lb_auteur character varying(500), + nom_complet character varying(500), + nom_complet_html character varying(500), + nom_valide character varying(500), + nom_vern character varying(1000), + nom_vern_eng character varying(500), + group1_inpn character varying(50), + group2_inpn character varying(50), + url text, + group3_inpn character varying(250) +); + +ALTER TABLE ONLY taxonomie.taxref + ADD CONSTRAINT pk_taxref PRIMARY KEY (cd_nom); + +CREATE INDEX i_fk_taxref_bib_taxref_habitat ON taxonomie.taxref USING btree (id_habitat); + +CREATE INDEX i_fk_taxref_bib_taxref_rangs ON taxonomie.taxref USING btree (id_rang); + +CREATE INDEX i_fk_taxref_bib_taxref_statuts ON taxonomie.taxref USING btree (id_statut); + +CREATE INDEX i_fk_taxref_group1_inpn ON taxonomie.taxref USING btree (group1_inpn); + +CREATE INDEX i_fk_taxref_group2_inpn ON taxonomie.taxref USING btree (group2_inpn); + +CREATE INDEX i_fk_taxref_nom_vern ON taxonomie.taxref USING btree (nom_vern); + +CREATE INDEX i_taxref_cd_ref ON taxonomie.taxref USING btree (cd_ref); + +CREATE INDEX i_taxref_cd_sup ON taxonomie.taxref USING btree (cd_sup); + +CREATE INDEX i_taxref_group3_inpn ON taxonomie.taxref USING btree (group3_inpn); + +CREATE INDEX i_taxref_hierarchy ON taxonomie.taxref USING btree (regne, phylum, classe, ordre, famille); + +ALTER TABLE ONLY taxonomie.taxref + ADD CONSTRAINT fk_taxref_bib_taxref_habitats FOREIGN KEY (id_habitat) REFERENCES taxonomie.bib_taxref_habitats(id_habitat) ON UPDATE CASCADE; + +ALTER TABLE ONLY taxonomie.taxref + ADD CONSTRAINT fk_taxref_bib_taxref_rangs FOREIGN KEY (id_rang) REFERENCES taxonomie.bib_taxref_rangs(id_rang) ON UPDATE CASCADE; + +ALTER TABLE ONLY taxonomie.taxref + ADD CONSTRAINT taxref_id_statut_fkey FOREIGN KEY (id_statut) REFERENCES taxonomie.bib_taxref_statuts(id_statut) ON UPDATE CASCADE; + diff --git a/data/db_state/taxonomie/taxref_changes.sql b/data/db_state/taxonomie/taxref_changes.sql new file mode 100644 index 0000000000..5acfc3ea3d --- /dev/null +++ b/data/db_state/taxonomie/taxref_changes.sql @@ -0,0 +1,14 @@ + +CREATE TABLE taxonomie.taxref_changes ( + cd_nom integer NOT NULL, + num_version_init character varying(5), + num_version_final character varying(5), + champ character varying(50) NOT NULL, + valeur_init character varying(255), + valeur_final character varying(255), + type_change character varying(25) +); + +ALTER TABLE ONLY taxonomie.taxref_changes + ADD CONSTRAINT pk_taxref_changes PRIMARY KEY (cd_nom, champ); + diff --git a/data/db_state/taxonomie/vm_taxref_hierarchie.sql b/data/db_state/taxonomie/vm_taxref_hierarchie.sql new file mode 100644 index 0000000000..b6c5f478e6 --- /dev/null +++ b/data/db_state/taxonomie/vm_taxref_hierarchie.sql @@ -0,0 +1,21 @@ + +CREATE TABLE taxonomie.vm_taxref_hierarchie ( + regne character varying(20), + phylum character varying(50), + classe character varying(50), + ordre character varying(50), + famille character varying(50), + cd_nom integer NOT NULL, + cd_ref integer, + lb_nom character varying(250), + id_rang text, + nb_tx_fm bigint, + nb_tx_or bigint, + nb_tx_cl bigint, + nb_tx_ph bigint, + nb_tx_kd bigint +); + +ALTER TABLE ONLY taxonomie.vm_taxref_hierarchie + ADD CONSTRAINT vm_taxref_hierarchie_pkey PRIMARY KEY (cd_nom); + diff --git a/data/db_state/utilisateurs/bib_organismes.sql b/data/db_state/utilisateurs/bib_organismes.sql new file mode 100644 index 0000000000..2f6f67b8ba --- /dev/null +++ b/data/db_state/utilisateurs/bib_organismes.sql @@ -0,0 +1,36 @@ + +CREATE TABLE utilisateurs.bib_organismes ( + id_organisme integer NOT NULL, + uuid_organisme uuid DEFAULT public.uuid_generate_v4() NOT NULL, + nom_organisme character varying(500) NOT NULL, + adresse_organisme character varying(128), + cp_organisme character varying(5), + ville_organisme character varying(100), + tel_organisme character varying(14), + fax_organisme character varying(14), + email_organisme character varying(100), + url_organisme character varying(255), + url_logo character varying(255), + id_parent integer, + additional_data jsonb DEFAULT '{}'::jsonb +); + +CREATE SEQUENCE utilisateurs.bib_organismes_id_organisme_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.bib_organismes_id_organisme_seq OWNED BY utilisateurs.bib_organismes.id_organisme; + +ALTER TABLE ONLY utilisateurs.bib_organismes + ADD CONSTRAINT bib_organismes_un UNIQUE (uuid_organisme); + +ALTER TABLE ONLY utilisateurs.bib_organismes + ADD CONSTRAINT pk_bib_organismes PRIMARY KEY (id_organisme); + +ALTER TABLE ONLY utilisateurs.bib_organismes + ADD CONSTRAINT fk_bib_organismes_id_parent FOREIGN KEY (id_parent) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + diff --git a/data/db_state/utilisateurs/cor_profil_for_app.sql b/data/db_state/utilisateurs/cor_profil_for_app.sql new file mode 100644 index 0000000000..817865f8e7 --- /dev/null +++ b/data/db_state/utilisateurs/cor_profil_for_app.sql @@ -0,0 +1,17 @@ + +CREATE TABLE utilisateurs.cor_profil_for_app ( + id_profil integer NOT NULL, + id_application integer NOT NULL +); + +COMMENT ON TABLE utilisateurs.cor_profil_for_app IS 'Permet d''attribuer et limiter les profils disponibles pour chacune des applications'; + +ALTER TABLE ONLY utilisateurs.cor_profil_for_app + ADD CONSTRAINT pk_cor_profil_for_app PRIMARY KEY (id_application, id_profil); + +ALTER TABLE ONLY utilisateurs.cor_profil_for_app + ADD CONSTRAINT fk_cor_profil_for_app_id_application FOREIGN KEY (id_application) REFERENCES utilisateurs.t_applications(id_application) ON UPDATE CASCADE; + +ALTER TABLE ONLY utilisateurs.cor_profil_for_app + ADD CONSTRAINT fk_cor_profil_for_app_id_profil FOREIGN KEY (id_profil) REFERENCES utilisateurs.t_profils(id_profil) ON UPDATE CASCADE; + diff --git a/data/db_state/utilisateurs/cor_role_app_profil.sql b/data/db_state/utilisateurs/cor_role_app_profil.sql new file mode 100644 index 0000000000..d061bf765a --- /dev/null +++ b/data/db_state/utilisateurs/cor_role_app_profil.sql @@ -0,0 +1,25 @@ + +CREATE TABLE utilisateurs.cor_role_app_profil ( + id_role integer NOT NULL, + id_application integer NOT NULL, + id_profil integer NOT NULL, + is_default_group_for_app boolean DEFAULT false NOT NULL +); + +COMMENT ON TABLE utilisateurs.cor_role_app_profil IS 'Cette table centrale, permet d''associer des roles à des profils par application'; + +ALTER TABLE utilisateurs.cor_role_app_profil + ADD CONSTRAINT check_is_default_group_for_app_is_grp_and_unique CHECK (utilisateurs.check_is_default_group_for_app_is_grp_and_unique(id_application, id_role, is_default_group_for_app)) NOT VALID; + +ALTER TABLE ONLY utilisateurs.cor_role_app_profil + ADD CONSTRAINT pk_cor_role_app_profil PRIMARY KEY (id_role, id_application, id_profil); + +ALTER TABLE ONLY utilisateurs.cor_role_app_profil + ADD CONSTRAINT fk_cor_role_app_profil_id_application FOREIGN KEY (id_application) REFERENCES utilisateurs.t_applications(id_application) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY utilisateurs.cor_role_app_profil + ADD CONSTRAINT fk_cor_role_app_profil_id_profil FOREIGN KEY (id_profil) REFERENCES utilisateurs.t_profils(id_profil) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY utilisateurs.cor_role_app_profil + ADD CONSTRAINT fk_cor_role_app_profil_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/utilisateurs/cor_role_liste.sql b/data/db_state/utilisateurs/cor_role_liste.sql new file mode 100644 index 0000000000..2418aca994 --- /dev/null +++ b/data/db_state/utilisateurs/cor_role_liste.sql @@ -0,0 +1,17 @@ + +CREATE TABLE utilisateurs.cor_role_liste ( + id_role integer NOT NULL, + id_liste integer NOT NULL +); + +COMMENT ON TABLE utilisateurs.cor_role_liste IS 'Equivalent de l''ancienne cor_role_menu. Permet de créer des listes de roles (observateurs par ex.), sans notion de permission'; + +ALTER TABLE ONLY utilisateurs.cor_role_liste + ADD CONSTRAINT pk_cor_role_liste PRIMARY KEY (id_liste, id_role); + +ALTER TABLE ONLY utilisateurs.cor_role_liste + ADD CONSTRAINT fk_cor_role_liste_id_liste FOREIGN KEY (id_liste) REFERENCES utilisateurs.t_listes(id_liste) ON UPDATE CASCADE; + +ALTER TABLE ONLY utilisateurs.cor_role_liste + ADD CONSTRAINT fk_cor_role_liste_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE; + diff --git a/data/db_state/utilisateurs/cor_role_provider.sql b/data/db_state/utilisateurs/cor_role_provider.sql new file mode 100644 index 0000000000..fad08c3a5a --- /dev/null +++ b/data/db_state/utilisateurs/cor_role_provider.sql @@ -0,0 +1,17 @@ + +CREATE TABLE utilisateurs.cor_role_provider ( + id_role integer NOT NULL, + id_provider integer NOT NULL +); + +COMMENT ON TABLE utilisateurs.cor_role_provider IS 'Table de correpondance entre t_roles et t_providers'; + +ALTER TABLE ONLY utilisateurs.cor_role_provider + ADD CONSTRAINT cor_role_provider_pkey PRIMARY KEY (id_role, id_provider); + +ALTER TABLE ONLY utilisateurs.cor_role_provider + ADD CONSTRAINT cor_role_provider_id_provider_fkey FOREIGN KEY (id_provider) REFERENCES utilisateurs.t_providers(id_provider); + +ALTER TABLE ONLY utilisateurs.cor_role_provider + ADD CONSTRAINT cor_role_provider_id_role_fkey FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role); + diff --git a/data/db_state/utilisateurs/cor_role_token.sql b/data/db_state/utilisateurs/cor_role_token.sql new file mode 100644 index 0000000000..a15ad2b8e4 --- /dev/null +++ b/data/db_state/utilisateurs/cor_role_token.sql @@ -0,0 +1,12 @@ + +CREATE TABLE utilisateurs.cor_role_token ( + id_role integer NOT NULL, + token text +); + +ALTER TABLE ONLY utilisateurs.cor_role_token + ADD CONSTRAINT cor_role_token_pk_id_role PRIMARY KEY (id_role); + +ALTER TABLE ONLY utilisateurs.cor_role_token + ADD CONSTRAINT cor_role_token_fk_id_role FOREIGN KEY (id_role) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/utilisateurs/cor_roles.sql b/data/db_state/utilisateurs/cor_roles.sql new file mode 100644 index 0000000000..8d6ebf9faf --- /dev/null +++ b/data/db_state/utilisateurs/cor_roles.sql @@ -0,0 +1,15 @@ + +CREATE TABLE utilisateurs.cor_roles ( + id_role_groupe integer NOT NULL, + id_role_utilisateur integer NOT NULL +); + +ALTER TABLE ONLY utilisateurs.cor_roles + ADD CONSTRAINT cor_roles_pkey PRIMARY KEY (id_role_groupe, id_role_utilisateur); + +ALTER TABLE ONLY utilisateurs.cor_roles + ADD CONSTRAINT cor_roles_id_role_groupe_fkey FOREIGN KEY (id_role_groupe) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY utilisateurs.cor_roles + ADD CONSTRAINT cor_roles_id_role_utilisateur_fkey FOREIGN KEY (id_role_utilisateur) REFERENCES utilisateurs.t_roles(id_role) ON UPDATE CASCADE ON DELETE CASCADE; + diff --git a/data/db_state/utilisateurs/t_applications.sql b/data/db_state/utilisateurs/t_applications.sql new file mode 100644 index 0000000000..26002d62a8 --- /dev/null +++ b/data/db_state/utilisateurs/t_applications.sql @@ -0,0 +1,24 @@ + +CREATE TABLE utilisateurs.t_applications ( + id_application integer NOT NULL, + code_application character varying(20) NOT NULL, + nom_application character varying(50) NOT NULL, + desc_application text, + id_parent integer +); + +CREATE SEQUENCE utilisateurs.t_applications_id_application_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.t_applications_id_application_seq OWNED BY utilisateurs.t_applications.id_application; + +ALTER TABLE ONLY utilisateurs.t_applications + ADD CONSTRAINT pk_t_applications PRIMARY KEY (id_application); + +ALTER TABLE ONLY utilisateurs.t_applications + ADD CONSTRAINT fk_t_applications_id_parent FOREIGN KEY (id_parent) REFERENCES utilisateurs.t_applications(id_application) ON UPDATE CASCADE; + diff --git a/data/db_state/utilisateurs/t_listes.sql b/data/db_state/utilisateurs/t_listes.sql new file mode 100644 index 0000000000..2cec569776 --- /dev/null +++ b/data/db_state/utilisateurs/t_listes.sql @@ -0,0 +1,23 @@ + +CREATE TABLE utilisateurs.t_listes ( + id_liste integer NOT NULL, + code_liste character varying(20) NOT NULL, + nom_liste character varying(50) NOT NULL, + desc_liste text +); + +COMMENT ON TABLE utilisateurs.t_listes IS 'Table des listes déroulantes des applications. Les roles (groupes ou utilisateurs) devant figurer dans une liste sont gérés dans la table cor_role_liste'; + +CREATE SEQUENCE utilisateurs.t_listes_id_liste_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.t_listes_id_liste_seq OWNED BY utilisateurs.t_listes.id_liste; + +ALTER TABLE ONLY utilisateurs.t_listes + ADD CONSTRAINT pk_t_listes PRIMARY KEY (id_liste); + diff --git a/data/db_state/utilisateurs/t_profils.sql b/data/db_state/utilisateurs/t_profils.sql new file mode 100644 index 0000000000..0c7b193671 --- /dev/null +++ b/data/db_state/utilisateurs/t_profils.sql @@ -0,0 +1,23 @@ + +CREATE TABLE utilisateurs.t_profils ( + id_profil integer NOT NULL, + code_profil integer, + nom_profil character varying(255), + desc_profil text +); + +COMMENT ON TABLE utilisateurs.t_profils IS 'Table des profils d''utilisateurs génériques ou applicatifs, qui seront ensuite attachés à des roles et des applications'; + +CREATE SEQUENCE utilisateurs.t_profils_id_profil_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.t_profils_id_profil_seq OWNED BY utilisateurs.t_profils.id_profil; + +ALTER TABLE ONLY utilisateurs.t_profils + ADD CONSTRAINT pk_t_profils PRIMARY KEY (id_profil); + diff --git a/data/db_state/utilisateurs/t_providers.sql b/data/db_state/utilisateurs/t_providers.sql new file mode 100644 index 0000000000..a38edc6b06 --- /dev/null +++ b/data/db_state/utilisateurs/t_providers.sql @@ -0,0 +1,24 @@ + +CREATE TABLE utilisateurs.t_providers ( + id_provider integer NOT NULL, + name character varying NOT NULL, + url character varying +); + +COMMENT ON COLUMN utilisateurs.t_providers.name IS 'Nom de l''instance du provider'; + +COMMENT ON COLUMN utilisateurs.t_providers.url IS 'L''url du fournisseur d''authentification'; + +CREATE SEQUENCE utilisateurs.t_providers_id_provider_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.t_providers_id_provider_seq OWNED BY utilisateurs.t_providers.id_provider; + +ALTER TABLE ONLY utilisateurs.t_providers + ADD CONSTRAINT t_providers_pkey PRIMARY KEY (id_provider); + diff --git a/data/db_state/utilisateurs/t_roles.sql b/data/db_state/utilisateurs/t_roles.sql new file mode 100644 index 0000000000..e9df0ef9d5 --- /dev/null +++ b/data/db_state/utilisateurs/t_roles.sql @@ -0,0 +1,49 @@ + +CREATE TABLE utilisateurs.t_roles ( + groupe boolean DEFAULT false NOT NULL, + id_role integer NOT NULL, + uuid_role uuid DEFAULT public.uuid_generate_v4() NOT NULL, + identifiant character varying(100), + nom_role character varying(50), + prenom_role character varying(50), + desc_role text, + pass character varying(100), + pass_plus text, + email character varying(250), + id_organisme integer, + remarques text, + active boolean DEFAULT true, + champs_addi jsonb, + date_insert timestamp without time zone, + date_update timestamp without time zone +); + +CREATE SEQUENCE utilisateurs.t_roles_id_role_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.t_roles_id_role_seq OWNED BY utilisateurs.t_roles.id_role; + +ALTER TABLE ONLY utilisateurs.t_roles + ADD CONSTRAINT pk_t_roles PRIMARY KEY (id_role); + +ALTER TABLE ONLY utilisateurs.t_roles + ADD CONSTRAINT t_roles_uuid_un UNIQUE (uuid_role); + +CREATE INDEX i_utilisateurs_active ON utilisateurs.t_roles USING btree (active); + +CREATE INDEX i_utilisateurs_groupe ON utilisateurs.t_roles USING btree (groupe); + +CREATE INDEX i_utilisateurs_nom_prenom ON utilisateurs.t_roles USING btree (nom_role, prenom_role); + +CREATE TRIGGER tri_modify_date_insert_t_roles BEFORE INSERT ON utilisateurs.t_roles FOR EACH ROW EXECUTE FUNCTION utilisateurs.modify_date_insert(); + +CREATE TRIGGER tri_modify_date_update_t_roles BEFORE UPDATE ON utilisateurs.t_roles FOR EACH ROW EXECUTE FUNCTION utilisateurs.modify_date_update(); + +ALTER TABLE ONLY utilisateurs.t_roles + ADD CONSTRAINT t_roles_id_organisme_fkey FOREIGN KEY (id_organisme) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE; + diff --git a/data/db_state/utilisateurs/temp_users.sql b/data/db_state/utilisateurs/temp_users.sql new file mode 100644 index 0000000000..a69b3afdcc --- /dev/null +++ b/data/db_state/utilisateurs/temp_users.sql @@ -0,0 +1,43 @@ + +CREATE TABLE utilisateurs.temp_users ( + id_temp_user integer NOT NULL, + token_role text, + organisme character varying(250), + id_application integer NOT NULL, + confirmation_url character varying(250), + groupe boolean DEFAULT false NOT NULL, + identifiant character varying(100), + nom_role character varying(50), + prenom_role character varying(50), + desc_role text, + pass_md5 text, + password text, + email character varying(250), + id_organisme integer, + remarques text, + champs_addi jsonb, + date_insert timestamp without time zone, + date_update timestamp without time zone +); + +CREATE SEQUENCE utilisateurs.temp_users_id_temp_user_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE utilisateurs.temp_users_id_temp_user_seq OWNED BY utilisateurs.temp_users.id_temp_user; + +ALTER TABLE ONLY utilisateurs.temp_users + ADD CONSTRAINT pk_temp_users PRIMARY KEY (id_temp_user); + +CREATE TRIGGER tri_modify_date_insert_temp_roles BEFORE INSERT ON utilisateurs.temp_users FOR EACH ROW EXECUTE FUNCTION utilisateurs.modify_date_insert(); + +ALTER TABLE ONLY utilisateurs.temp_users + ADD CONSTRAINT temp_user_id_application_fkey FOREIGN KEY (id_organisme) REFERENCES utilisateurs.bib_organismes(id_organisme) ON UPDATE CASCADE ON DELETE CASCADE; + +ALTER TABLE ONLY utilisateurs.temp_users + ADD CONSTRAINT temp_user_id_organisme_fkey FOREIGN KEY (id_application) REFERENCES utilisateurs.t_applications(id_application) ON UPDATE CASCADE ON DELETE CASCADE; +