Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changement de is_habitat_complex #3125

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/requirements-dependencies.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pypnusershub>=3.0.0,<4
pypnnomenclature>=1.6.3,<2
pypnnomenclature>=1.6.4,<2
pypn_habref_api>=0.4.1,<1
utils-flask-sqlalchemy-geo>=0.3.2,<1
utils-flask-sqlalchemy>=0.4.1,<1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""replace_is_complex_with_habitat_complexity

Revision ID: c1a6b0793360
Revises: 295861464d84
Create Date: 2024-07-18 15:52:38.695575

"""

from alembic import op
from pypnnomenclature.models import TNomenclatures
import sqlalchemy as sa
from sqlalchemy.orm.session import Session


# revision identifiers, used by Alembic.
revision = "c1a6b0793360"
down_revision = "295861464d84"
branch_labels = None
depends_on = None


def upgrade():

conn = op.get_bind()
metadata = sa.MetaData(bind=conn)
Station = sa.Table("t_stations", metadata, schema="pr_occhab", autoload_with=conn)

op.add_column(
"t_stations",
sa.Column(
"id_nomenclature_type_mosaique_habitat",
sa.Integer(),
sa.ForeignKey("ref_nomenclatures.t_nomenclatures.id_nomenclature"),
nullable=True,
),
schema="pr_occhab",
)
session = Session(bind=op.get_bind())
id_default_type_mosaique_habitat = session.scalar(
sa.select(TNomenclatures.id_nomenclature).where(
TNomenclatures.mnemonique == "Mosaïque mixte"
)
)
session.close()
op.execute(
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)
)
op.drop_column("t_stations", "is_habitat_complex", schema="pr_occhab")
op.execute(
"""
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
"""
)


def downgrade():
op.drop_constraint("check_t_stations_type_mosaique_habitat", "t_stations", schema="pr_occhab")
op.drop_column("t_stations", "id_nomenclature_type_mosaique_habitat", schema="pr_occhab")
op.add_column(
"t_stations",
sa.Column("is_habitat_complex", sa.Boolean(), nullable=True),
schema="pr_occhab",
)
10 changes: 9 additions & 1 deletion contrib/gn_module_occhab/backend/gn_module_occhab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ class Station(NomenclaturesMixin, db.Model):
date_max = db.Column(db.DateTime, server_default=FetchedValue())
observers_txt = db.Column(db.Unicode(length=500))
station_name = db.Column(db.Unicode(length=1000))
is_habitat_complex = db.Column(db.Boolean)
# is_habitat_complex = db.Column(db.Boolean)
id_nomenclature_type_mosaique_habitat = db.Column(
db.Integer,
ForeignKey(Nomenclature.id_nomenclature),
)
type_mosaique_habitat = db.relationship(
Nomenclature,
foreign_keys=[id_nomenclature_type_mosaique_habitat],
)
altitude_min = db.Column(db.Integer)
altitude_max = db.Column(db.Integer)
depth_min = db.Column(db.Integer)
Expand Down
Loading