Add meta.find_schema_problems(); every install runs 00-10; drop migrations

09_schema_check.sql adds meta.find_schema_problems(), a read-only check
any client (Python, C++, psql) can call:

    SELECT * FROM meta.find_schema_problems();   -- zero rows = usable

One row per problem (object, problem): missing schemas, extension,
sequences, tables, columns, wrong column type or NOT NULL, missing
constraints, indexes, views, stored-function bodies that differ from the
DDL (whitespace-insensitive md5 fingerprint), a missing/disabled/
misdirected event trigger, short reference data, no version row. It
mirrors 00-08 and must change in the same commit as they do; the
release test (a fresh install returns zero rows) enforces that.

10_schema_version.sql records VERSION in meta.schema_version. Before,
only the Python client wrote that row, so databases provisioned by
run_setup.py recorded no version at all.

run_setup.py now runs 00-10. It skipped 08_script_log.sql, so its
databases lacked a table the Python client uses; every fresh install is
now identical regardless of provisioner.

sql/migrate/ is removed: databases are re-provisioned, not migrated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
peter 2026-10-06 11:01:28 +01:00
parent 6dde987cfb
commit 1f5cfeceeb
7 changed files with 367 additions and 269 deletions

View file

@ -8,7 +8,11 @@ into either project -- edit it here.
It executes the numbered DDL files in ./sql/ in order:
00_extensions, 01_schemas, 02_sequences, 03_tables, 04_indexes,
05_procedures, 06_triggers, 07_reference_data
05_procedures, 06_triggers, 07_reference_data, 08_script_log,
09_schema_check, 10_schema_version
Every fresh install runs all of them, so every client sees the same database.
Afterwards `SELECT * FROM meta.find_schema_problems()` must return no rows.
Connection settings come from (highest precedence first):
1. command-line flags (--host --port --dbname --user --password)
@ -31,8 +35,8 @@ from typing import Dict
SQL_DIR = Path(__file__).parent / "sql"
CONFIG_FILE = Path(__file__).parent / "db_config.json"
# Executed in order. 08_script_log.sql and sql/migrate/*.sql are auxiliary and
# are intentionally NOT part of a fresh install.
# Executed in order -- all of them, on every fresh install. 10_schema_version
# runs last, so a database that records a version is complete.
SQL_FILES = [
"00_extensions.sql",
"01_schemas.sql",
@ -42,6 +46,9 @@ SQL_FILES = [
"05_procedures.sql",
"06_triggers.sql",
"07_reference_data.sql",
"08_script_log.sql",
"09_schema_check.sql",
"10_schema_version.sql",
]
DEFAULTS = {