quartermaster/alembic/versions/f1ccdc4bc1bf_initial_schema.py

56 lines
2.2 KiB
Python
Raw Normal View History

"""initial schema
Revision ID: f1ccdc4bc1bf
Revises:
Create Date: 2026-04-17 10:59:39.959411
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'f1ccdc4bc1bf'
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('entry',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('section', sa.Enum('income', 'fixed_bill', 'debt_minimum', 'food', 'subscription', 'other', name='section', native_enum=False, length=32), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('amount', sa.Numeric(precision=10, scale=2), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('id')
)
with op.batch_alter_table('entry', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_entry_section'), ['section'], unique=False)
op.create_table('debt_target',
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('debt_minimum_id', sa.Integer(), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.CheckConstraint('id = 1', name='debt_target_singleton'),
sa.ForeignKeyConstraint(['debt_minimum_id'], ['entry.id'], ondelete='SET NULL'),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('debt_target')
with op.batch_alter_table('entry', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_entry_section'))
op.drop_table('entry')
# ### end Alembic commands ###