diff --git a/MuoVErsi/sources/base.py b/MuoVErsi/sources/base.py index 15ddce6..d8962a1 100644 --- a/MuoVErsi/sources/base.py +++ b/MuoVErsi/sources/base.py @@ -370,7 +370,7 @@ class Trip(Base): __tablename__ = 'trips' id: Mapped[int] = mapped_column(primary_key=True) - orig_id: Mapped[Optional[str]] + orig_id: Mapped[str] dest_text: Mapped[str] number: Mapped[int] orig_dep_date: Mapped[date] diff --git a/alembic/versions/1f2c7b1eec8b_add_source_field_to_trips.py b/alembic/versions/1f2c7b1eec8b_add_source_field_to_trips.py index d657cfc..d95580c 100644 --- a/alembic/versions/1f2c7b1eec8b_add_source_field_to_trips.py +++ b/alembic/versions/1f2c7b1eec8b_add_source_field_to_trips.py @@ -18,9 +18,6 @@ def upgrade() -> None: op.add_column('trips', sa.Column('source', sa.String(), server_default='treni', nullable=False)) - op.alter_column('trips', 'orig_id', - existing_type=sa.VARCHAR(), - nullable=True) op.drop_constraint('trains_codOrigine_numeroTreno_dataPartenzaTreno_key', 'trips', type_='unique') # update foreign key of stop_times.trip_id to cascade on delete @@ -30,16 +27,13 @@ def upgrade() -> None: # remove duplicates of source, number, orig_dep_date from trips table op.execute('DELETE FROM trips WHERE id IN (SELECT id FROM (SELECT id, ROW_NUMBER() OVER (partition BY source, number, orig_dep_date ORDER BY id) AS rnum FROM trips) t WHERE t.rnum > 1);') - op.create_unique_constraint(None, 'trips', ['source', 'number', 'orig_dep_date']) + op.create_unique_constraint('trips_source_number_orig_dep_date_key', 'trips', ['source', 'number', 'orig_dep_date']) def downgrade() -> None: - op.drop_constraint(None, 'trips', type_='unique') + op.drop_constraint('trips_source_number_orig_dep_date_key', 'trips', type_='unique') op.create_unique_constraint('trains_codOrigine_numeroTreno_dataPartenzaTreno_key', 'trips', ['orig_id', 'number', 'orig_dep_date']) - op.alter_column('trips', 'orig_id', - existing_type=sa.VARCHAR(), - nullable=False) op.drop_column('trips', 'source') op.drop_constraint('stop_times_trip_id_fkey', 'stop_times', type_='foreignkey') op.create_foreign_key('stop_times_train_id_fkey', 'stop_times', 'trips', ['trip_id'], ['id'])