From c5a707e72abc7803d6380f1e6eb80fbf45c8871a Mon Sep 17 00:00:00 2001 From: Ewen Date: Fri, 18 Oct 2024 23:01:03 +0200 Subject: [PATCH] modify Alembic migration for fct metrics --- .../c32d65d6e6fd_create_fct_metrics.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py b/backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py index 8f32de50..743c408d 100644 --- a/backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py +++ b/backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py @@ -7,7 +7,8 @@ """ from alembic import op import sqlalchemy as sa - +from sqlalchemy import Inspector +import geoalchemy2 # revision identifiers, used by Alembic. revision = 'c32d65d6e6fd' @@ -17,8 +18,27 @@ def upgrade() -> None: - pass + + # Création de la table fct_metrics + op.create_table( + 'fct_metrics', + sa.Column('timestamp', sa.DateTime, primary_key=True), #granule + sa.Column('vessel_id', sa.Integer, nullable=False), #vessel id + sa.Column('type', sa.String, nullable=False), #in_mpa or at_sea + sa.Column('duration_total', sa.DateTime, nullable=False), #time spent at sea at timestamp + sa.Column('duration_fishing', sa.DateTime, nullable=True), #time spent fishing + sa.Column("mpa_name", sa.String, nullable=True), # if type is in_mpa, write here the mpa name + ) def downgrade() -> None: - pass + # Suppression de la table fct_metrics en cas de rollback + conn = op.get_bind() + inspector = Inspector.from_engine(conn) + sql_tables = inspector.get_table_names() + tables = [ + "fct_metrics", + ] + for t in tables: + if t in sql_tables: + op.drop_table(t) \ No newline at end of file