From 2b5f26f6f9673ae92c8cf8b87c87fe2e2d94e663 Mon Sep 17 00:00:00 2001 From: JulienCorny <40057801+JulienCorny@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:18:17 +0100 Subject: [PATCH] feat(monitoring, db): add id_import column for each entity in monitoring model (#3275) * add id_import in monitoring model * feat: add id_import columns in monitoring tables * fix(db): change head of revision to latest in feat/import-monitorings --------- Co-authored-by: Julien Corny Co-authored-by: jacquesfize --- .../geonature/core/gn_monitoring/models.py | 5 +++ ...da_add_id_import_column_for_each_entity.py | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 backend/geonature/migrations/versions/df277299fdda_add_id_import_column_for_each_entity.py diff --git a/backend/geonature/core/gn_monitoring/models.py b/backend/geonature/core/gn_monitoring/models.py index 6ba3a45ca7..6c2669da8d 100644 --- a/backend/geonature/core/gn_monitoring/models.py +++ b/backend/geonature/core/gn_monitoring/models.py @@ -169,6 +169,8 @@ class TBaseVisits(DB.Model): foreign_keys=[id_dataset], ) + id_import = DB.Column(DB.Integer, nullable=True) + @serializable @geoserializable(geoCol="geom", idCol="id_base_site") @@ -212,6 +214,8 @@ class TBaseSites(DB.Model): foreign_keys=[cor_site_module.c.id_base_site, cor_site_module.c.id_module], ) + id_import = DB.Column(DB.Integer, nullable=True) + @serializable class TObservations(DB.Model): @@ -226,3 +230,4 @@ class TObservations(DB.Model): cd_nom = DB.Column(DB.Integer) comments = DB.Column(DB.String) uuid_observation = DB.Column(UUID(as_uuid=True), default=select(func.uuid_generate_v4())) + id_import = DB.Column(DB.Integer, nullable=True) diff --git a/backend/geonature/migrations/versions/df277299fdda_add_id_import_column_for_each_entity.py b/backend/geonature/migrations/versions/df277299fdda_add_id_import_column_for_each_entity.py new file mode 100644 index 0000000000..9d9c6e0b4e --- /dev/null +++ b/backend/geonature/migrations/versions/df277299fdda_add_id_import_column_for_each_entity.py @@ -0,0 +1,39 @@ +"""[monitoring] add id_import column for each entity + +Revision ID: df277299fdda +Revises: 6734d8f7eb2a +Create Date: 2024-11-28 18:20:49.512808 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "df277299fdda" +down_revision = "a94bea44ab56" +branch_labels = None +depends_on = None + +import_column_name = "id_import" +schema = "gn_monitoring" +entity_tables = ["t_base_sites", "t_base_visits", "t_observations"] + + +def upgrade(): + for table in entity_tables: + op.add_column( + schema=schema, + table_name=table, + column=sa.Column(import_column_name, sa.Integer, nullable=True), + ) + + +def downgrade(): + for table in entity_tables: + op.drop_column( + schema=schema, + table_name=table, + column_name=import_column_name, + )