From 9d5befdde9113168b11433bd4248a709b8027c48 Mon Sep 17 00:00:00 2001 From: Lars Date: Mon, 7 Sep 2026 12:35:22 +0200 Subject: [PATCH] Fix Postgres prompt seed crashing on CASE WHEN 0/1. SQLite treats integers as booleans; a backend recreate after the API key was added hit that on every start. Co-authored-by: Cursor --- backend/db.py | 2 +- backend/tests/test_sql_compat.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/db.py b/backend/db.py index 442798a..a369bfc 100644 --- a/backend/db.py +++ b/backend/db.py @@ -307,7 +307,7 @@ def _seed_prompts(conn: Any) -> None: SET name = ?, description = ?, category = ?, prompt_type = ?, required_feature = ?, is_system_default = 1, default_template = ?, seed_revision = ?, - template = CASE WHEN ? THEN ? ELSE template END, + template = CASE WHEN ? = 1 THEN ? ELSE template END, updated = datetime('now') WHERE slug = ? """, diff --git a/backend/tests/test_sql_compat.py b/backend/tests/test_sql_compat.py index bc385a2..037c67f 100644 --- a/backend/tests/test_sql_compat.py +++ b/backend/tests/test_sql_compat.py @@ -57,6 +57,9 @@ def main() -> None: expect("'?'" in quoted, "question mark inside quotes kept") expect(quoted.endswith("%s") or quoted.rstrip().endswith("%s"), "trailing placeholder converted") + case_sql = adapt_sql("UPDATE t SET x = CASE WHEN ? = 1 THEN ? ELSE x END") + expect("CASE WHEN %s = 1 THEN %s ELSE x END" in case_sql, "boolean-safe case placeholder") + parts = split_sql("CREATE TABLE a (id TEXT); CREATE TABLE b (id TEXT);") expect(parts == ["CREATE TABLE a (id TEXT)", "CREATE TABLE b (id TEXT)"], "split two statements") schema = (ROOT / "schema.sql").read_text(encoding="utf-8")