Merge remote-tracking branch 'origin/prod-v7' into integration-all
This commit is contained in:
@@ -436,3 +436,37 @@ async def ensure_audit_table(engine: AsyncEngine) -> None:
|
||||
for stmt in indexes:
|
||||
await conn.execute(text(stmt))
|
||||
logger.info("audit_log table ensured")
|
||||
|
||||
|
||||
async def ensure_bot_drafts_table(engine: AsyncEngine) -> None:
|
||||
"""Ensure bot_drafts table and indexes exist for Bale bot quote sync."""
|
||||
ddl = """
|
||||
CREATE TABLE IF NOT EXISTS bot_drafts (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
chat_id BIGINT NOT NULL,
|
||||
kind VARCHAR(16) NOT NULL,
|
||||
payload JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
missing JSONB,
|
||||
status VARCHAR(16) NOT NULL DEFAULT 'active',
|
||||
source VARCHAR(16),
|
||||
source_message_id BIGINT,
|
||||
review_message_id BIGINT,
|
||||
last_bale_update_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
)
|
||||
"""
|
||||
indexes = (
|
||||
"CREATE INDEX IF NOT EXISTS ix_bot_drafts_chat_id ON bot_drafts(chat_id)",
|
||||
"CREATE INDEX IF NOT EXISTS ix_bot_drafts_chat_status ON bot_drafts(chat_id, status)",
|
||||
"ALTER TABLE bot_drafts ADD COLUMN IF NOT EXISTS last_bale_update_at TIMESTAMPTZ",
|
||||
"ALTER TABLE bot_drafts ADD COLUMN IF NOT EXISTS source_message_id BIGINT",
|
||||
"CREATE INDEX IF NOT EXISTS ix_bot_drafts_review_msg ON bot_drafts(review_message_id)",
|
||||
"CREATE INDEX IF NOT EXISTS ix_bot_drafts_source_msg ON bot_drafts(source_message_id)",
|
||||
)
|
||||
async with engine.begin() as conn:
|
||||
await conn.execute(text(ddl))
|
||||
for stmt in indexes:
|
||||
await conn.execute(text(stmt))
|
||||
logger.info("bot_drafts table ensured")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user