178 lines
7.9 KiB
Python
178 lines
7.9 KiB
Python
"""initial schema
|
|
|
|
Revision ID: b2b1f5a18a74
|
|
Revises:
|
|
Create Date: 2026-07-17 17:08:30.212347
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'b2b1f5a18a74'
|
|
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('accounts',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('bank', sa.String(length=50), nullable=False),
|
|
sa.Column('iban', sa.String(length=34), nullable=False),
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
|
sa.Column('type', sa.String(length=20), nullable=False),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('iban')
|
|
)
|
|
op.create_table('categories',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=100), nullable=False),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('name')
|
|
)
|
|
op.create_table('loans',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('principal', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.Column('annual_rate_pct', sa.Numeric(precision=5, scale=2), nullable=False),
|
|
sa.Column('term_months', sa.Integer(), nullable=False),
|
|
sa.Column('payout_date', sa.Date(), nullable=False),
|
|
sa.Column('repayment_type', sa.String(length=20), nullable=False),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('scenarios',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('description', sa.Text(), nullable=False),
|
|
sa.Column('include_recurring', sa.Boolean(), nullable=False),
|
|
sa.Column('include_planned', sa.Boolean(), nullable=False),
|
|
sa.PrimaryKeyConstraint('id'),
|
|
sa.UniqueConstraint('name')
|
|
)
|
|
op.create_table('category_rules',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('pattern', sa.String(length=200), nullable=False),
|
|
sa.Column('category_id', sa.Integer(), nullable=False),
|
|
sa.Column('priority', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('planned_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.Column('due', sa.Date(), nullable=False),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('projection_points',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('scenario_id', sa.Integer(), nullable=False),
|
|
sa.Column('day', sa.Date(), nullable=False),
|
|
sa.Column('balance', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.ForeignKeyConstraint(['scenario_id'], ['scenarios.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_projection_points_scenario_id'), 'projection_points', ['scenario_id'], unique=False)
|
|
op.create_table('projection_results',
|
|
sa.Column('scenario_id', sa.Integer(), nullable=False),
|
|
sa.Column('computed_at', sa.DateTime(), nullable=False),
|
|
sa.Column('low_point_date', sa.Date(), nullable=False),
|
|
sa.Column('low_point_balance', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.Column('below_zero_date', sa.Date(), nullable=True),
|
|
sa.Column('below_threshold_date', sa.Date(), nullable=True),
|
|
sa.ForeignKeyConstraint(['scenario_id'], ['scenarios.id'], ),
|
|
sa.PrimaryKeyConstraint('scenario_id')
|
|
)
|
|
op.create_table('recurring_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(length=200), nullable=False),
|
|
sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.Column('rhythm', sa.String(length=20), nullable=False),
|
|
sa.Column('due_day', sa.Integer(), nullable=False),
|
|
sa.Column('start_date', sa.Date(), nullable=True),
|
|
sa.Column('end_date', sa.Date(), nullable=True),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('scenario_loans',
|
|
sa.Column('scenario_id', sa.Integer(), nullable=False),
|
|
sa.Column('loan_id', sa.Integer(), nullable=False),
|
|
sa.ForeignKeyConstraint(['loan_id'], ['loans.id'], ),
|
|
sa.ForeignKeyConstraint(['scenario_id'], ['scenarios.id'], ),
|
|
sa.PrimaryKeyConstraint('scenario_id', 'loan_id')
|
|
)
|
|
op.create_table('scenario_modifiers',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('scenario_id', sa.Integer(), nullable=False),
|
|
sa.Column('target_type', sa.String(length=20), nullable=False),
|
|
sa.Column('target_id', sa.Integer(), nullable=False),
|
|
sa.Column('kind', sa.String(length=20), nullable=False),
|
|
sa.Column('value', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.ForeignKeyConstraint(['scenario_id'], ['scenarios.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('statements',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('filename', sa.String(length=255), nullable=False),
|
|
sa.Column('bank', sa.String(length=50), nullable=False),
|
|
sa.Column('account_id', sa.Integer(), nullable=True),
|
|
sa.Column('period_start', sa.Date(), nullable=True),
|
|
sa.Column('period_end', sa.Date(), nullable=True),
|
|
sa.Column('opening_balance', sa.Numeric(precision=12, scale=2), nullable=True),
|
|
sa.Column('closing_balance', sa.Numeric(precision=12, scale=2), nullable=True),
|
|
sa.Column('status', sa.String(length=20), nullable=False),
|
|
sa.Column('error_message', sa.Text(), nullable=True),
|
|
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_table('transactions',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('account_id', sa.Integer(), nullable=False),
|
|
sa.Column('statement_id', sa.Integer(), nullable=True),
|
|
sa.Column('booking_date', sa.Date(), nullable=False),
|
|
sa.Column('value_date', sa.Date(), nullable=True),
|
|
sa.Column('amount', sa.Numeric(precision=12, scale=2), nullable=False),
|
|
sa.Column('purpose', sa.Text(), nullable=False),
|
|
sa.Column('counterparty', sa.String(length=200), nullable=False),
|
|
sa.Column('category_id', sa.Integer(), nullable=True),
|
|
sa.Column('status', sa.String(length=20), nullable=False),
|
|
sa.Column('dedup_hash', sa.String(length=64), nullable=False),
|
|
sa.Column('is_duplicate', sa.Boolean(), nullable=False),
|
|
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
|
|
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], ),
|
|
sa.ForeignKeyConstraint(['statement_id'], ['statements.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_transactions_dedup_hash'), 'transactions', ['dedup_hash'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index(op.f('ix_transactions_dedup_hash'), table_name='transactions')
|
|
op.drop_table('transactions')
|
|
op.drop_table('statements')
|
|
op.drop_table('scenario_modifiers')
|
|
op.drop_table('scenario_loans')
|
|
op.drop_table('recurring_items')
|
|
op.drop_table('projection_results')
|
|
op.drop_index(op.f('ix_projection_points_scenario_id'), table_name='projection_points')
|
|
op.drop_table('projection_points')
|
|
op.drop_table('planned_items')
|
|
op.drop_table('category_rules')
|
|
op.drop_table('scenarios')
|
|
op.drop_table('loans')
|
|
op.drop_table('categories')
|
|
op.drop_table('accounts')
|
|
# ### end Alembic commands ###
|