Files
HOAPro/backend/backend/alembic/versions/b2d22e13e06c_initial_tables.py
2025-07-31 11:27:50 -04:00

109 lines
4.7 KiB
Python

"""Initial tables
Revision ID: b2d22e13e06c
Revises:
Create Date: 2025-07-10 10:17:44.144159
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'b2d22e13e06c'
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('buckets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_index(op.f('ix_buckets_id'), 'buckets', ['id'], unique=False)
op.create_table('roles',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.Enum('admin', 'user', name='roleenum'), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_index(op.f('ix_roles_id'), 'roles', ['id'], unique=False)
op.create_table('accounts',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('bucket_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(), nullable=False),
sa.Column('type', sa.Enum('checking', 'savings', 'cd', 'tbill', 'other', name='accounttypeenum'), nullable=False),
sa.Column('interest_rate', sa.Float(), nullable=True),
sa.Column('maturity_date', sa.DateTime(), nullable=True),
sa.Column('balance', sa.Float(), nullable=True),
sa.Column('last_validated_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['bucket_id'], ['buckets.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_accounts_id'), 'accounts', ['id'], unique=False)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('password_hash', sa.String(), nullable=False),
sa.Column('role_id', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
op.create_table('cash_flows',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('account_id', sa.Integer(), nullable=True),
sa.Column('type', sa.Enum('inflow', 'outflow', name='cashflowtypeenum'), nullable=False),
sa.Column('estimate_actual', sa.Boolean(), nullable=True),
sa.Column('amount', sa.Float(), nullable=False),
sa.Column('date', sa.DateTime(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_cash_flows_id'), 'cash_flows', ['id'], unique=False)
op.create_table('transactions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('account_id', sa.Integer(), nullable=True),
sa.Column('type', sa.Enum('deposit', 'withdrawal', 'transfer', name='transactiontypeenum'), nullable=False),
sa.Column('amount', sa.Float(), nullable=False),
sa.Column('date', sa.DateTime(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('related_account_id', sa.Integer(), nullable=True),
sa.Column('reconciled', sa.Boolean(), nullable=False, server_default=sa.false()),
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ),
sa.ForeignKeyConstraint(['related_account_id'], ['accounts.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_transactions_id'), 'transactions', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_transactions_id'), table_name='transactions')
op.drop_table('transactions')
op.drop_index(op.f('ix_cash_flows_id'), table_name='cash_flows')
op.drop_table('cash_flows')
op.drop_index(op.f('ix_users_username'), table_name='users')
op.drop_index(op.f('ix_users_id'), table_name='users')
op.drop_table('users')
op.drop_index(op.f('ix_accounts_id'), table_name='accounts')
op.drop_table('accounts')
op.drop_index(op.f('ix_roles_id'), table_name='roles')
op.drop_table('roles')
op.drop_index(op.f('ix_buckets_id'), table_name='buckets')
op.drop_table('buckets')
# ### end Alembic commands ###