first commit
This commit is contained in:
49
alembic/versions/202605110002_car_catalog.py
Normal file
49
alembic/versions/202605110002_car_catalog.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""car catalog
|
||||
|
||||
Revision ID: 202605110002
|
||||
Revises: 202605110001
|
||||
Create Date: 2026-05-11
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision: str = "202605110002"
|
||||
down_revision: str | None = "202605110001"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"car_makes",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=80), nullable=False),
|
||||
sa.Column("country", sa.String(length=80), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(op.f("ix_car_makes_name"), "car_makes", ["name"], unique=True)
|
||||
|
||||
op.create_table(
|
||||
"car_models",
|
||||
sa.Column("id", sa.Integer(), nullable=False),
|
||||
sa.Column("make_id", sa.Integer(), nullable=False),
|
||||
sa.Column("name", sa.String(length=100), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
|
||||
sa.ForeignKeyConstraint(["make_id"], ["car_makes.id"], ondelete="CASCADE"),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
sa.UniqueConstraint("make_id", "name", name="uq_car_models_make_name"),
|
||||
)
|
||||
op.create_index(op.f("ix_car_models_make_id"), "car_models", ["make_id"], unique=False)
|
||||
op.create_index(op.f("ix_car_models_name"), "car_models", ["name"], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f("ix_car_models_name"), table_name="car_models")
|
||||
op.drop_index(op.f("ix_car_models_make_id"), table_name="car_models")
|
||||
op.drop_table("car_models")
|
||||
op.drop_index(op.f("ix_car_makes_name"), table_name="car_makes")
|
||||
op.drop_table("car_makes")
|
||||
Reference in New Issue
Block a user