From 4d40843e241a2c1bf7b81f5178872ed76c685019 Mon Sep 17 00:00:00 2001 From: archeious Date: Fri, 17 Apr 2026 12:51:22 -0600 Subject: [PATCH] feat(db): add nullable notes column to entry and month_entry Free-text annotation up to 1024 chars. Nullable so existing rows need no backfill; an empty or whitespace-only input will be normalised to NULL in the service layer. Alembic batch_alter_table handles the SQLite table rebuild automatically. Refs #13 Co-Authored-By: Claude Opus 4.7 (1M context) --- ...6d_add_notes_column_to_entry_and_month_.py | 42 +++++++++++++++++++ src/quartermaster/models.py | 2 + 2 files changed, 44 insertions(+) create mode 100644 alembic/versions/ec804bdf366d_add_notes_column_to_entry_and_month_.py diff --git a/alembic/versions/ec804bdf366d_add_notes_column_to_entry_and_month_.py b/alembic/versions/ec804bdf366d_add_notes_column_to_entry_and_month_.py new file mode 100644 index 0000000..8dac030 --- /dev/null +++ b/alembic/versions/ec804bdf366d_add_notes_column_to_entry_and_month_.py @@ -0,0 +1,42 @@ +"""add notes column to entry and month_entry + +Revision ID: ec804bdf366d +Revises: 03ebe3c07262 +Create Date: 2026-04-17 12:47:41.533978 + +""" +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = 'ec804bdf366d' +down_revision: Union[str, Sequence[str], None] = '03ebe3c07262' +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('entry', schema=None) as batch_op: + batch_op.add_column(sa.Column('notes', sa.String(length=1024), nullable=True)) + + with op.batch_alter_table('month_entry', schema=None) as batch_op: + batch_op.add_column(sa.Column('notes', sa.String(length=1024), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('month_entry', schema=None) as batch_op: + batch_op.drop_column('notes') + + with op.batch_alter_table('entry', schema=None) as batch_op: + batch_op.drop_column('notes') + + # ### end Alembic commands ### diff --git a/src/quartermaster/models.py b/src/quartermaster/models.py index ee81008..c2edacb 100644 --- a/src/quartermaster/models.py +++ b/src/quartermaster/models.py @@ -51,6 +51,7 @@ class Entry(Base): ) name: Mapped[str] = mapped_column(String(128), nullable=False) amount: Mapped[Decimal] = mapped_column(Numeric(10, 2), nullable=False) + notes: Mapped[str | None] = mapped_column(String(1024), nullable=True) created_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), server_default=func.now(), nullable=False ) @@ -117,6 +118,7 @@ class MonthEntry(Base): Numeric(10, 2), nullable=False, default=Decimal("0.00"), server_default="0.00", ) + notes: Mapped[str | None] = mapped_column(String(1024), nullable=True) origin_name: Mapped[str | None] = mapped_column(String(128), nullable=True) origin_planned: Mapped[Decimal | None] = mapped_column( Numeric(10, 2), nullable=True