@x12i/keyrox-store-pg 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/database.d.ts +10 -0
  2. package/dist/database.d.ts.map +1 -0
  3. package/dist/database.js +28 -0
  4. package/dist/database.js.map +1 -0
  5. package/dist/directory-access-sql.d.ts +12 -0
  6. package/dist/directory-access-sql.d.ts.map +1 -0
  7. package/dist/directory-access-sql.js +253 -0
  8. package/dist/directory-access-sql.js.map +1 -0
  9. package/dist/directory-sql.d.ts +8 -0
  10. package/dist/directory-sql.d.ts.map +1 -0
  11. package/dist/directory-sql.js +1052 -0
  12. package/dist/directory-sql.js.map +1 -0
  13. package/dist/hosted-human-sessions.d.ts +5 -0
  14. package/dist/hosted-human-sessions.d.ts.map +1 -0
  15. package/dist/hosted-human-sessions.js +105 -0
  16. package/dist/hosted-human-sessions.js.map +1 -0
  17. package/dist/index.d.ts +21 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +59 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/migrate.d.ts +4 -0
  22. package/dist/migrate.d.ts.map +1 -0
  23. package/dist/migrate.js +51 -0
  24. package/dist/migrate.js.map +1 -0
  25. package/dist/notification-deliveries.d.ts +5 -0
  26. package/dist/notification-deliveries.d.ts.map +1 -0
  27. package/dist/notification-deliveries.js +81 -0
  28. package/dist/notification-deliveries.js.map +1 -0
  29. package/dist/notification-webhook-sql.d.ts +4 -0
  30. package/dist/notification-webhook-sql.d.ts.map +1 -0
  31. package/dist/notification-webhook-sql.js +109 -0
  32. package/dist/notification-webhook-sql.js.map +1 -0
  33. package/dist/rows.d.ts +54 -0
  34. package/dist/rows.d.ts.map +1 -0
  35. package/dist/rows.js +426 -0
  36. package/dist/rows.js.map +1 -0
  37. package/dist/sql-store.d.ts +4 -0
  38. package/dist/sql-store.d.ts.map +1 -0
  39. package/dist/sql-store.js +1350 -0
  40. package/dist/sql-store.js.map +1 -0
  41. package/migrations/001_init.sql +260 -0
  42. package/migrations/002_apps.sql +36 -0
  43. package/migrations/003_environments.sql +46 -0
  44. package/migrations/004_sso.sql +62 -0
  45. package/migrations/005_workloads.sql +64 -0
  46. package/migrations/006_directory.sql +155 -0
  47. package/migrations/007_account_sso.sql +40 -0
  48. package/migrations/008_app_sign_in.sql +26 -0
  49. package/migrations/009_account_sso_next.sql +4 -0
  50. package/migrations/010_account_sso_profile.sql +14 -0
  51. package/migrations/011_hosted_sso_profiles.sql +26 -0
  52. package/migrations/012_app_signup_roles.sql +2 -0
  53. package/migrations/013_product_role_catalog.sql +14 -0
  54. package/migrations/014_application_staff_access.sql +21 -0
  55. package/migrations/015_audit_service_actor.sql +7 -0
  56. package/migrations/016_app_waitlist_questions.sql +2 -0
  57. package/migrations/017_app_signup_policy.sql +9 -0
  58. package/migrations/018_managed_app_sign_in.sql +8 -0
  59. package/migrations/019_hosted_sso_email_proofs.sql +12 -0
  60. package/migrations/020_cli_login_codes.sql +15 -0
  61. package/migrations/021_hosted_email_codes.sql +18 -0
  62. package/migrations/022_sso_waitlist_callback.sql +3 -0
  63. package/migrations/023_app_email_code_sign_in.sql +1 -0
  64. package/migrations/024_hosted_auth_copy.sql +2 -0
  65. package/migrations/025_app_directory_workspaces.sql +55 -0
  66. package/migrations/027_role_features_and_configuration.sql +17 -0
  67. package/migrations/028_sso_only_signup_audience.sql +4 -0
  68. package/migrations/029_people_only_directory_model.sql +3 -0
  69. package/migrations/030_typed_questionnaires.sql +3 -0
  70. package/migrations/031_app_notifications.sql +22 -0
  71. package/migrations/032_agent_grant_duration.sql +10 -0
  72. package/migrations/033_application_lifecycle.sql +67 -0
  73. package/migrations/034_notification_deliveries.sql +25 -0
  74. package/migrations/035_app_notification_webhook_jobs.sql +28 -0
  75. package/migrations/036_account_notification_recovery.sql +11 -0
  76. package/migrations/037_waitlist_confirmation.sql +7 -0
  77. package/migrations/039_hosted_human_sessions.sql +45 -0
  78. package/migrations/040_hosted_human_clients.sql +35 -0
  79. package/migrations/041_app_workspace_invitations.sql +9 -0
  80. package/migrations/042_directory_email_proof.sql +16 -0
  81. package/migrations/043_sso_exchange_redirect_uri.sql +1 -0
  82. package/migrations/044_repair_app_sign_in_connections.sql +30 -0
  83. package/migrations/045_directory_integrity.sql +140 -0
  84. package/migrations/046_person_email_across_organizations.sql +7 -0
  85. package/migrations/047_owner_access.sql +35 -0
  86. package/migrations/048_invitation_links.sql +28 -0
  87. package/package.json +36 -4
  88. package/README.md +0 -3
