Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
57 lines
2.5 KiB
Python
57 lines
2.5 KiB
Python
"""szenario zeitraum, neuer betrag, szenario-eigene wiederkehrende zahlungen
|
|
|
|
Revision ID: e7f1a9c3b214
|
|
Revises: d5e8b3c7a410
|
|
Create Date: 2026-09-30
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = 'e7f1a9c3b214'
|
|
down_revision: Union[str, Sequence[str], None] = 'd5e8b3c7a410'
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
FK_PLANNED_CATEGORY = 'fk_scenario_planned_items_category_id'
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Bestandsdaten: percent/absolute/remove haben end_date NULL (API hat es
|
|
# bisher genullt) und gelten damit unverändert unbegrenzt.
|
|
op.add_column('scenario_modifiers', sa.Column('start_date', sa.Date(), nullable=True))
|
|
# Batch-Modus: SQLite kennt kein ALTER von Constraints (Tabelle wird neu
|
|
# angelegt); auf Postgres entspricht das den direkten ALTER-Befehlen.
|
|
with op.batch_alter_table('scenario_planned_items') as batch:
|
|
batch.add_column(sa.Column('category_id', sa.Integer(), nullable=True))
|
|
batch.create_foreign_key(FK_PLANNED_CATEGORY, 'categories',
|
|
['category_id'], ['id'])
|
|
op.create_table(
|
|
'scenario_recurring_items',
|
|
sa.Column('id', sa.Integer(), primary_key=True),
|
|
sa.Column('scenario_id', sa.Integer(), sa.ForeignKey('scenarios.id'), 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(), sa.ForeignKey('categories.id'), nullable=True),
|
|
)
|
|
op.create_index('ix_scenario_recurring_items_scenario_id',
|
|
'scenario_recurring_items', ['scenario_id'])
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Alte Semantik: "set" gab es nicht, end_date nur bei "ende".
|
|
op.execute("DELETE FROM scenario_modifiers WHERE kind = 'set'")
|
|
op.execute("UPDATE scenario_modifiers SET end_date = NULL WHERE kind <> 'ende'")
|
|
op.drop_index('ix_scenario_recurring_items_scenario_id', 'scenario_recurring_items')
|
|
op.drop_table('scenario_recurring_items')
|
|
with op.batch_alter_table('scenario_planned_items') as batch:
|
|
batch.drop_column('category_id')
|
|
op.drop_column('scenario_modifiers', 'start_date')
|