-
Notifications
You must be signed in to change notification settings - Fork 1
feat(metaschema-schema): port system-controlled database standing columns #128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,16 @@ CREATE TABLE metaschema_public.database ( | |
| -- Write-once: first row to set it wins; immutable once true. | ||
| platform boolean NOT NULL DEFAULT false, | ||
|
|
||
| -- Operational access standing. NULL = in good standing; set = every serving | ||
| -- lane (pg-wire proxy, gateways, GraphQL, workers) refuses work for this | ||
| -- database. System-controlled: tenants read it, only the system role or a | ||
| -- platform admin writes it (guard trigger in the metaschema module). The | ||
| -- reason names who set it — 'billing' clears automatically when allowance | ||
| -- returns, 'admin' only when an admin lifts it. Not an audit log: billing | ||
| -- state is the record of WHY; this is only the current on/off derived from it. | ||
| suspended_at timestamptz, | ||
| suspended_reason text, | ||
|
|
||
| created_at timestamptz DEFAULT now(), | ||
| updated_at timestamptz DEFAULT now(), | ||
|
|
||
|
|
@@ -27,11 +37,20 @@ CREATE TABLE metaschema_public.database ( | |
| ALTER TABLE metaschema_public.database | ||
| ADD CONSTRAINT db_namechk CHECK (char_length(name) > 2); | ||
|
|
||
| ALTER TABLE metaschema_public.database | ||
| ADD CONSTRAINT database_suspension_chk CHECK ( | ||
| (suspended_at IS NULL) = (suspended_reason IS NULL) | ||
| AND (suspended_reason IS NULL OR suspended_reason IN ('billing', 'admin')) | ||
| ); | ||
|
|
||
| CREATE UNIQUE INDEX databases_database_platform_singleton_idx | ||
| ON metaschema_public.database (platform) | ||
| WHERE platform; | ||
| CREATE INDEX database_owner_id_idx ON metaschema_public.database ( owner_id ); | ||
| CREATE INDEX database_suspended_at_idx ON metaschema_public.database ( suspended_at ); | ||
|
|
||
| COMMENT ON COLUMN metaschema_public.database.schema_hash IS '@behavior -*'; | ||
| COMMENT ON COLUMN metaschema_public.database.suspended_at IS '@behavior -insert -update'; | ||
| COMMENT ON COLUMN metaschema_public.database.suspended_reason IS '@behavior -insert -update'; | ||
|
Comment on lines
+53
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 security · medium Suspended columns lack promised guard trigger The comment at 📋 Prompt for AI AgentsIn packages/metaschema-schema/deploy/schemas/metaschema_public/tables/database/table.sql, the new |
||
|
|
||
| COMMIT; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 bug · medium
No upgrade path for existing databases
The new
suspended_at/suspended_reasoncolumns,database_suspension_chk, anddatabase_suspended_at_idxare added only inside the write-onceCREATE TABLE(table.sql:28-50) and the regenerated base install script, with noALTER TABLEmigration, no version bump, and no extension upgrade script insql/. Installations wheremetaschema_public.databasealready exists never receive the new columns, so the suspension feature silently does nothing there while fresh installs get it.📋 Prompt for AI Agents
In packages/metaschema-schema, add a migration path for existing installs: bump the extension version (package.json, metaschema-schema.control, and the sql/ artifact name) and add an upgrade script (e.g. metaschema-schema--0.44.0--0.45.0.sql) that runs
ALTER TABLE metaschema_public.database ADD COLUMN suspended_at timestamptz, ADD COLUMN suspended_reason text;, adds thedatabase_suspension_chkCHECK constraint, and createsdatabase_suspended_at_idx, so databases where the table already exists receive the same columns/constraint/index as fresh installs.