"""Add hierarchical locations. Revision ID: e5f6g7h8i9j0 Revises: d4e5f6g7h8i9 Create Date: 2025-01-21 01:00:00.000000 """ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. revision = "e5f6g7h8i9j0" down_revision = "d4e5f6g7h8i9" branch_labels = None depends_on = None def upgrade() -> None: """Create location table and add location_id to spool.""" # Create location table op.create_table( "location", sa.Column("id", sa.Integer(), nullable=False), sa.Column("name", sa.String(length=64), nullable=False), sa.Column("parent_id", sa.Integer(), nullable=True), sa.Column("location_type", sa.String(length=32), nullable=True), sa.Column("description", sa.String(length=256), nullable=True), sa.ForeignKeyConstraint( ["parent_id"], ["location.id"], ondelete="SET NULL", ), sa.PrimaryKeyConstraint("id"), ) op.create_index(op.f("ix_location_id"), "location", ["id"], unique=False) op.create_index(op.f("ix_location_parent_id"), "location", ["parent_id"], unique=False) # Add location_id column to spool table (SQLite compatible - no FK constraint) op.add_column( "spool", sa.Column("location_id", sa.Integer(), nullable=True), ) op.create_index(op.f("ix_spool_location_id"), "spool", ["location_id"], unique=False) def downgrade() -> None: """Drop location table and remove location_id from spool.""" op.drop_index(op.f("ix_spool_location_id"), table_name="spool") op.drop_column("spool", "location_id") op.drop_index(op.f("ix_location_parent_id"), table_name="location") op.drop_index(op.f("ix_location_id"), table_name="location") op.drop_table("location")