@@ -0,0 +1,155 @@
1
+ ALTER TABLE users ADD COLUMN last_org_id text;
2
+ ALTER TABLE orgs ADD COLUMN logo_url text;
3
+ ALTER TABLE memberships ADD COLUMN production_access boolean NOT NULL DEFAULT false;
4
+ UPDATE memberships SET production_access = true WHERE role = 'owner';
5
+ ALTER TABLE invites ADD COLUMN production_access boolean NOT NULL DEFAULT false;
6
+
7
+ ALTER TABLE applications
8
+ ADD COLUMN product_name text NOT NULL DEFAULT '',
9
+ ADD COLUMN logo_url text,
10
+ ADD COLUMN accent_color text,
11
+ ADD COLUMN signup_mode text NOT NULL DEFAULT 'open',
12
+ ADD COLUMN allow_without_personal_org boolean NOT NULL DEFAULT false;
13
+ UPDATE applications SET product_name = title WHERE product_name = '';
14
+
15
+ CREATE TABLE platform_settings (
16
+ id text PRIMARY KEY,
17
+ signup_mode text NOT NULL,
18
+ explicit boolean NOT NULL DEFAULT false,
19
+ operators text[] NOT NULL DEFAULT '{}'
20
+ );
21
+
22
+ INSERT INTO platform_settings (id, signup_mode, explicit, operators) VALUES ('platform', 'open', false, '{}');
23
+
24
+ CREATE TABLE platform_waitlist (
25
+ id text PRIMARY KEY,
26
+ email text NOT NULL UNIQUE,
27
+ status text NOT NULL,
28
+ token_hash text,
29
+ created_at timestamptz NOT NULL
30
+ );
31
+
32
+ CREATE TABLE app_identities (
33
+ id text PRIMARY KEY,
34
+ app_id text NOT NULL REFERENCES applications (id),
35
+ environment_id text NOT NULL REFERENCES app_environments (id),
36
+ org_id text NOT NULL,
37
+ kind text NOT NULL,
38
+ email text,
39
+ password_hash text,
40
+ display_name text NOT NULL,
41
+ status text NOT NULL,
42
+ email_verified_at timestamptz,
43
+ metadata jsonb NOT NULL DEFAULT '{}',
44
+ created_at timestamptz NOT NULL,
45
+ updated_at timestamptz NOT NULL
46
+ );
47
+
48
+ CREATE UNIQUE INDEX app_identities_email_idx ON app_identities (environment_id, lower(email)) WHERE email IS NOT NULL;
49
+ CREATE INDEX app_identities_environment_idx ON app_identities (environment_id, created_at, id);
50
+
51
+ CREATE TABLE app_identity_memberships (
52
+ id text PRIMARY KEY,
53
+ environment_id text NOT NULL,
54
+ identity_id text NOT NULL REFERENCES app_identities (id),
55
+ organization_id text NOT NULL,
56
+ relation text NOT NULL,
57
+ created_at timestamptz NOT NULL,
58
+ UNIQUE (identity_id, organization_id)
59
+ );
60
+
61
+ CREATE INDEX app_identity_memberships_environment_idx ON app_identity_memberships (environment_id);
62
+
63
+ CREATE TABLE app_permissions (
64
+ id text PRIMARY KEY,
65
+ environment_id text NOT NULL,
66
+ key text NOT NULL,
67
+ description text NOT NULL,
68
+ created_at timestamptz NOT NULL,
69
+ UNIQUE (environment_id, key)
70
+ );
71
+
72
+ CREATE TABLE app_product_roles (
73
+ id text PRIMARY KEY,
74
+ environment_id text NOT NULL,
75
+ name text NOT NULL,
76
+ permissions text[] NOT NULL,
77
+ inherits text[] NOT NULL,
78
+ created_at timestamptz NOT NULL
79
+ );
80
+
81
+ CREATE TABLE app_groups (
82
+ id text PRIMARY KEY,
83
+ environment_id text NOT NULL,
84
+ name text NOT NULL,
85
+ created_at timestamptz NOT NULL
86
+ );
87
+
88
+ CREATE TABLE app_group_members (
89
+ id text PRIMARY KEY,
90
+ environment_id text NOT NULL,
91
+ group_id text NOT NULL REFERENCES app_groups (id),
92
+ identity_id text NOT NULL,
93
+ created_at timestamptz NOT NULL,
94
+ UNIQUE (group_id, identity_id)
95
+ );
96
+
97
+ CREATE TABLE app_role_bindings (
98
+ id text PRIMARY KEY,
99
+ environment_id text NOT NULL,
100
+ role_id text NOT NULL,
101
+ subject_type text NOT NULL,
102
+ subject_id text NOT NULL,
103
+ organization_id text,
104
+ resource text,
105
+ created_at timestamptz NOT NULL
106
+ );
107
+
108
+ CREATE INDEX app_role_bindings_environment_idx ON app_role_bindings (environment_id);
109
+
110
+ CREATE TABLE app_features (
111
+ id text PRIMARY KEY,
112
+ environment_id text NOT NULL,
113
+ key text NOT NULL,
114
+ enabled boolean NOT NULL,
115
+ config jsonb NOT NULL DEFAULT '{}',
116
+ created_at timestamptz NOT NULL,
117
+ UNIQUE (environment_id, key)
118
+ );
119
+
120
+ CREATE TABLE app_feature_assignments (
121
+ id text PRIMARY KEY,
122
+ environment_id text NOT NULL,
123
+ feature_id text NOT NULL REFERENCES app_features (id),
124
+ target_type text NOT NULL,
125
+ target_id text,
126
+ enabled boolean NOT NULL,
127
+ feature_limit integer,
128
+ config jsonb NOT NULL DEFAULT '{}',
129
+ created_at timestamptz NOT NULL
130
+ );
131
+
132
+ CREATE INDEX app_feature_assignments_environment_idx ON app_feature_assignments (environment_id);
133
+
134
+ CREATE TABLE app_waitlist (
135
+ id text PRIMARY KEY,
136
+ app_id text NOT NULL,
137
+ environment_id text NOT NULL,
138
+ email text NOT NULL,
139
+ status text NOT NULL,
140
+ token_hash text,
141
+ created_at timestamptz NOT NULL,
142
+ UNIQUE (environment_id, email)
143
+ );
144
+
145
+ CREATE TABLE directory_challenges (
146
+ id text PRIMARY KEY,
147
+ environment_id text NOT NULL,
148
+ identity_id text NOT NULL,
149
+ purpose text NOT NULL,
150
+ email text NOT NULL,
151
+ token_hash text NOT NULL UNIQUE,
152
+ expires_at timestamptz NOT NULL,
153
+ used_at timestamptz,
154
+ created_at timestamptz NOT NULL
155
+ );
@@ -0,0 +1,40 @@
1
+ ALTER TABLE users ALTER COLUMN password_hash DROP NOT NULL;
2
+
3
+ CREATE TABLE platform_sign_in (
4
+ id text PRIMARY KEY,
5
+ provider text NOT NULL UNIQUE,
6
+ client_id text NOT NULL,
7
+ client_secret_enc text NOT NULL,
8
+ directory_id text,
9
+ issuer text,
10
+ created_at timestamptz NOT NULL
11
+ );
12
+
13
+ CREATE TABLE account_identities (
14
+ id text PRIMARY KEY,
15
+ user_id text NOT NULL REFERENCES users (id),
16
+ provider text NOT NULL,
17
+ subject text NOT NULL,
18
+ email text,
19
+ created_at timestamptz NOT NULL,
20
+ UNIQUE (provider, subject),
21
+ UNIQUE (user_id, provider)
22
+ );
23
+
24
+ CREATE TABLE account_sso_logins (
25
+ id text PRIMARY KEY,
26
+ state_hash text NOT NULL UNIQUE,
27
+ nonce text NOT NULL,
28
+ verifier text NOT NULL,
29
+ provider text NOT NULL,
30
+ expires_at timestamptz NOT NULL,
31
+ created_at timestamptz NOT NULL
32
+ );
33
+
34
+ CREATE TABLE account_handoffs (
35
+ id text PRIMARY KEY,
36
+ code_hash text NOT NULL UNIQUE,
37
+ session_token text NOT NULL,
38
+ expires_at timestamptz NOT NULL,
39
+ created_at timestamptz NOT NULL
40
+ );
@@ -0,0 +1,26 @@
1
+ CREATE TABLE app_sign_in_connections (
2
+ id text PRIMARY KEY,
3
+ app_id text NOT NULL REFERENCES applications (id) ON DELETE CASCADE,
4
+ provider text NOT NULL,
5
+ client_id text NOT NULL,
6
+ client_secret_enc text NOT NULL,
7
+ directory_id text,
8
+ issuer text,
9
+ created_at timestamptz NOT NULL,
10
+ legacy_connection_id text,
11
+ UNIQUE (app_id, provider)
12
+ );
13
+
14
+ -- Retain the tenant registry so the previous release can still read its data.
15
+ -- An explicit app/provider selection is required before copying a credential.
16
+ -- Preserve legacy identity authority independently of the new row identifier.
17
+ INSERT INTO app_sign_in_connections (
18
+ id, app_id, provider, client_id, client_secret_enc, directory_id, issuer, created_at, legacy_connection_id
19
+ )
20
+ SELECT
21
+ concat('sic_migrated_', length(connection.id), ':', connection.id, ':', application.id),
22
+ application.id, connection.provider, connection.client_id, connection.client_secret_enc,
23
+ connection.directory_id, connection.issuer, connection.created_at, connection.id
24
+ FROM sign_in_connections AS connection
25
+ JOIN applications AS application ON application.org_id = connection.org_id
26
+ JOIN app_sign_in AS settings ON settings.app_id = application.id AND connection.provider = ANY(settings.providers);
@@ -0,0 +1,4 @@
1
+ ALTER TABLE account_sso_logins
2
+ ADD COLUMN next_path text,
3
+ ADD COLUMN link_user_id text REFERENCES users (id),
4
+ ADD COLUMN link_session_hash text;
@@ -0,0 +1,14 @@
1
+ CREATE TABLE account_sso_profiles (
2
+ id text PRIMARY KEY,
3
+ code_hash text NOT NULL UNIQUE,
4
+ browser_hash text NOT NULL,
5
+ provider text NOT NULL,
6
+ connection_fingerprint text NOT NULL,
7
+ subject text NOT NULL,
8
+ email text NOT NULL,
9
+ next_path text,
10
+ expires_at timestamptz NOT NULL,
11
+ created_at timestamptz NOT NULL
12
+ );
13
+
14
+ CREATE INDEX account_sso_profiles_expiry_idx ON account_sso_profiles (expires_at);
@@ -0,0 +1,26 @@
1
+ CREATE TABLE hosted_sso_profiles (
2
+ id text PRIMARY KEY,
3
+ challenge_hash text NOT NULL UNIQUE,
4
+ browser_hash text NOT NULL,
5
+ app_id text NOT NULL REFERENCES applications (id),
6
+ environment_id text NOT NULL REFERENCES app_environments (id),
7
+ org_id text NOT NULL,
8
+ provider text NOT NULL,
9
+ authority text NOT NULL,
10
+ subject text NOT NULL,
11
+ email text,
12
+ redirect_uri text NOT NULL,
13
+ app_state text,
14
+ expires_at timestamptz NOT NULL,
15
+ created_at timestamptz NOT NULL
16
+ );
17
+
18
+ CREATE INDEX hosted_sso_profiles_expiration_idx ON hosted_sso_profiles (expires_at);
19
+
20
+ CREATE TABLE hosted_sso_identities (
21
+ environment_id text NOT NULL REFERENCES app_environments (id),
22
+ authority text NOT NULL,
23
+ subject text NOT NULL,
24
+ identity_id text NOT NULL REFERENCES app_identities (id),
25
+ PRIMARY KEY (environment_id, authority, subject)
26
+ );
@@ -0,0 +1,2 @@
1
+ ALTER TABLE app_environments
2
+ ADD COLUMN default_signup_role_id text REFERENCES app_product_roles (id) ON DELETE SET NULL;
@@ -0,0 +1,14 @@
1
+ CREATE TABLE tenant_product_roles (
2
+ id text PRIMARY KEY,
3
+ org_id text NOT NULL REFERENCES orgs (id),
4
+ name text NOT NULL,
5
+ description text NOT NULL,
6
+ created_at timestamptz NOT NULL
7
+ );
8
+
9
+ CREATE UNIQUE INDEX tenant_product_roles_name_idx ON tenant_product_roles (org_id, lower(name));
10
+
11
+ ALTER TABLE app_product_roles ADD COLUMN catalog_role_id text REFERENCES tenant_product_roles (id);
12
+
13
+ CREATE UNIQUE INDEX app_product_roles_catalog_idx ON app_product_roles (environment_id, catalog_role_id)
14
+ WHERE catalog_role_id IS NOT NULL;
@@ -0,0 +1,21 @@
1
+ ALTER TABLE applications ADD CONSTRAINT applications_id_org_unique UNIQUE (id, org_id);
2
+
3
+ ALTER TABLE app_environments ADD CONSTRAINT app_environments_id_app_org_unique UNIQUE (id, app_id, org_id);
4
+
5
+ CREATE TABLE app_staff_access (
6
+ id text PRIMARY KEY,
7
+ org_id text NOT NULL,
8
+ app_id text NOT NULL,
9
+ environment_id text NOT NULL,
10
+ user_id text NOT NULL,
11
+ design boolean NOT NULL,
12
+ runtime text NOT NULL CHECK (runtime IN ('none', 'read', 'manage')),
13
+ created_at timestamptz NOT NULL,
14
+ updated_at timestamptz NOT NULL,
15
+ UNIQUE (environment_id, user_id),
16
+ FOREIGN KEY (org_id, user_id) REFERENCES memberships (org_id, user_id) ON DELETE CASCADE,
17
+ FOREIGN KEY (app_id, org_id) REFERENCES applications (id, org_id),
18
+ FOREIGN KEY (environment_id, app_id, org_id) REFERENCES app_environments (id, app_id, org_id) ON DELETE CASCADE
19
+ );
20
+
21
+ CREATE INDEX app_staff_access_org_user_idx ON app_staff_access (org_id, user_id);
@@ -0,0 +1,7 @@
1
+ ALTER TABLE service_credentials ADD CONSTRAINT service_credentials_org_id_unique UNIQUE (org_id, id);
2
+
3
+ ALTER TABLE audit_events ADD COLUMN actor_service_id text;
4
+ ALTER TABLE audit_events ADD CONSTRAINT audit_events_service_actor_fk
5
+ FOREIGN KEY (org_id, actor_service_id) REFERENCES service_credentials (org_id, id);
6
+ ALTER TABLE audit_events ADD CONSTRAINT audit_events_service_actor_scope
7
+ CHECK (actor_service_id IS NULL OR (org_id IS NOT NULL AND actor_user_id IS NULL AND agent_id IS NULL));
@@ -0,0 +1,2 @@
1
+ ALTER TABLE applications ADD COLUMN waitlist_questions text[] NOT NULL DEFAULT ARRAY[]::text[];
2
+ ALTER TABLE app_waitlist ADD COLUMN answers jsonb NOT NULL DEFAULT '[]'::jsonb;
@@ -0,0 +1,9 @@
1
+ ALTER TABLE applications ADD COLUMN signup_audience text NOT NULL DEFAULT 'any-email'
2
+ CHECK (signup_audience IN ('any-email', 'business-or-sso'));
3
+
4
+ ALTER TABLE applications ADD COLUMN signup_sso_providers text[] NOT NULL DEFAULT '{}';
5
+
6
+ ALTER TABLE applications ADD COLUMN signup_organization text NOT NULL DEFAULT 'required'
7
+ CHECK (signup_organization IN ('required', 'optional'));
8
+
9
+ ALTER TABLE app_product_roles ADD COLUMN allows_organizationless_signup boolean NOT NULL DEFAULT false;
@@ -0,0 +1,8 @@
1
+ ALTER TABLE applications ADD COLUMN managed_sign_in boolean NOT NULL DEFAULT true;
2
+
3
+ ALTER TABLE platform_sign_in ADD COLUMN managed_for_apps boolean NOT NULL DEFAULT false;
4
+
5
+ ALTER TABLE platform_sign_in ADD CONSTRAINT platform_sign_in_managed_provider_check
6
+ CHECK (NOT managed_for_apps OR (provider <> 'oidc' AND (provider <> 'microsoft' OR directory_id IS NOT DISTINCT FROM 'common')));
7
+
8
+ ALTER TABLE sso_logins ADD COLUMN connection_authority text;
@@ -0,0 +1,12 @@
1
+ ALTER TABLE hosted_sso_profiles ADD COLUMN display_name text;
2
+
3
+ ALTER TABLE hosted_sso_profiles ADD COLUMN connection_fingerprint text;
4
+
5
+ CREATE TABLE hosted_sso_email_proofs (
6
+ profile_id text PRIMARY KEY REFERENCES hosted_sso_profiles (id) ON DELETE CASCADE,
7
+ token_hash text NOT NULL UNIQUE,
8
+ email text NOT NULL,
9
+ created_at timestamptz NOT NULL,
10
+ expires_at timestamptz NOT NULL,
11
+ CHECK (expires_at > created_at)
12
+ );
@@ -0,0 +1,15 @@
1
+ CREATE TABLE cli_login_codes (
2
+ code_hash text PRIMARY KEY,
3
+ request_hash text NOT NULL UNIQUE,
4
+ code_challenge text NOT NULL,
5
+ redirect_uri text NOT NULL,
6
+ user_id text NOT NULL REFERENCES users (id) ON DELETE CASCADE,
7
+ org_id text NOT NULL REFERENCES orgs (id) ON DELETE CASCADE,
8
+ browser_session_hash text NOT NULL REFERENCES sessions (secret_hash) ON DELETE CASCADE,
9
+ expires_at timestamptz NOT NULL,
10
+ created_at timestamptz NOT NULL,
11
+ consumed_at timestamptz,
12
+ CHECK (expires_at > created_at)
13
+ );
14
+ CREATE INDEX cli_login_codes_expiry_idx ON cli_login_codes (expires_at);
15
+ CREATE INDEX cli_login_codes_browser_session_idx ON cli_login_codes (browser_session_hash);
@@ -0,0 +1,18 @@
1
+ CREATE TABLE hosted_email_codes (
2
+ environment_id text NOT NULL REFERENCES app_environments (id) ON DELETE CASCADE,
3
+ email text NOT NULL,
4
+ id text NOT NULL,
5
+ challenge_hash text NOT NULL UNIQUE,
6
+ code_hash text NOT NULL,
7
+ created_at timestamptz NOT NULL,
8
+ expires_at timestamptz NOT NULL,
9
+ send_history timestamptz[] NOT NULL,
10
+ attempts_remaining integer NOT NULL,
11
+ consumed_at timestamptz,
12
+ PRIMARY KEY (environment_id, email),
13
+ CHECK (email = lower(email)),
14
+ CHECK (expires_at > created_at),
15
+ CHECK (attempts_remaining >= 0)
16
+ );
17
+
18
+ CREATE INDEX hosted_email_codes_created_at_idx ON hosted_email_codes (created_at);
@@ -0,0 +1,3 @@
1
+ ALTER TABLE sso_logins ADD COLUMN waitlist_in_app boolean NOT NULL DEFAULT false;
2
+
3
+ ALTER TABLE hosted_sso_profiles ADD COLUMN waitlist_in_app boolean NOT NULL DEFAULT false;
@@ -0,0 +1 @@
1
+ ALTER TABLE applications ADD COLUMN email_code_sign_in boolean NOT NULL DEFAULT false;
@@ -0,0 +1,2 @@
1
+ ALTER TABLE applications ADD COLUMN auth_copy jsonb NOT NULL DEFAULT '{}'::jsonb
2
+ CHECK (jsonb_typeof(auth_copy) = 'object');
@@ -0,0 +1,55 @@
1
+ ALTER TABLE applications
2
+ ADD COLUMN directory_model text NOT NULL DEFAULT 'organizations'
3
+ CHECK (directory_model IN ('organizations', 'workspaces', 'organizations-and-workspaces')),
4
+ ADD COLUMN directory_labels jsonb NOT NULL DEFAULT '{}'::jsonb
5
+ CHECK (jsonb_typeof(directory_labels) = 'object'),
6
+ ADD COLUMN onboarding jsonb NOT NULL DEFAULT '{}'::jsonb
7
+ CHECK (jsonb_typeof(onboarding) = 'object');
8
+
9
+ ALTER TABLE app_environments ADD UNIQUE (app_id, id);
10
+
11
+ ALTER TABLE app_identities ADD UNIQUE (environment_id, id);
12
+
13
+ CREATE TABLE app_workspaces (
14
+ id text PRIMARY KEY,
15
+ app_id text NOT NULL,
16
+ environment_id text NOT NULL,
17
+ organization_id text,
18
+ name text NOT NULL CHECK (length(btrim(name)) > 0),
19
+ status text NOT NULL CHECK (status IN ('active', 'disabled')),
20
+ created_at timestamptz NOT NULL,
21
+ updated_at timestamptz NOT NULL,
22
+ UNIQUE (environment_id, id),
23
+ FOREIGN KEY (app_id, environment_id) REFERENCES app_environments (app_id, id),
24
+ FOREIGN KEY (environment_id, organization_id) REFERENCES app_identities (environment_id, id)
25
+ );
26
+
27
+ CREATE INDEX app_workspaces_app_idx ON app_workspaces (app_id);
28
+
29
+ CREATE TABLE app_workspace_memberships (
30
+ id text PRIMARY KEY,
31
+ environment_id text NOT NULL,
32
+ workspace_id text NOT NULL,
33
+ identity_id text NOT NULL,
34
+ relation text NOT NULL CHECK (relation IN ('owner', 'member')),
35
+ created_at timestamptz NOT NULL,
36
+ UNIQUE (environment_id, workspace_id, identity_id),
37
+ FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id),
38
+ FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id)
39
+ );
40
+
41
+ CREATE INDEX app_workspace_memberships_identity_idx ON app_workspace_memberships (environment_id, identity_id);
42
+
43
+ CREATE TABLE app_onboarding_responses (
44
+ environment_id text NOT NULL,
45
+ target text NOT NULL CHECK (target IN ('user', 'organization', 'workspace')),
46
+ subject_id text NOT NULL,
47
+ identity_id text GENERATED ALWAYS AS (CASE WHEN target <> 'workspace' THEN subject_id END) STORED,
48
+ workspace_id text GENERATED ALWAYS AS (CASE WHEN target = 'workspace' THEN subject_id END) STORED,
49
+ questions jsonb NOT NULL CHECK (jsonb_typeof(questions) = 'array'),
50
+ answers jsonb NOT NULL CHECK (jsonb_typeof(answers) = 'object'),
51
+ updated_at timestamptz NOT NULL,
52
+ PRIMARY KEY (environment_id, target, subject_id),
53
+ FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id),
54
+ FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id)
55
+ );
@@ -0,0 +1,17 @@
1
+ ALTER TABLE app_features ADD COLUMN kind text NOT NULL DEFAULT 'feature'
2
+ CHECK (kind IN ('feature', 'configuration'));
3
+
4
+ ALTER TABLE app_features ADD CONSTRAINT app_features_environment_id_id_key UNIQUE (environment_id, id);
5
+ ALTER TABLE app_product_roles ADD CONSTRAINT app_product_roles_environment_id_id_key UNIQUE (environment_id, id);
6
+
7
+ ALTER TABLE app_feature_assignments DROP CONSTRAINT app_feature_assignments_feature_id_fkey;
8
+ ALTER TABLE app_feature_assignments
9
+ ADD CONSTRAINT app_feature_assignment_definition_environment_fk FOREIGN KEY (environment_id, feature_id)
10
+ REFERENCES app_features (environment_id, id) ON DELETE CASCADE,
11
+ ADD COLUMN role_target_id text GENERATED ALWAYS AS (CASE WHEN target_type = 'role' THEN target_id END) STORED,
12
+ ADD CONSTRAINT app_feature_assignment_role_target CHECK (target_type <> 'role' OR target_id IS NOT NULL),
13
+ ADD CONSTRAINT app_feature_assignment_role_environment_fk FOREIGN KEY (environment_id, role_target_id)
14
+ REFERENCES app_product_roles (environment_id, id) ON DELETE CASCADE;
15
+
16
+ CREATE UNIQUE INDEX app_feature_assignment_role_definition_idx
17
+ ON app_feature_assignments (environment_id, role_target_id, feature_id) WHERE role_target_id IS NOT NULL;
@@ -0,0 +1,4 @@
1
+ ALTER TABLE applications DROP CONSTRAINT applications_signup_audience_check;
2
+
3
+ ALTER TABLE applications ADD CONSTRAINT applications_signup_audience_check
4
+ CHECK (signup_audience IN ('any-email', 'business-or-sso', 'sso-only'));
@@ -0,0 +1,3 @@
1
+ ALTER TABLE applications DROP CONSTRAINT applications_directory_model_check;
2
+ ALTER TABLE applications ADD CONSTRAINT applications_directory_model_check
3
+ CHECK (directory_model IN ('organizations', 'workspaces', 'organizations-and-workspaces', 'people-only'));
@@ -0,0 +1,3 @@
1
+ ALTER TABLE applications
2
+ ADD COLUMN waitlist_question_definitions jsonb CHECK (jsonb_typeof(waitlist_question_definitions) = 'array'),
3
+ ADD COLUMN waitlist_question_layout text NOT NULL DEFAULT 'form' CHECK (waitlist_question_layout IN ('form', 'wizard'));
@@ -0,0 +1,22 @@
1
+ CREATE TABLE app_notification_settings (
2
+ environment_id text PRIMARY KEY REFERENCES app_environments (id),
3
+ app_id text NOT NULL REFERENCES applications (id),
4
+ org_id text NOT NULL REFERENCES orgs (id),
5
+ delivery text NOT NULL CHECK (delivery IN ('keyrox', 'both', 'webhook')),
6
+ templates jsonb NOT NULL,
7
+ updated_at timestamptz NOT NULL
8
+ );
9
+
10
+ CREATE TABLE app_notification_webhooks (
11
+ id text PRIMARY KEY,
12
+ environment_id text NOT NULL REFERENCES app_environments (id),
13
+ app_id text NOT NULL REFERENCES applications (id),
14
+ org_id text NOT NULL REFERENCES orgs (id),
15
+ url text NOT NULL,
16
+ secret_enc text NOT NULL,
17
+ enabled boolean NOT NULL,
18
+ created_at timestamptz NOT NULL,
19
+ updated_at timestamptz NOT NULL
20
+ );
21
+
22
+ CREATE INDEX app_notification_webhooks_environment_idx ON app_notification_webhooks (environment_id, created_at);
@@ -0,0 +1,10 @@
1
+ -- Upgrade the former default while keeping any tenant limit an owner explicitly set.
2
+ UPDATE orgs
3
+ SET grant_max_days = 730, policy_version = policy_version + 1
4
+ WHERE grant_max_days = 90
5
+ AND NOT EXISTS (
6
+ SELECT 1 FROM audit_events
7
+ WHERE audit_events.org_id = orgs.id
8
+ AND audit_events.action = 'org.policy.update'
9
+ AND audit_events.detail LIKE '%grantMaxDays%'
10
+ );
@@ -0,0 +1,67 @@
1
+ ALTER TABLE applications ADD COLUMN trashed_at timestamptz;
2
+
3
+ CREATE INDEX applications_trash_idx ON applications (org_id, trashed_at DESC, id DESC)
4
+ WHERE trashed_at IS NOT NULL;
5
+
6
+ CREATE TABLE application_logo_purge (
7
+ app_id text PRIMARY KEY
8
+ );
9
+
10
+ ALTER TABLE app_environments DROP CONSTRAINT app_environments_app_id_fkey,
11
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE;
12
+ ALTER TABLE app_tokens DROP CONSTRAINT app_tokens_app_id_fkey, DROP CONSTRAINT app_tokens_environment_fk,
13
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
14
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
15
+ ALTER TABLE app_sign_in DROP CONSTRAINT app_sign_in_app_id_fkey,
16
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE;
17
+ ALTER TABLE environment_redirects DROP CONSTRAINT environment_redirects_environment_id_fkey,
18
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
19
+ ALTER TABLE sso_logins DROP CONSTRAINT sso_logins_app_id_fkey, DROP CONSTRAINT sso_logins_environment_id_fkey,
20
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
21
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
22
+ ALTER TABLE audiences DROP CONSTRAINT audiences_app_id_fkey,
23
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE;
24
+ ALTER TABLE gateway_routes DROP CONSTRAINT gateway_routes_audience_id_fkey,
25
+ ADD FOREIGN KEY (audience_id) REFERENCES audiences (id) ON DELETE CASCADE;
26
+ ALTER TABLE app_identities DROP CONSTRAINT app_identities_app_id_fkey, DROP CONSTRAINT app_identities_environment_id_fkey,
27
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
28
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
29
+ ALTER TABLE app_identity_memberships DROP CONSTRAINT app_identity_memberships_identity_id_fkey,
30
+ ADD FOREIGN KEY (identity_id) REFERENCES app_identities (id) ON DELETE CASCADE;
31
+ ALTER TABLE app_group_members DROP CONSTRAINT app_group_members_group_id_fkey,
32
+ ADD FOREIGN KEY (group_id) REFERENCES app_groups (id) ON DELETE CASCADE;
33
+ ALTER TABLE hosted_sso_profiles DROP CONSTRAINT hosted_sso_profiles_app_id_fkey, DROP CONSTRAINT hosted_sso_profiles_environment_id_fkey,
34
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
35
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
36
+ ALTER TABLE hosted_sso_identities DROP CONSTRAINT hosted_sso_identities_environment_id_fkey, DROP CONSTRAINT hosted_sso_identities_identity_id_fkey,
37
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE,
38
+ ADD FOREIGN KEY (identity_id) REFERENCES app_identities (id) ON DELETE CASCADE;
39
+ ALTER TABLE app_staff_access DROP CONSTRAINT app_staff_access_app_id_org_id_fkey,
40
+ ADD FOREIGN KEY (app_id, org_id) REFERENCES applications (id, org_id) ON DELETE CASCADE;
41
+ ALTER TABLE app_workspaces DROP CONSTRAINT app_workspaces_app_id_environment_id_fkey, DROP CONSTRAINT app_workspaces_environment_id_organization_id_fkey,
42
+ ADD FOREIGN KEY (app_id, environment_id) REFERENCES app_environments (app_id, id) ON DELETE CASCADE,
43
+ ADD FOREIGN KEY (environment_id, organization_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE;
44
+ ALTER TABLE app_workspace_memberships DROP CONSTRAINT app_workspace_memberships_environment_id_workspace_id_fkey,
45
+ DROP CONSTRAINT app_workspace_memberships_environment_id_identity_id_fkey,
46
+ ADD FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id) ON DELETE CASCADE,
47
+ ADD FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE;
48
+ ALTER TABLE app_onboarding_responses DROP CONSTRAINT app_onboarding_responses_environment_id_identity_id_fkey,
49
+ DROP CONSTRAINT app_onboarding_responses_environment_id_workspace_id_fkey,
50
+ ADD FOREIGN KEY (environment_id, identity_id) REFERENCES app_identities (environment_id, id) ON DELETE CASCADE,
51
+ ADD FOREIGN KEY (environment_id, workspace_id) REFERENCES app_workspaces (environment_id, id) ON DELETE CASCADE;
52
+ ALTER TABLE app_notification_settings DROP CONSTRAINT app_notification_settings_app_id_fkey,
53
+ DROP CONSTRAINT app_notification_settings_environment_id_fkey,
54
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
55
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
56
+ ALTER TABLE app_notification_webhooks DROP CONSTRAINT app_notification_webhooks_app_id_fkey,
57
+ DROP CONSTRAINT app_notification_webhooks_environment_id_fkey,
58
+ ADD FOREIGN KEY (app_id) REFERENCES applications (id) ON DELETE CASCADE,
59
+ ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE;
60
+
61
+ -- Keep legacy rows readable and enforce their environment reference on new writes.
62
+ ALTER TABLE app_permissions ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
63
+ ALTER TABLE app_product_roles ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
64
+ ALTER TABLE app_groups ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
65
+ ALTER TABLE app_role_bindings ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
66
+ ALTER TABLE app_features ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
67
+ ALTER TABLE app_waitlist ADD FOREIGN KEY (environment_id) REFERENCES app_environments (id) ON DELETE CASCADE NOT VALID;
@@ -0,0 +1,25 @@
1
+ CREATE TABLE notification_deliveries (
2
+ message_id text PRIMARY KEY,
3
+ organization_id text NOT NULL,
4
+ environment_id text,
5
+ environment_key_version integer,
6
+ type text NOT NULL,
7
+ status text NOT NULL CHECK (status IN ('pending','queued','sending','provider_accepted','delivered','failed','bounced','complained','suppressed','cancelled','expired')),
8
+ payload_enc text,
9
+ created_at timestamptz NOT NULL,
10
+ updated_at timestamptz NOT NULL,
11
+ expires_at timestamptz NOT NULL,
12
+ accepted_at timestamptz,
13
+ failure_code text,
14
+ attempts integer NOT NULL DEFAULT 0,
15
+ next_attempt_at timestamptz,
16
+ lease_id text,
17
+ lease_until timestamptz,
18
+ CHECK ((environment_id IS NULL) = (environment_key_version IS NULL)),
19
+ CHECK ((lease_id IS NULL) = (lease_until IS NULL))
20
+ );
21
+
22
+ CREATE INDEX notification_deliveries_due ON notification_deliveries (next_attempt_at, created_at) WHERE next_attempt_at IS NOT NULL;
23
+ CREATE INDEX notification_deliveries_scope ON notification_deliveries (organization_id, environment_id, created_at DESC, message_id DESC);
24
+ CREATE INDEX notification_deliveries_cleanup ON notification_deliveries (updated_at) WHERE next_attempt_at IS NULL;
25
+
@@ -0,0 +1,28 @@
1
+ CREATE TABLE app_notification_webhook_jobs (
2
+ id text PRIMARY KEY,
3
+ event_id text NOT NULL,
4
+ webhook_id text NOT NULL,
5
+ organization_id text NOT NULL,
6
+ app_id text NOT NULL,
7
+ environment_id text NOT NULL REFERENCES app_environments (id) ON DELETE CASCADE,
8
+ environment_key_version integer NOT NULL,
9
+ type text NOT NULL,
10
+ body_enc text,
11
+ keyrox_delivery boolean NOT NULL,
12
+ status text NOT NULL CHECK (status IN ('queued', 'accepted', 'failed', 'expired', 'cancelled')),
13
+ attempt_count integer NOT NULL DEFAULT 0,
14
+ last_http_status integer,
15
+ failure_code text,
16
+ created_at timestamptz NOT NULL,
17
+ updated_at timestamptz NOT NULL,
18
+ expires_at timestamptz NOT NULL,
19
+ next_attempt_at timestamptz,
20
+ lease_token text,
21
+ leased_until timestamptz
22
+ );
23
+
24
+ CREATE INDEX app_notification_webhook_jobs_due_idx ON app_notification_webhook_jobs (next_attempt_at, id) WHERE status = 'queued';
25
+ CREATE INDEX app_notification_webhook_jobs_event_idx ON app_notification_webhook_jobs (event_id) WHERE status = 'queued';
26
+ CREATE INDEX app_notification_webhook_jobs_activity_idx ON app_notification_webhook_jobs (environment_id, organization_id, created_at DESC, id DESC);
27
+ CREATE INDEX app_notification_webhook_jobs_content_expiry_idx ON app_notification_webhook_jobs (expires_at) WHERE body_enc IS NOT NULL;
28
+ CREATE INDEX app_notification_webhook_jobs_retention_idx ON app_notification_webhook_jobs (updated_at) WHERE body_enc IS NULL;