-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a script to dump each table creation script + make a first dump
- Loading branch information
1 parent
30195be
commit 724d290
Showing
170 changed files
with
5,396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
Oops, something went wrong.