This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Database ownership
|
||||
|
||||
One PostgreSQL cluster is allowed in V1, but each semantic owner has its own schema and login role. Cross-owner writes and application JOINs are forbidden. Cross-owner foreign keys are forbidden by default.
|
||||
|
||||
`bootstrap/001_roles_and_schemas.sql` is run by a dedicated bootstrap/migration principal, never automatically by every runtime replica.
|
||||
@@ -0,0 +1,146 @@
|
||||
-- Bootstrap roles/schemas. Replace passwords via ALTER ROLE from secret-aware deployment; do not hardcode real passwords.
|
||||
BEGIN;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'identity_role') THEN CREATE ROLE identity_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS identity AUTHORIZATION identity_role;
|
||||
REVOKE ALL ON SCHEMA identity FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'authority_role') THEN CREATE ROLE authority_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS authority AUTHORIZATION authority_role;
|
||||
REVOKE ALL ON SCHEMA authority FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'situation_role') THEN CREATE ROLE situation_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS situation AUTHORIZATION situation_role;
|
||||
REVOKE ALL ON SCHEMA situation FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'work_role') THEN CREATE ROLE work_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS work AUTHORIZATION work_role;
|
||||
REVOKE ALL ON SCHEMA work FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'epistemics_role') THEN CREATE ROLE epistemics_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS epistemics AUTHORIZATION epistemics_role;
|
||||
REVOKE ALL ON SCHEMA epistemics FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'continuity_role') THEN CREATE ROLE continuity_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS continuity AUTHORIZATION continuity_role;
|
||||
REVOKE ALL ON SCHEMA continuity FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'capability_role') THEN CREATE ROLE capability_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS capability AUTHORIZATION capability_role;
|
||||
REVOKE ALL ON SCHEMA capability FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'commit_role') THEN CREATE ROLE commit_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS commit AUTHORIZATION commit_role;
|
||||
REVOKE ALL ON SCHEMA commit FROM PUBLIC;
|
||||
DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'artifact_role') THEN CREATE ROLE artifact_role LOGIN; END IF; END $$;
|
||||
CREATE SCHEMA IF NOT EXISTS artifact AUTHORIZATION artifact_role;
|
||||
REVOKE ALL ON SCHEMA artifact FROM PUBLIC;
|
||||
|
||||
SET ROLE identity_role;
|
||||
CREATE TABLE IF NOT EXISTS identity.actors (
|
||||
actor_id TEXT PRIMARY KEY,
|
||||
display_name TEXT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS identity.principals (
|
||||
principal_id TEXT PRIMARY KEY,
|
||||
display_name TEXT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS identity.principal_bindings (
|
||||
actor_id TEXT NOT NULL,
|
||||
principal_id TEXT NOT NULL,
|
||||
active BOOLEAN NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (actor_id, principal_id)
|
||||
);
|
||||
INSERT INTO identity.actors (actor_id, display_name) VALUES ('domovoy-creator-actor', 'Domovoy Creator') ON CONFLICT (actor_id) DO NOTHING;
|
||||
INSERT INTO identity.principals (principal_id, display_name) VALUES ('domovoy-creator-principal', 'Domovoy Creator Principal') ON CONFLICT (principal_id) DO NOTHING;
|
||||
INSERT INTO identity.principal_bindings (actor_id, principal_id, active) VALUES ('domovoy-creator-actor', 'domovoy-creator-principal', TRUE) ON CONFLICT (actor_id, principal_id) DO NOTHING;
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE authority_role;
|
||||
CREATE TABLE IF NOT EXISTS authority.scopes (
|
||||
scope_id TEXT PRIMARY KEY,
|
||||
label TEXT NOT NULL,
|
||||
global_scope BOOLEAN NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS authority.authority_grants (
|
||||
grant_id TEXT PRIMARY KEY,
|
||||
actor_id TEXT NOT NULL,
|
||||
principal_id TEXT NOT NULL,
|
||||
scope_id TEXT NOT NULL,
|
||||
grant_class TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
active BOOLEAN NOT NULL,
|
||||
valid_from TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
valid_until TIMESTAMPTZ,
|
||||
CHECK (revision > 0)
|
||||
);
|
||||
INSERT INTO authority.scopes (scope_id, label, global_scope) VALUES ('domovoy-global-scope', 'All Domovoy scopes', TRUE) ON CONFLICT (scope_id) DO NOTHING;
|
||||
INSERT INTO authority.authority_grants (grant_id, actor_id, principal_id, scope_id, grant_class, revision, active) VALUES ('domovoy-creator-grant', 'domovoy-creator-actor', 'domovoy-creator-principal', 'domovoy-global-scope', 'CREATOR', 1, TRUE) ON CONFLICT (grant_id) DO NOTHING;
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE commit_role;
|
||||
CREATE TABLE IF NOT EXISTS commit.authorized_actions (
|
||||
authorized_action_id TEXT PRIMARY KEY, action_intent_id TEXT NOT NULL,
|
||||
state TEXT NOT NULL, revision BIGINT NOT NULL, CHECK (revision > 0)
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS commit.action_attempts (
|
||||
action_attempt_id TEXT PRIMARY KEY, authorized_action_id TEXT NOT NULL,
|
||||
action_intent_id TEXT NOT NULL, state TEXT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE work_role;
|
||||
CREATE TABLE IF NOT EXISTS work.tasks (
|
||||
task_id TEXT PRIMARY KEY, goal_id TEXT NOT NULL, scope_id TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL, CHECK (revision > 0)
|
||||
);
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE situation_role;
|
||||
CREATE TABLE IF NOT EXISTS situation.focus_bindings (
|
||||
focus_binding_id TEXT PRIMARY KEY,
|
||||
actor_id TEXT NOT NULL,
|
||||
session_id TEXT NOT NULL,
|
||||
workspace_id TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL,
|
||||
goal_id TEXT NOT NULL,
|
||||
scope_id TEXT NOT NULL,
|
||||
active BOOLEAN NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE capability_role;
|
||||
CREATE TABLE IF NOT EXISTS capability.health (
|
||||
capability_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
semantic_version INTEGER NOT NULL,
|
||||
observed_at_unix_millis BIGINT,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (revision > 0),
|
||||
CHECK ((semantic_version = 1 AND observed_at_unix_millis IS NULL) OR (semantic_version = 2 AND observed_at_unix_millis > 0))
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS capability.health_projection (
|
||||
capability_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
semantic_version INTEGER NOT NULL,
|
||||
observed_at_unix_millis BIGINT
|
||||
);
|
||||
RESET ROLE;
|
||||
|
||||
SET ROLE continuity_role;
|
||||
CREATE TABLE IF NOT EXISTS continuity.prospective_items (
|
||||
prospective_item_id TEXT PRIMARY KEY,
|
||||
commitment_id TEXT NOT NULL,
|
||||
owner_principal_id TEXT NOT NULL,
|
||||
scope_id TEXT NOT NULL,
|
||||
goal_id TEXT NOT NULL,
|
||||
trigger_at_unix_millis BIGINT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (revision > 0)
|
||||
);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,16 @@
|
||||
BEGIN;
|
||||
SET ROLE identity_role;
|
||||
CREATE TABLE IF NOT EXISTS identity.actors (actor_id TEXT PRIMARY KEY, display_name TEXT NOT NULL, recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
CREATE TABLE IF NOT EXISTS identity.principals (principal_id TEXT PRIMARY KEY, display_name TEXT NOT NULL, recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
CREATE TABLE IF NOT EXISTS identity.principal_bindings (actor_id TEXT NOT NULL, principal_id TEXT NOT NULL, active BOOLEAN NOT NULL, recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (actor_id, principal_id));
|
||||
INSERT INTO identity.actors (actor_id, display_name) VALUES ('domovoy-creator-actor', 'Domovoy Creator') ON CONFLICT (actor_id) DO NOTHING;
|
||||
INSERT INTO identity.principals (principal_id, display_name) VALUES ('domovoy-creator-principal', 'Domovoy Creator Principal') ON CONFLICT (principal_id) DO NOTHING;
|
||||
INSERT INTO identity.principal_bindings (actor_id, principal_id, active) VALUES ('domovoy-creator-actor', 'domovoy-creator-principal', TRUE) ON CONFLICT (actor_id, principal_id) DO NOTHING;
|
||||
RESET ROLE;
|
||||
SET ROLE authority_role;
|
||||
CREATE TABLE IF NOT EXISTS authority.scopes (scope_id TEXT PRIMARY KEY, label TEXT NOT NULL, global_scope BOOLEAN NOT NULL, recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
CREATE TABLE IF NOT EXISTS authority.authority_grants (grant_id TEXT PRIMARY KEY, actor_id TEXT NOT NULL, principal_id TEXT NOT NULL, scope_id TEXT NOT NULL, grant_class TEXT NOT NULL, revision BIGINT NOT NULL, active BOOLEAN NOT NULL, valid_from TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, valid_until TIMESTAMPTZ, CHECK (revision > 0));
|
||||
INSERT INTO authority.scopes (scope_id, label, global_scope) VALUES ('domovoy-global-scope', 'All Domovoy scopes', TRUE) ON CONFLICT (scope_id) DO NOTHING;
|
||||
INSERT INTO authority.authority_grants (grant_id, actor_id, principal_id, scope_id, grant_class, revision, active) VALUES ('domovoy-creator-grant', 'domovoy-creator-actor', 'domovoy-creator-principal', 'domovoy-global-scope', 'CREATOR', 1, TRUE) ON CONFLICT (grant_id) DO NOTHING;
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,16 @@
|
||||
BEGIN;
|
||||
SET ROLE continuity_role;
|
||||
CREATE TABLE IF NOT EXISTS continuity.prospective_items (
|
||||
prospective_item_id TEXT PRIMARY KEY,
|
||||
commitment_id TEXT NOT NULL,
|
||||
owner_principal_id TEXT NOT NULL,
|
||||
scope_id TEXT NOT NULL,
|
||||
goal_id TEXT NOT NULL,
|
||||
trigger_at_unix_millis BIGINT NOT NULL,
|
||||
state TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (revision > 0)
|
||||
);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,15 @@
|
||||
BEGIN;
|
||||
SET ROLE situation_role;
|
||||
CREATE TABLE IF NOT EXISTS situation.focus_bindings (
|
||||
focus_binding_id TEXT PRIMARY KEY,
|
||||
actor_id TEXT NOT NULL,
|
||||
session_id TEXT NOT NULL,
|
||||
workspace_id TEXT NOT NULL,
|
||||
project_id TEXT NOT NULL,
|
||||
goal_id TEXT NOT NULL,
|
||||
scope_id TEXT NOT NULL,
|
||||
active BOOLEAN NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,5 @@
|
||||
BEGIN;
|
||||
SET ROLE work_role;
|
||||
CREATE TABLE IF NOT EXISTS work.tasks (task_id TEXT PRIMARY KEY, goal_id TEXT NOT NULL, scope_id TEXT NOT NULL, revision BIGINT NOT NULL, CHECK (revision > 0));
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
SET ROLE commit_role;
|
||||
CREATE TABLE IF NOT EXISTS commit.authorized_actions (authorized_action_id TEXT PRIMARY KEY, action_intent_id TEXT NOT NULL, state TEXT NOT NULL, revision BIGINT NOT NULL, CHECK (revision > 0));
|
||||
CREATE TABLE IF NOT EXISTS commit.action_attempts (action_attempt_id TEXT PRIMARY KEY, authorized_action_id TEXT NOT NULL, action_intent_id TEXT NOT NULL, state TEXT NOT NULL, recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,12 @@
|
||||
BEGIN;
|
||||
SET ROLE capability_role;
|
||||
CREATE TABLE IF NOT EXISTS capability.health (
|
||||
capability_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
recorded_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CHECK (revision > 0)
|
||||
);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,18 @@
|
||||
BEGIN;
|
||||
SET ROLE capability_role;
|
||||
ALTER TABLE capability.health ADD COLUMN IF NOT EXISTS semantic_version INTEGER;
|
||||
ALTER TABLE capability.health ADD COLUMN IF NOT EXISTS observed_at_unix_millis BIGINT;
|
||||
UPDATE capability.health SET semantic_version = 1 WHERE semantic_version IS NULL;
|
||||
ALTER TABLE capability.health ALTER COLUMN semantic_version SET NOT NULL;
|
||||
ALTER TABLE capability.health DROP CONSTRAINT IF EXISTS capability_health_semantic_shape;
|
||||
ALTER TABLE capability.health ADD CONSTRAINT capability_health_semantic_shape CHECK ((semantic_version = 1 AND observed_at_unix_millis IS NULL) OR (semantic_version = 2 AND observed_at_unix_millis > 0));
|
||||
CREATE TABLE IF NOT EXISTS capability.health_projection (
|
||||
capability_id TEXT PRIMARY KEY,
|
||||
state TEXT NOT NULL,
|
||||
reason TEXT NOT NULL,
|
||||
revision BIGINT NOT NULL,
|
||||
semantic_version INTEGER NOT NULL,
|
||||
observed_at_unix_millis BIGINT
|
||||
);
|
||||
RESET ROLE;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,3 @@
|
||||
# artifact migrations
|
||||
|
||||
Only the `artifact` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# authority migrations
|
||||
|
||||
Only the `authority` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# capability migrations
|
||||
|
||||
Only the `capability` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# commit migrations
|
||||
|
||||
Only the `commit` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# continuity migrations
|
||||
|
||||
Only the `continuity` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# epistemics migrations
|
||||
|
||||
Only the `epistemics` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# identity migrations
|
||||
|
||||
Only the `identity` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# situation migrations
|
||||
|
||||
Only the `situation` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
@@ -0,0 +1,3 @@
|
||||
# work migrations
|
||||
|
||||
Only the `work` semantic owner may introduce canonical writes in this schema. Migrations must be explicit, versioned and tested.
|
||||
Reference in New Issue
Block a user