Skip to content

Commit

Permalink
Save only bib_liste
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl authored and TheoLechemia committed Nov 10, 2023
1 parent d695db5 commit 72a74df
Showing 1 changed file with 0 additions and 82 deletions.
82 changes: 0 additions & 82 deletions apptax/migrations/versions/633e0ad4c4e3_save_bib_nom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,72 +35,6 @@ def upgrade():
FROM taxonomie.bib_noms AS bn ;
"""
)
# Création des attributs nom_vern et comments qui contiendrons les données contenues dans la table bib_nom
op.execute(
"""
INSERT INTO taxonomie.bib_themes (nom_theme, desc_theme, ordre)
VALUES(
'Save bib_nom',
'Thème contenant les attributs correspondants aux données de la table bib_noms',
100
);
INSERT INTO taxonomie.bib_attributs
(nom_attribut, label_attribut, liste_valeur_attribut, desc_attribut, type_attribut, type_widget, regne, group2_inpn, id_theme, ordre)
SELECT
'bib_nom_comments',
'Champ comments de la table bib_noms',
'{}',
'Champ comments de la table bib_noms',
'text',
'text',
NULL,
NULL,
id_theme,
1
FROM taxonomie.bib_themes
WHERE nom_theme = 'Save bib_nom';
INSERT INTO taxonomie.bib_attributs
(nom_attribut, label_attribut, liste_valeur_attribut, desc_attribut, type_attribut, type_widget, regne, group2_inpn, id_theme, ordre)
SELECT
'bib_nom_francais',
'Champ nom français de la table bib_noms',
'{}',
'Champ nom français de la table bib_noms',
'text',
'text',
NULL,
NULL,
id_theme,
1
FROM taxonomie.bib_themes
WHERE nom_theme = 'Save bib_nom';
INSERT INTO taxonomie.cor_taxon_attribut (id_attribut, valeur_attribut, cd_ref)
SELECT
(SELECT id_attribut FROM taxonomie.bib_attributs WHERE nom_attribut = 'bib_nom_francais' LIMIT 1),
string_agg(DISTINCT nom_francais, ',') ,
t.cd_ref
FROM taxonomie.bib_noms AS bn
JOIN taxonomie.taxref AS t
ON t.cd_nom = bn.cd_nom
WHERE NOT nom_francais IS NULL AND NOT nom_francais = ''
GROUP BY t.cd_ref;
INSERT INTO taxonomie.cor_taxon_attribut (id_attribut, valeur_attribut, cd_ref)
SELECT
(SELECT id_attribut FROM taxonomie.bib_attributs WHERE nom_attribut = 'bib_nom_comments' LIMIT 1),
string_agg(DISTINCT comments, ',') ,
t.cd_ref
FROM taxonomie.bib_noms AS bn
JOIN taxonomie.taxref AS t
ON t.cd_nom = bn.cd_nom
WHERE NOT comments IS NULL AND NOT COMMENTS = ''
GROUP BY t.cd_ref;
"""
)


def downgrade():
Expand All @@ -111,19 +45,3 @@ def downgrade():
DELETE FROM taxonomie.bib_listes WHERE code_liste ='BIB_NOM';
"""
)
op.execute(
"""
DELETE FROM taxonomie.cor_taxon_attribut
WHERE id_attribut IN (
SELECT id_attribut
FROM taxonomie.bib_attributs
WHERE nom_attribut IN ( 'bib_nom_comments' , 'bib_nom_francais')
);
DELETE FROM taxonomie.bib_attributs
WHERE nom_attribut IN ( 'bib_nom_comments' , 'bib_nom_francais');
DELETE FROM taxonomie.bib_attributs
WHERE nom_attribut IN ( 'bib_nom_comments' , 'bib_nom_francais');
DELETE FROM taxonomie.bib_themes
WHERE nom_theme = 'Save bib_nom';
"""
)

0 comments on commit 72a74df

Please sign in to comment.