state defaults to 'planning' (server default plus SQLAlchemy default). activated_at and closed_at are nullable timestamps that record when the month crossed each boundary. Alembic batch_alter_table handles the SQLite rewrite. MonthState is a Python string enum mapped to a non-native VARCHAR(16). Refs #15 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""add month lifecycle state
|
|
|
|
Revision ID: a4ec4f8f6e9f
|
|
Revises: ec804bdf366d
|
|
Create Date: 2026-04-17 12:59:25.811354
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = 'a4ec4f8f6e9f'
|
|
down_revision: Union[str, Sequence[str], None] = 'ec804bdf366d'
|
|
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! ###
|
|
with op.batch_alter_table('month', schema=None) as batch_op:
|
|
batch_op.add_column(sa.Column('state', sa.Enum('planning', 'active', 'closed', name='monthstate', native_enum=False, length=16), server_default='planning', nullable=False))
|
|
batch_op.add_column(sa.Column('activated_at', sa.DateTime(timezone=True), nullable=True))
|
|
batch_op.add_column(sa.Column('closed_at', sa.DateTime(timezone=True), nullable=True))
|
|
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
with op.batch_alter_table('month', schema=None) as batch_op:
|
|
batch_op.drop_column('closed_at')
|
|
batch_op.drop_column('activated_at')
|
|
batch_op.drop_column('state')
|
|
|
|
# ### end Alembic commands ###
|