kin: KIN-135-backend_dev

This commit is contained in:
Gros Frumos 2026-03-20 21:56:46 +02:00
parent 4c01e0e4ee
commit 24be66d16c
9 changed files with 436 additions and 6 deletions

View file

@ -72,6 +72,7 @@ CREATE TABLE IF NOT EXISTS tasks (
telegram_sent BOOLEAN DEFAULT 0,
acceptance_criteria TEXT,
smoke_test_result JSON DEFAULT NULL,
return_count INTEGER DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
@ -151,6 +152,7 @@ CREATE TABLE IF NOT EXISTS pipelines (
parent_pipeline_id INTEGER REFERENCES pipelines(id),
department TEXT,
pid INTEGER,
pipeline_type TEXT DEFAULT 'standard',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
completed_at DATETIME
);
@ -326,6 +328,20 @@ CREATE TABLE IF NOT EXISTS pipeline_log (
);
CREATE INDEX IF NOT EXISTS idx_pipeline_log_pipeline_id ON pipeline_log(pipeline_id, id);
-- История возвратов задачи к PM (KIN-135)
CREATE TABLE IF NOT EXISTS task_returns (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
return_number INTEGER NOT NULL,
reason_category TEXT NOT NULL,
reason_text TEXT,
returned_by TEXT DEFAULT 'system',
pipeline_id INTEGER REFERENCES pipelines(id),
returned_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_task_returns_task_id ON task_returns(task_id);
"""
@ -800,6 +816,39 @@ def _migrate(conn: sqlite3.Connection):
conn.execute("ALTER TABLE tasks ADD COLUMN smoke_test_result JSON DEFAULT NULL")
conn.commit()
# KIN-135: Add return_count to tasks — counts full returns to PM
task_cols_final3 = {r[1] for r in conn.execute("PRAGMA table_info(tasks)").fetchall()}
if "return_count" not in task_cols_final3:
conn.execute("ALTER TABLE tasks ADD COLUMN return_count INTEGER DEFAULT 0")
conn.commit()
# KIN-135: Add pipeline_type to pipelines — distinguishes escalation pipelines
if "pipelines" in existing_tables:
pipeline_cols2 = {r[1] for r in conn.execute("PRAGMA table_info(pipelines)").fetchall()}
if "pipeline_type" not in pipeline_cols2:
conn.execute("ALTER TABLE pipelines ADD COLUMN pipeline_type TEXT DEFAULT 'standard'")
conn.commit()
# KIN-135: Create task_returns table — return history per task
existing_tables2 = {r[0] for r in conn.execute(
"SELECT name FROM sqlite_master WHERE type='table'"
).fetchall()}
if "task_returns" not in existing_tables2:
conn.executescript("""
CREATE TABLE IF NOT EXISTS task_returns (
id INTEGER PRIMARY KEY AUTOINCREMENT,
task_id TEXT NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
return_number INTEGER NOT NULL,
reason_category TEXT NOT NULL,
reason_text TEXT,
returned_by TEXT DEFAULT 'system',
pipeline_id INTEGER REFERENCES pipelines(id),
returned_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_task_returns_task_id ON task_returns(task_id);
""")
conn.commit()
def _seed_default_hooks(conn: sqlite3.Connection):
"""Seed default hooks for the kin project (idempotent).