111 lines
6.1 KiB
Python
111 lines
6.1 KiB
Python
"""vehicle service profile
|
|
|
|
Revision ID: 202605120003
|
|
Revises: 202605120002
|
|
Create Date: 2026-05-12
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from alembic import op
|
|
|
|
revision: str = "202605120003"
|
|
down_revision: str | None = "202605120002"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.add_column("cars", sa.Column("target_consumption_l_per_100km", sa.Numeric(6, 2), nullable=True))
|
|
op.add_column("cars", sa.Column("fuel_tank_volume_l", sa.Numeric(6, 2), nullable=True))
|
|
op.add_column("cars", sa.Column("engine_oil_type", sa.String(length=80), nullable=True))
|
|
op.add_column("cars", sa.Column("engine_oil_volume_l", sa.Numeric(5, 2), nullable=True))
|
|
op.add_column("cars", sa.Column("transmission_fluid_type", sa.String(length=80), nullable=True))
|
|
op.add_column("cars", sa.Column("transmission_fluid_volume_l", sa.Numeric(5, 2), nullable=True))
|
|
op.add_column("cars", sa.Column("coolant_type", sa.String(length=80), nullable=True))
|
|
op.add_column("cars", sa.Column("brake_fluid_type", sa.String(length=80), nullable=True))
|
|
op.add_column("cars", sa.Column("tire_pressure_front_bar", sa.Numeric(4, 2), nullable=True))
|
|
op.add_column("cars", sa.Column("tire_pressure_rear_bar", sa.Numeric(4, 2), nullable=True))
|
|
|
|
op.create_table(
|
|
"service_centers",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(length=160), nullable=False),
|
|
sa.Column("telegram_chat_id", sa.String(length=80), nullable=True),
|
|
sa.Column("contact_phone", sa.String(length=40), nullable=True),
|
|
sa.Column("address", sa.String(length=240), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("name"),
|
|
sa.UniqueConstraint("telegram_chat_id"),
|
|
)
|
|
op.create_index(op.f("ix_service_centers_name"), "service_centers", ["name"])
|
|
op.create_index(op.f("ix_service_centers_telegram_chat_id"), "service_centers", ["telegram_chat_id"])
|
|
|
|
op.create_table(
|
|
"car_service_links",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("car_id", sa.Integer(), nullable=False),
|
|
sa.Column("service_center_id", sa.Integer(), nullable=False),
|
|
sa.Column("external_vehicle_ref", sa.String(length=120), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["car_id"], ["cars.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["service_center_id"], ["service_centers.id"], ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("car_id", "service_center_id", name="uq_car_service_link"),
|
|
)
|
|
op.create_index(op.f("ix_car_service_links_car_id"), "car_service_links", ["car_id"])
|
|
op.create_index(op.f("ix_car_service_links_external_vehicle_ref"), "car_service_links", ["external_vehicle_ref"])
|
|
op.create_index(op.f("ix_car_service_links_service_center_id"), "car_service_links", ["service_center_id"])
|
|
|
|
op.create_table(
|
|
"service_inbox_messages",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("service_center_id", sa.Integer(), nullable=True),
|
|
sa.Column("car_id", sa.Integer(), nullable=True),
|
|
sa.Column("source_chat_id", sa.String(length=80), nullable=True),
|
|
sa.Column("raw_text", sa.Text(), nullable=False),
|
|
sa.Column("parsed_status", sa.String(length=32), nullable=False, server_default="pending"),
|
|
sa.Column("parsed_payload", sa.Text(), nullable=True),
|
|
sa.Column("error", sa.Text(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
|
sa.ForeignKeyConstraint(["car_id"], ["cars.id"], ondelete="SET NULL"),
|
|
sa.ForeignKeyConstraint(["service_center_id"], ["service_centers.id"], ondelete="SET NULL"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_service_inbox_messages_car_id"), "service_inbox_messages", ["car_id"])
|
|
op.create_index(op.f("ix_service_inbox_messages_parsed_status"), "service_inbox_messages", ["parsed_status"])
|
|
op.create_index(op.f("ix_service_inbox_messages_service_center_id"), "service_inbox_messages", ["service_center_id"])
|
|
op.create_index(op.f("ix_service_inbox_messages_source_chat_id"), "service_inbox_messages", ["source_chat_id"])
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_service_inbox_messages_source_chat_id"), table_name="service_inbox_messages")
|
|
op.drop_index(op.f("ix_service_inbox_messages_service_center_id"), table_name="service_inbox_messages")
|
|
op.drop_index(op.f("ix_service_inbox_messages_parsed_status"), table_name="service_inbox_messages")
|
|
op.drop_index(op.f("ix_service_inbox_messages_car_id"), table_name="service_inbox_messages")
|
|
op.drop_table("service_inbox_messages")
|
|
|
|
op.drop_index(op.f("ix_car_service_links_service_center_id"), table_name="car_service_links")
|
|
op.drop_index(op.f("ix_car_service_links_external_vehicle_ref"), table_name="car_service_links")
|
|
op.drop_index(op.f("ix_car_service_links_car_id"), table_name="car_service_links")
|
|
op.drop_table("car_service_links")
|
|
|
|
op.drop_index(op.f("ix_service_centers_telegram_chat_id"), table_name="service_centers")
|
|
op.drop_index(op.f("ix_service_centers_name"), table_name="service_centers")
|
|
op.drop_table("service_centers")
|
|
|
|
op.drop_column("cars", "tire_pressure_rear_bar")
|
|
op.drop_column("cars", "tire_pressure_front_bar")
|
|
op.drop_column("cars", "brake_fluid_type")
|
|
op.drop_column("cars", "coolant_type")
|
|
op.drop_column("cars", "transmission_fluid_volume_l")
|
|
op.drop_column("cars", "transmission_fluid_type")
|
|
op.drop_column("cars", "engine_oil_volume_l")
|
|
op.drop_column("cars", "engine_oil_type")
|
|
op.drop_column("cars", "fuel_tank_volume_l")
|
|
op.drop_column("cars", "target_consumption_l_per_100km")
|