feat: Add combined track functionality with repository and service layers
- Introduced CombinedTrackModel, CombinedTrackCreate, and CombinedTrackRepository for managing combined tracks. - Implemented logic to create combined tracks based on existing tracks between two stations. - Added methods to check for existing combined tracks and retrieve constituent track IDs. - Enhanced TrackModel and TrackRepository to support OSM ID and track updates. - Created migration scripts for adding combined tracks table and OSM ID to tracks. - Updated services and API endpoints to handle combined track operations. - Added tests for combined track creation, repository methods, and API interactions.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
"""Template for new Alembic migration scripts."""
|
||||
|
||||
from __future__ import annotations
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from geoalchemy2.types import Geometry
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = 'e7d4bb03da04'
|
||||
down_revision = '63d02d67b39e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"combined_tracks",
|
||||
sa.Column(
|
||||
"id",
|
||||
postgresql.UUID(as_uuid=True),
|
||||
primary_key=True,
|
||||
server_default=sa.text("gen_random_uuid()"),
|
||||
),
|
||||
sa.Column("name", sa.String(length=128), nullable=True),
|
||||
sa.Column("start_station_id", postgresql.UUID(
|
||||
as_uuid=True), nullable=False),
|
||||
sa.Column("end_station_id", postgresql.UUID(
|
||||
as_uuid=True), nullable=False),
|
||||
sa.Column("length_meters", sa.Numeric(10, 2), nullable=True),
|
||||
sa.Column("max_speed_kph", sa.Integer(), nullable=True),
|
||||
sa.Column(
|
||||
"is_bidirectional",
|
||||
sa.Boolean(),
|
||||
nullable=False,
|
||||
server_default=sa.text("true"),
|
||||
),
|
||||
sa.Column(
|
||||
"status", sa.String(length=32), nullable=False, server_default="planned"
|
||||
),
|
||||
sa.Column(
|
||||
"combined_geometry",
|
||||
Geometry(geometry_type="LINESTRING", srid=4326),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("constituent_track_ids", sa.Text(), nullable=False),
|
||||
sa.Column(
|
||||
"created_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.text("timezone('utc', now())"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column(
|
||||
"updated_at",
|
||||
sa.DateTime(timezone=True),
|
||||
server_default=sa.text("timezone('utc', now())"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["start_station_id"], ["stations.id"], ondelete="RESTRICT"
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
["end_station_id"], ["stations.id"], ondelete="RESTRICT"
|
||||
),
|
||||
sa.UniqueConstraint(
|
||||
"start_station_id", "end_station_id", name="uq_combined_tracks_station_pair"
|
||||
),
|
||||
)
|
||||
op.create_index(
|
||||
"ix_combined_tracks_geometry", "combined_tracks", ["combined_geometry"], postgresql_using="gist"
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_combined_tracks_geometry", table_name="combined_tracks")
|
||||
op.drop_table("combined_tracks")
|
||||
Reference in New Issue
Block a user