63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
"""add_manufacturers_table
|
|
|
|
Revision ID: a192abbf4091
|
|
Revises: 627d4460a94f
|
|
Create Date: 2026-06-25 10:32:11.398529
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "a192abbf4091"
|
|
down_revision: str | None = "627d4460a94f"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table(
|
|
"manufacturers",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(), nullable=False),
|
|
sa.Column("url", sa.String(), nullable=False),
|
|
sa.Column("logo_url", sa.String(), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
# batch_alter_table's alter_column doesn't emit CREATE TYPE for the new
|
|
# Enum on its own (unlike create_table, which ties enum creation to the
|
|
# table-create DDL event) - create it explicitly first, or Postgres fails
|
|
# with `type "uncseries" does not exist`. checkfirst / no-op on SQLite.
|
|
uncseries = sa.Enum("UNC", "UNF", "UNEF", "UN", "UNS", name="uncseries")
|
|
uncseries.create(op.get_bind(), checkfirst=True)
|
|
with op.batch_alter_table("unc_threads", schema=None) as batch_op:
|
|
batch_op.alter_column(
|
|
"series",
|
|
existing_type=sa.VARCHAR(length=8),
|
|
type_=uncseries,
|
|
existing_nullable=False,
|
|
postgresql_using="series::uncseries",
|
|
)
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table("unc_threads", schema=None) as batch_op:
|
|
batch_op.alter_column(
|
|
"series",
|
|
existing_type=sa.Enum("UNC", "UNF", "UNEF", "UN", "UNS", name="uncseries"),
|
|
type_=sa.VARCHAR(length=8),
|
|
existing_nullable=False,
|
|
postgresql_using="series::varchar(8)",
|
|
)
|
|
sa.Enum(name="uncseries").drop(op.get_bind(), checkfirst=True)
|
|
|
|
op.drop_table("manufacturers")
|
|
# ### end Alembic commands ###
|