Skip to content

Commit

Permalink
modify Alembic migration for fct metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ejamet73 committed Oct 18, 2024
1 parent 9fb7613 commit c5a707e
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

0 comments on commit c5a707e

Please sign in to comment.