Skip to content

Commit

Permalink
feat(db) : update revision by including bib_fields and cor_field_enti…
Browse files Browse the repository at this point in the history
…ty required changes
  • Loading branch information
jacquesfize committed Oct 30, 2024
1 parent 8d28804 commit 2a759ff
Showing 1 changed file with 50 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,34 @@ def upgrade():

# GET required nomenclature id and occhab destination id
session = Session(bind=op.get_bind())

id_default_type_mosaique_habitat = session.scalar(
sa.select(TNomenclatures.id_nomenclature).where(
TNomenclatures.mnemonique == "Mosaïque mixte"
)
)
Destination = sa.Table("bib_destinations", metadata, schema="gn_imports", autoload_with=conn)
destination = sa.Table("bib_destinations", metadata, schema="gn_imports", autoload_with=conn)
entity = sa.Table("bib_entities", metadata, autoload=True, schema="gn_imports")
theme = sa.Table("bib_themes", metadata, autoload=True, schema="gn_imports")
station = sa.Table("t_stations", metadata, schema="pr_occhab", autoload_with=conn)
cor_entity_field = sa.Table("cor_entity_field", metadata, autoload=True, schema="gn_imports")

id_theme_general = session.execute(
sa.select(theme.c.id_theme).where(theme.c.name_theme == "general_info")
).scalar()
id_destination_occhab = session.scalar(
sa.select(Destination.c.id_destination).where(Destination.c.code == "occhab")
sa.select(destination.c.id_destination).where(destination.c.code == "occhab")
)
id_entity_station = session.execute(
sa.select(entity.c.id_entity).where(entity.c.code == "station")
).scalar()

session.close()

# UPDATE Station table
Station = sa.Table("t_stations", metadata, schema="pr_occhab", autoload_with=conn)

op.execute(
sa.update(Station)
sa.update(station)
.where(sa.text("pr_occhab.t_stations.is_habitat_complex = true"))
.values(id_nomenclature_type_mosaique_habitat=id_default_type_mosaique_habitat)
)
Expand Down Expand Up @@ -84,19 +96,41 @@ def upgrade():
op.drop_column("t_imports_occhab", "is_habitat_complex", schema="gn_imports")

# UPDATE BibFields
BibFields = sa.Table("bib_fields", metadata, schema="gn_imports", autoload_with=conn)
op.execute(sa.delete(BibFields).where(BibFields.c.name_field == "is_habitat_complex"))
bib_fields = sa.Table("bib_fields", metadata, schema="gn_imports", autoload_with=conn)
op.execute(sa.delete(bib_fields).where(bib_fields.c.name_field == "is_habitat_complex"))
id_new_field = (
op.get_bind()
.execute(
sa.insert(bib_fields)
.values(
name_field="id_nomenclature_type_mosaique_habitat",
fr_label="Mosaïque d'habitat",
source_field="src_id_nomenclature_type_mosaique_habitat",
dest_field="id_nomenclature_type_mosaique_habitat",
mandatory=False,
mnemonique="MOSAIQUE_HAB",
autogenerated=False,
display=True,
id_destination=id_destination_occhab,
)
.returning(bib_fields.c.id_field)
)
.scalar()
)

op.execute(
sa.insert(BibFields).values(
name_field="id_nomenclature_type_mosaique_habitat",
fr_label="Mosaïque d'habitat",
source_field="src_id_nomenclature_type_mosaique_habitat",
dest_field="id_nomenclature_type_mosaique_habitat",
mandatory=False,
mnemonique="MOSAIQUE_HAB",
autogenerated=False,
display=True,
id_destination=id_destination_occhab,
sa.insert(cor_entity_field).values(
id_entity=id_entity_station,
id_field=id_new_field,
id_theme=id_theme_general,
comment="Correspondance champs standard: mosaiqueValue",
order_field=op.get_bind()
.execute(
sa.select(sa.func.max(cor_entity_field.c.order_field) + 1).select_from(
cor_entity_field
)
)
.scalar(),
)
)

Expand Down

0 comments on commit 2a759ff

Please sign in to comment.