generated from kgod/ai-review-template
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""Add durable optimization workflow state to PostgreSQL."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
|
|
|
|
revision = "20260730_05"
|
|
down_revision = "20260724_03"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
schema = op.get_context().config.get_main_option("resume_agent.schema", "resume_agent")
|
|
bind = op.get_bind()
|
|
bind.exec_driver_sql(
|
|
f'''
|
|
CREATE TABLE IF NOT EXISTS "{schema}".optimization_runs (
|
|
id VARCHAR(128) PRIMARY KEY,
|
|
session_id VARCHAR(128) NOT NULL
|
|
REFERENCES "{schema}".sessions(id) ON DELETE CASCADE,
|
|
entry_id VARCHAR(128) NOT NULL,
|
|
mode VARCHAR(32) NOT NULL,
|
|
status VARCHAR(32) NOT NULL,
|
|
source_revision INTEGER NOT NULL CHECK (source_revision >= 1),
|
|
state JSONB NOT NULL,
|
|
proposal JSONB,
|
|
created_at TIMESTAMPTZ NOT NULL,
|
|
updated_at TIMESTAMPTZ NOT NULL
|
|
)
|
|
'''
|
|
)
|
|
bind.exec_driver_sql(
|
|
f'''CREATE INDEX IF NOT EXISTS ix_optimization_runs_active
|
|
ON "{schema}".optimization_runs (session_id, entry_id, status)'''
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
schema = op.get_context().config.get_main_option("resume_agent.schema", "resume_agent")
|
|
op.get_bind().exec_driver_sql(f'DROP TABLE IF EXISTS "{schema}".optimization_runs')
|