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

Metrics processing #212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 44 additions & 0 deletions backend/alembic/versions/c32d65d6e6fd_create_fct_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""create fct metrics

Revision ID: c32d65d6e6fd
Revises: 06bb3c26076f
Create Date: 2024-10-18 11:13:02.468934

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import Inspector
import geoalchemy2

# revision identifiers, used by Alembic.
revision = 'c32d65d6e6fd'
down_revision = '06bb3c26076f'
branch_labels = None
depends_on = None


def upgrade() -> None:

# 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:
# 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)
Loading