diff --git a/.git_api_info b/.git_api_info index 345ccd1..896df23 100644 --- a/.git_api_info +++ b/.git_api_info @@ -1,2 +1,2 @@ -Branch: main -Commit: 29279bfd72a6fa296d1aa05a825bd88ca1f36c91 +Branch: invoice-update +Commit: 50538bb64faa7f46d643ed60b9f0f272d5624a39 diff --git a/alembic/versions/sql/acupedia_schema_v5.sql b/alembic/versions/sql/acupedia_schema_v5.sql index b210f07..2f1f08f 100644 --- a/alembic/versions/sql/acupedia_schema_v5.sql +++ b/alembic/versions/sql/acupedia_schema_v5.sql @@ -2636,6 +2636,12 @@ create table if not exists commerce.invoices ( ) ); +create table if not exists commerce.invoice_monthly_sequences ( + year_month varchar(7) primary key, + last_serial integer not null default 0, + updated_at timestamptz not null default now() +); + do $$ begin if not exists ( diff --git a/app/lifespan.py b/app/lifespan.py index 5c71886..f60d983 100644 --- a/app/lifespan.py +++ b/app/lifespan.py @@ -113,6 +113,26 @@ async def lifespan( "Redis caching disabled" ) + # ------------------------------------------------------------- + # Ensure commerce.invoice_monthly_sequences table exists + # ------------------------------------------------------------- + try: + from app.db.session import engine + from sqlalchemy import text + async with engine.begin() as conn: + await conn.execute(text( + """ + CREATE TABLE IF NOT EXISTS commerce.invoice_monthly_sequences ( + year_month VARCHAR(7) PRIMARY KEY, + last_serial INTEGER NOT NULL DEFAULT 0, + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() + ); + """ + )) + logger.info("Commerce invoice sequence table verified") + except Exception as exc: + logger.warning("Could not auto-verify invoice sequence table on startup: %s", exc) + yield finally: diff --git a/docs/accupedia_db_v5.sql b/docs/accupedia_db_v5.sql index d7fe630..6adc23c 100644 --- a/docs/accupedia_db_v5.sql +++ b/docs/accupedia_db_v5.sql @@ -2638,6 +2638,12 @@ create table if not exists commerce.invoices ( ) ); +create table if not exists commerce.invoice_monthly_sequences ( + year_month varchar(7) primary key, + last_serial integer not null default 0, + updated_at timestamptz not null default now() +); + do $$ begin if not exists (