kin: KIN-OBS-022 Исправить мелкие баги отображения и deprecation в cli/watch.py

This commit is contained in:
Gros Frumos 2026-03-17 18:32:03 +02:00
parent f0a69ed1d3
commit 80e83058a0
2 changed files with 34 additions and 4 deletions

View file

@ -737,6 +737,35 @@ def _migrate(conn: sqlite3.Connection):
)
conn.commit()
# Add UNIQUE(from_project, to_project, type) to project_links (KIN-INFRA-013).
# SQLite does not support ALTER TABLE ADD CONSTRAINT — table recreation required.
if "project_links" in existing_tables:
pl_sql_row = conn.execute(
"SELECT sql FROM sqlite_master WHERE type='table' AND name='project_links'"
).fetchone()
pl_has_unique = pl_sql_row and "UNIQUE" in (pl_sql_row[0] or "").upper()
if not pl_has_unique:
conn.executescript("""
PRAGMA foreign_keys=OFF;
CREATE TABLE project_links_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
from_project TEXT NOT NULL REFERENCES projects(id),
to_project TEXT NOT NULL REFERENCES projects(id),
type TEXT NOT NULL,
description TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
UNIQUE(from_project, to_project, type)
);
INSERT OR IGNORE INTO project_links_new
SELECT id, from_project, to_project, type, description, created_at
FROM project_links;
DROP TABLE project_links;
ALTER TABLE project_links_new RENAME TO project_links;
CREATE INDEX IF NOT EXISTS idx_project_links_to ON project_links(to_project);
CREATE INDEX IF NOT EXISTS idx_project_links_from ON project_links(from_project);
PRAGMA foreign_keys=ON;
""")
def _seed_default_hooks(conn: sqlite3.Connection):
"""Seed default hooks for the kin project (idempotent).