97 lines
4.0 KiB
Python
97 lines
4.0 KiB
Python
|
|
"""V1 baseline
|
||
|
|
|
||
|
|
Revision ID: 57af90893f55
|
||
|
|
Revises:
|
||
|
|
Create Date: 2026-06-01 13:49:15.867487
|
||
|
|
|
||
|
|
"""
|
||
|
|
from typing import Sequence, Union
|
||
|
|
|
||
|
|
from alembic import op
|
||
|
|
import sqlalchemy as sa
|
||
|
|
|
||
|
|
|
||
|
|
# revision identifiers, used by Alembic.
|
||
|
|
revision: str = '57af90893f55'
|
||
|
|
down_revision: Union[str, Sequence[str], None] = None
|
||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
||
|
|
|
||
|
|
|
||
|
|
def upgrade() -> None:
|
||
|
|
"""Upgrade schema."""
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
op.create_table('boxes',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
||
|
|
sa.Column('note', sa.Text(), nullable=True),
|
||
|
|
sa.Column('room', sa.String(length=100), nullable=True),
|
||
|
|
sa.Column('status', sa.String(length=50), nullable=True),
|
||
|
|
sa.Column('image_blob', sa.LargeBinary(), nullable=True),
|
||
|
|
sa.Column('image_mime_type', sa.String(length=50), nullable=True),
|
||
|
|
sa.Column('image_width', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('image_height', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('boxes', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_boxes_id'), ['id'], unique=False)
|
||
|
|
|
||
|
|
op.create_table('items',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('box_id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
||
|
|
sa.Column('note', sa.Text(), nullable=True),
|
||
|
|
sa.Column('quantity', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('is_container', sa.Boolean(), nullable=False),
|
||
|
|
sa.Column('image_blob', sa.LargeBinary(), nullable=True),
|
||
|
|
sa.Column('image_mime_type', sa.String(length=50), nullable=True),
|
||
|
|
sa.Column('image_width', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('image_height', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(['box_id'], ['boxes.id'], ondelete='CASCADE'),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('items', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_items_id'), ['id'], unique=False)
|
||
|
|
|
||
|
|
op.create_table('subitems',
|
||
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('parent_item_id', sa.Integer(), nullable=False),
|
||
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
||
|
|
sa.Column('note', sa.Text(), nullable=True),
|
||
|
|
sa.Column('quantity', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('image_blob', sa.LargeBinary(), nullable=True),
|
||
|
|
sa.Column('image_mime_type', sa.String(length=50), nullable=True),
|
||
|
|
sa.Column('image_width', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('image_height', sa.Integer(), nullable=True),
|
||
|
|
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
|
||
|
|
sa.ForeignKeyConstraint(['parent_item_id'], ['items.id'], ondelete='CASCADE'),
|
||
|
|
sa.PrimaryKeyConstraint('id')
|
||
|
|
)
|
||
|
|
with op.batch_alter_table('subitems', schema=None) as batch_op:
|
||
|
|
batch_op.create_index(batch_op.f('ix_subitems_id'), ['id'], unique=False)
|
||
|
|
|
||
|
|
# ### end Alembic commands ###
|
||
|
|
|
||
|
|
|
||
|
|
def downgrade() -> None:
|
||
|
|
"""Downgrade schema."""
|
||
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
||
|
|
with op.batch_alter_table('subitems', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_subitems_id'))
|
||
|
|
|
||
|
|
op.drop_table('subitems')
|
||
|
|
with op.batch_alter_table('items', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_items_id'))
|
||
|
|
|
||
|
|
op.drop_table('items')
|
||
|
|
with op.batch_alter_table('boxes', schema=None) as batch_op:
|
||
|
|
batch_op.drop_index(batch_op.f('ix_boxes_id'))
|
||
|
|
|
||
|
|
op.drop_table('boxes')
|
||
|
|
# ### end Alembic commands ###
|