Skip to content

Commit

Permalink
upgrade :Suppression IF EXISTS et downgrade : rajout des contraintes
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Dec 19, 2022
1 parent cf44ca6 commit fb775ab
Showing 1 changed file with 69 additions and 34 deletions.
103 changes: 69 additions & 34 deletions apptax/migrations/versions/188bc535258a_drop_old_status_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,69 @@
def upgrade():
op.execute(
"""
DROP TABLE IF EXISTS taxonomie.taxref_liste_rouge_fr;
DROP TABLE IF EXISTS taxonomie.bib_taxref_categories_lr;
DROP TABLE IF EXISTS taxonomie.taxref_protection_especes;
DROP TABLE IF EXISTS taxonomie.taxref_protection_articles_structure;
DROP TABLE IF EXISTS taxonomie.taxref_protection_articles;
DROP TABLE taxonomie.taxref_liste_rouge_fr;
DROP TABLE taxonomie.bib_taxref_categories_lr;
DROP TABLE taxonomie.taxref_protection_especes;
DROP TABLE taxonomie.taxref_protection_articles_structure;
DROP TABLE taxonomie.taxref_protection_articles;
"""
)


def downgrade():
"""
Create LR table
Create LR constraints
Create taxref protection tables
Create taxref protection constraints
"""
op.execute(
"""
CREATE TABLE taxonomie.bib_taxref_categories_lr
(
id_categorie_france character(2) NOT NULL,
categorie_lr character varying(50) NOT NULL,
nom_categorie_lr character varying(255) NOT NULL,
desc_categorie_lr character varying(255)
);
CREATE TABLE taxonomie.taxref_liste_rouge_fr
(
id_lr serial NOT NULL,
ordre_statut integer,
vide character varying(255),
cd_nom integer,
cd_ref integer,
nomcite character varying(255),
nom_scientifique character varying(255),
auteur character varying(255),
nom_vernaculaire character varying(255),
nom_commun character varying(255),
rang character(4),
famille character varying(50),
endemisme character varying(255),
population character varying(255),
commentaire text,
id_categorie_france character(2) NOT NULL,
criteres_france character varying(255),
liste_rouge character varying(255),
fiche_espece character varying(255),
tendance character varying(255),
liste_rouge_source character varying(255),
annee_publication integer,
categorie_lr_europe character varying(2),
categorie_lr_mondiale character varying(5)
id_lr serial NOT NULL,
ordre_statut integer,
vide character varying(255),
cd_nom integer,
cd_ref integer,
nomcite character varying(255),
nom_scientifique character varying(255),
auteur character varying(255),
nom_vernaculaire character varying(255),
nom_commun character varying(255),
rang character(4),
famille character varying(50),
endemisme character varying(255),
population character varying(255),
commentaire text,
id_categorie_france character(2) NOT NULL,
criteres_france character varying(255),
liste_rouge character varying(255),
fiche_espece character varying(255),
tendance character varying(255),
liste_rouge_source character varying(255),
annee_publication integer,
categorie_lr_europe character varying(2),
categorie_lr_mondiale character varying(5)
);
ALTER TABLE ONLY taxonomie.bib_taxref_categories_lr
ADD CONSTRAINT pk_bib_taxref_id_categorie_france PRIMARY KEY (id_categorie_france);
ALTER TABLE ONLY taxonomie.taxref_liste_rouge_fr
ADD CONSTRAINT pk_taxref_liste_rouge_fr PRIMARY KEY (id_lr);
ALTER TABLE ONLY taxonomie.taxref_liste_rouge_fr
ADD CONSTRAINT fk_taxref_lr_bib_taxref_categories FOREIGN KEY (id_categorie_france) REFERENCES taxonomie.bib_taxref_categories_lr (id_categorie_france) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE NO ACTION;
CREATE TABLE taxonomie.taxref_protection_articles (
cd_protection character varying(20) NOT NULL,
cd_protection character varying(20) PRIMARY KEY ,
article character varying(100),
intitule text,
arrete text,
Expand All @@ -80,13 +101,27 @@ def downgrade():
syn_cite character varying(200),
nom_francais_cite character varying(100),
precisions text,
cd_nom_cite character varying(255) NOT NULL
cd_nom_cite character varying(255) NOT NULL,
PRIMARY KEY (cd_nom, cd_protection, cd_nom_cite)
);
CREATE TABLE taxonomie.taxref_protection_articles_structure (
cd_protection character varying(50) NOT NULL,
alias_statut character varying(10),
concerne_structure boolean
cd_protection character varying(50) NOT NULL PRIMARY KEY,
alias_statut character varying(10),
concerne_structure boolean
);
ALTER TABLE ONLY taxonomie.taxref_protection_especes
ADD CONSTRAINT taxref_protection_especes_cd_nom_fkey FOREIGN KEY (cd_nom)
REFERENCES taxonomie.taxref(cd_nom) ON UPDATE CASCADE;
ALTER TABLE ONLY taxonomie.taxref_protection_especes
ADD CONSTRAINT taxref_protection_especes_cd_protection_fkey FOREIGN KEY (cd_protection)
REFERENCES taxonomie.taxref_protection_articles(cd_protection);
ALTER TABLE ONLY taxonomie.taxref_protection_articles_structure
ADD CONSTRAINT taxref_protection_articles_structure_cd_protect_fkey FOREIGN KEY (cd_protection)
REFERENCES taxonomie.taxref_protection_articles(cd_protection);
CREATE INDEX fki_cd_nom_taxref_protection_especes ON taxonomie.taxref_protection_especes USING btree (cd_nom);
"""
)

0 comments on commit fb775ab

Please sign in to comment.