Files
KSP_project/migrations/versions/6c2a57f2b1e9_add_asset_log_tables.py
T
2026-05-08 15:16:04 +08:00

71 lines
3.0 KiB
Python

"""add asset log tables
Revision ID: 6c2a57f2b1e9
Revises: 83be4d38636d
Create Date: 2026-04-24 09:40:00.000000
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '6c2a57f2b1e9'
down_revision = '83be4d38636d'
branch_labels = None
depends_on = None
def upgrade():
op.create_table(
'assets',
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('asset_type', sa.String(length=120), nullable=False),
sa.Column('program', sa.String(length=255), nullable=True),
sa.Column('home_region', sa.String(length=120), nullable=True),
sa.Column('note', sa.Text(), 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'),
sa.UniqueConstraint('name'),
)
with op.batch_alter_table('assets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_assets_asset_type'), ['asset_type'], unique=False)
batch_op.create_index(batch_op.f('ix_assets_name'), ['name'], unique=False)
op.create_table(
'asset_log_entries',
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('asset_id', sa.Uuid(), nullable=False),
sa.Column('entry_kind', sa.String(length=16), nullable=False),
sa.Column('title', sa.String(length=255), nullable=False),
sa.Column('state_label', sa.String(length=120), nullable=True),
sa.Column('mission_label', sa.String(length=255), nullable=True),
sa.Column('location', sa.String(length=255), nullable=True),
sa.Column('start_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('end_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('summary', sa.Text(), nullable=True),
sa.Column('note', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['asset_id'], ['assets.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
)
with op.batch_alter_table('asset_log_entries', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_asset_log_entries_asset_id'), ['asset_id'], unique=False)
batch_op.create_index(batch_op.f('ix_asset_log_entries_start_at'), ['start_at'], unique=False)
def downgrade():
with op.batch_alter_table('asset_log_entries', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_asset_log_entries_start_at'))
batch_op.drop_index(batch_op.f('ix_asset_log_entries_asset_id'))
op.drop_table('asset_log_entries')
with op.batch_alter_table('assets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_assets_name'))
batch_op.drop_index(batch_op.f('ix_assets_asset_type'))
op.drop_table('assets')