Add road_usage table
This commit is contained in:
parent
f3a1ca4165
commit
5a5948b653
|
@ -0,0 +1,34 @@
|
||||||
|
"""create road_usage table
|
||||||
|
|
||||||
|
Revision ID: a9627f63fbed
|
||||||
|
Revises:
|
||||||
|
Create Date: 2022-03-16 20:26:17.449569
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy import Column, Integer, String, ForeignKey, Index, DateTime, Boolean
|
||||||
|
from sqlalchemy.types import BIGINT
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = "a9627f63fbed"
|
||||||
|
down_revision = None
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
op.create_table(
|
||||||
|
"road_usage",
|
||||||
|
Column("id", Integer, autoincrement=True, primary_key=True, index=True),
|
||||||
|
Column("track_id", Integer, ForeignKey("track.id", ondelete="CASCADE")),
|
||||||
|
Column("hex_hash", String, unique=True, index=True),
|
||||||
|
Column("way_id", BIGINT, index=True),
|
||||||
|
Column("time", DateTime),
|
||||||
|
Column("direction_reversed", Boolean),
|
||||||
|
Index("road_usage_segment", "way_id", "direction_reversed"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
op.drop_table("road_usage")
|
|
@ -68,7 +68,9 @@ def random_string(length):
|
||||||
async def connect_db(url, pool_size=10, max_overflow=20):
|
async def connect_db(url, pool_size=10, max_overflow=20):
|
||||||
global engine, sessionmaker
|
global engine, sessionmaker
|
||||||
|
|
||||||
engine = create_async_engine(url, echo=False, pool_size=pool_size, max_overflow=max_overflow)
|
engine = create_async_engine(
|
||||||
|
url, echo=False, pool_size=pool_size, max_overflow=max_overflow
|
||||||
|
)
|
||||||
sessionmaker = SessionMaker(engine, class_=AsyncSession, expire_on_commit=False)
|
sessionmaker = SessionMaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||||
|
|
||||||
yield engine
|
yield engine
|
||||||
|
@ -143,11 +145,28 @@ class Road(Base):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class RoadUsage(Base):
|
||||||
|
__tablename__ = "road_usage"
|
||||||
|
__table_args__ = (Index("road_segment", "way_id", "direction_reversed"),)
|
||||||
|
|
||||||
|
id = Column(Integer, autoincrement=True, primary_key=True, index=True)
|
||||||
|
track_id = Column(Integer, ForeignKey("track.id", ondelete="CASCADE"))
|
||||||
|
hex_hash = Column(String, unique=True, index=True)
|
||||||
|
way_id = Column(BIGINT, index=True)
|
||||||
|
time = Column(DateTime)
|
||||||
|
direction_reversed = Column(Boolean)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<RoadUsage {self.id}>"
|
||||||
|
|
||||||
|
|
||||||
NOW = text("NOW()")
|
NOW = text("NOW()")
|
||||||
|
|
||||||
|
|
||||||
class DuplicateTrackFileError(ValueError):
|
class DuplicateTrackFileError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Track(Base):
|
class Track(Base):
|
||||||
__tablename__ = "track"
|
__tablename__ = "track"
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
|
Loading…
Reference in a new issue