Ship the platform render of provision.sql (identity schema dredd)

Scribe joins Atrium as a module, so db/managed/provision.sql is now the
rendering with --identity-schema dredd --identity-owner atrium_migrator
(the one Atrium's push.sh compares), and CI's --check-file step passes the
same two flags, as Lexicon and Agora do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 09:51:20 +01:00
co-authored by Claude Opus 5.5
parent 5dbe0fb1c8
commit 87ebdaa3b5
4 changed files with 58 additions and 23 deletions
+3 -1
View File
@@ -134,10 +134,12 @@ jobs:
run: pip install -r requirements-dev.txt
- name: db/managed/provision.sql is what dredd-core renders
# The SQL-editor path must never drift from the provisioning routine: exit 1 = stale; re-render it
# with --output instead of --check-file (db/managed/README.md).
# with --output instead of --check-file (db/managed/README.md). Rendered for the PLATFORM
# (--identity-schema / --identity-owner): the rendering Atrium's push.sh compares, as Lexicon.
run: |
python -m dredd_core.managed provision --sql-only \
--schema scribe --app-role scribe_app --migrator-role scribe_migrator \
--identity-schema dredd --identity-owner atrium_migrator \
--check-file db/managed/provision.sql
- name: Emulate a managed Postgres (TEST-ONLY)
# The service is on localhost, so no --allow-remote (emulate refuses a non-local host without it).
+2 -1
View File
@@ -115,7 +115,8 @@ cd backend && pytest # DB-free unit tests; integration auto
SCRIBE_RUN_INTEGRATION=1 pytest # full API loop (needs a migrated+seeded Postgres)
alembic upgrade head --sql # inspect the DDL with no database
python -m dredd_core.managed provision --sql-only --schema scribe --app-role scribe_app \
--migrator-role scribe_migrator --check-file ../db/managed/provision.sql # rendering current?
--migrator-role scribe_migrator --identity-schema dredd --identity-owner atrium_migrator \
--check-file ../db/managed/provision.sql # rendering current? (the platform render)
python scripts/license_gate.py # CI license gate locally
python scripts/deploy_check.py # compose/Dockerfile/.env coherence
node --check frontend/app.js # ALWAYS after editing the console
+7 -6
View File
@@ -90,15 +90,16 @@ avoids.
```bash
python -m dredd_core.managed provision --sql-only --schema scribe --app-role scribe_app \
--migrator-role scribe_migrator --output db/managed/provision.sql
--migrator-role scribe_migrator --identity-schema dredd --identity-owner atrium_migrator \
--output db/managed/provision.sql
```
The committed file is the **standalone** rendering, which is what a generated app needs on day one.
Joining a platform adds two flags to that command, and therefore changes the file — which is exactly
why CI compares it. See section 6.
The committed file is the **platform** rendering (Scribe is a module of Atrium, as Lexicon and Agora
are), and CI's `--check-file` step passes the same two identity flags. A standalone deployment of
its own renders without them (see section 6).
**Joining Atrium (the platform) means re-rendering with the identity flags**, exactly as Galena,
Sygna and Counsel ship theirs, and adding the same two flags to CI's `--check-file` step:
**Joining Atrium (the platform) means re-rendering with the identity flags** — the committed file
already is that rendering:
```bash
python -m dredd_core.managed provision --sql-only --schema scribe --app-role scribe_app --migrator-role scribe_migrator --identity-schema dredd --identity-owner atrium_migrator --output db/managed/provision.sql
+46 -15
View File
@@ -1,16 +1,16 @@
-- =================================================================================================
-- Managed Postgres provisioning for one app of the family, in the shared database:
-- schema scribe, migrator scribe_migrator, app scribe_app, extensions: none, migrator statement_timeout 30min
-- search_path scribe, extensions; no shared identity schema (this app owns its own accounts)
-- search_path scribe, dredd, extensions; shared identity schema dredd, owned by atrium_migrator (created by its owner, USAGE only here)
--
-- Rendered by dredd-core. Do not edit: re-render, and let CI check it is current (exit 1 = stale):
-- python -m dredd_core.managed provision --sql-only \
-- --schema scribe --app-role scribe_app --migrator-role scribe_migrator \
-- --schema scribe --app-role scribe_app --migrator-role scribe_migrator --identity-schema dredd --identity-owner atrium_migrator \
-- --output db/managed/provision.sql (CI: --check-file db/managed/provision.sql)
--
-- Preferred path, from a shell (passwords come from environment variables and are never printed):
-- python -m dredd_core.managed provision --admin-url ADMIN_DATABASE_URL \
-- --schema scribe --app-role scribe_app --migrator-role scribe_migrator \
-- --schema scribe --app-role scribe_app --migrator-role scribe_migrator --identity-schema dredd --identity-owner atrium_migrator \
-- --migrator-password-env SCRIBE_MIGRATOR_PASSWORD --app-password-env SCRIBE_APP_PASSWORD
--
-- SQL editor path (no shell): paste this whole file into the provider's SQL editor, replace both
@@ -30,8 +30,8 @@ DECLARE
app_role text := 'scribe_app';
admin_roles text[] := ARRAY['postgres', 'postgres_managed']::text[];
extension_names text[] := '{}'::text[];
identity_schema text := '';
identity_owner text := '';
identity_schema text := 'dredd';
identity_owner text := 'atrium_migrator';
owns_identity boolean := false;
seen text;
r text;
@@ -200,19 +200,50 @@ BEGIN
END
$dredd_provision_extensions_usage$;
-- 9. search_path of scribe_migrator
ALTER ROLE scribe_migrator SET search_path = scribe, extensions;
-- 9. temporary membership in the identity owner atrium_migrator: needed to grant on dredd
GRANT atrium_migrator TO CURRENT_USER;
-- 10. search_path of scribe_app
ALTER ROLE scribe_app SET search_path = scribe, extensions;
-- 10. schema dredd: USAGE for scribe_migrator and scribe_app
GRANT USAGE ON SCHEMA dredd TO scribe_migrator, scribe_app;
-- 11. statement_timeout of scribe_migrator
-- 11. schema dredd: check that the USAGE grant took
DO $dredd_provision_identity_usage$
DECLARE
identity_schema text := 'dredd';
migrator_role text := 'scribe_migrator';
app_role text := 'scribe_app';
identity_owner text := 'atrium_migrator';
BEGIN
IF NOT (has_schema_privilege(migrator_role, identity_schema, 'USAGE')
AND has_schema_privilege(app_role, identity_schema, 'USAGE')) THEN
RAISE EXCEPTION USING
MESSAGE = 'provision: could not grant USAGE on the shared identity schema '
|| quote_ident(identity_schema) || ' to ' || quote_ident(migrator_role) || ' and '
|| quote_ident(app_role),
HINT = 'The connected role holds no grant option there (PostgreSQL then only warns "no '
|| 'privileges were granted"), because the schema belongs to ' || quote_ident(identity_owner)
|| '. The temporary membership in that role is what carries the grant option: check '
|| '--identity-owner names the role that really owns the schema.';
END IF;
END
$dredd_provision_identity_usage$;
-- 12. search_path of scribe_migrator
ALTER ROLE scribe_migrator SET search_path = scribe, dredd, extensions;
-- 13. search_path of scribe_app
ALTER ROLE scribe_app SET search_path = scribe, dredd, extensions;
-- 14. statement_timeout of scribe_migrator
ALTER ROLE scribe_migrator SET statement_timeout = '30min';
-- 12. end the temporary membership: no standing SET ROLE scribe_migrator for the admin
-- 15. end the temporary membership: no standing SET ROLE scribe_migrator for the admin
REVOKE scribe_migrator FROM CURRENT_USER;
-- 13. verify the end state
-- 16. end the temporary membership in atrium_migrator
REVOKE atrium_migrator FROM CURRENT_USER;
-- 17. verify the end state
DO $dredd_provision_verify$
DECLARE
target_schema text := 'scribe';
@@ -220,9 +251,9 @@ DECLARE
app_role text := 'scribe_app';
extension_names text[] := '{}'::text[];
timeout_setting text := 'statement_timeout=30min';
path_setting text := 'search_path=scribe, extensions';
identity_schema text := '';
identity_owner text := '';
path_setting text := 'search_path=scribe, dredd, extensions';
identity_schema text := 'dredd';
identity_owner text := 'atrium_migrator';
admin_roles text[] := ARRAY['postgres', 'postgres_managed']::text[];
admin_is_super boolean := (SELECT rolsuper FROM pg_roles WHERE rolname = current_user);
problems text[] := '{}'::text[];