Track sold cars
This commit is contained in:
31
alembic/versions/005_add_car_seen_sold_timestamps.py
Normal file
31
alembic/versions/005_add_car_seen_sold_timestamps.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "005_add_car_seen_sold_timestamps"
|
||||
down_revision: Union[str, None] = "004_add_ingestion_tables"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"MOBILEDE_cars",
|
||||
sa.Column("first_seen_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.add_column(
|
||||
"MOBILEDE_cars",
|
||||
sa.Column("sold_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.execute('UPDATE "MOBILEDE_cars" SET first_seen_at = last_seen_at WHERE first_seen_at IS NULL')
|
||||
op.alter_column("MOBILEDE_cars", "first_seen_at", nullable=False)
|
||||
op.create_index("ix_MOBILEDE_cars_first_seen_at", "MOBILEDE_cars", ["first_seen_at"])
|
||||
op.create_index("ix_MOBILEDE_cars_sold_at", "MOBILEDE_cars", ["sold_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_MOBILEDE_cars_sold_at", table_name="MOBILEDE_cars")
|
||||
op.drop_index("ix_MOBILEDE_cars_first_seen_at", table_name="MOBILEDE_cars")
|
||||
op.drop_column("MOBILEDE_cars", "sold_at")
|
||||
op.drop_column("MOBILEDE_cars", "first_seen_at")
|
||||
Reference in New Issue
Block a user