Skip to content

Commit 4f4bf1d

Browse files
committed
feat: add membership_type column to storage_module for multi-scope storage
- Add membership_type int column (NULL = app-level AuthzMembership, non-NULL = entity-scoped AuthzEntityMembership) - Rename default table names from buckets/files/upload_requests to app_buckets/app_files/app_upload_requests - Add unique index on (database_id, COALESCE(membership_type, -1)) to enforce one module per scope - Update entity_table_id comment to reflect app-level vs entity-scoped usage Syncs with constructive-db PR #876 (merged).
1 parent f79dd69 commit 4f4bf1d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

  • packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/storage_module

packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/storage_module/table.sql

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ CREATE TABLE metaschema_modules_public.storage_module (
1818
upload_requests_table_id uuid NOT NULL DEFAULT uuid_nil(),
1919

2020
-- Table names (input to the generator)
21-
buckets_table_name text NOT NULL DEFAULT 'buckets',
22-
files_table_name text NOT NULL DEFAULT 'files',
23-
upload_requests_table_name text NOT NULL DEFAULT 'upload_requests',
21+
buckets_table_name text NOT NULL DEFAULT 'app_buckets',
22+
files_table_name text NOT NULL DEFAULT 'app_files',
23+
upload_requests_table_name text NOT NULL DEFAULT 'app_upload_requests',
2424

25-
-- Entity table for RLS (users table, since users and orgs share it)
25+
-- Multi-tenant storage identity
26+
membership_type int DEFAULT NULL, -- NULL = global gate (AuthzMembership via app_sprt), non-NULL = entity-scoped (AuthzEntityMembership)
27+
28+
-- Entity table for RLS (NULL for app-level storage, entity table for entity-scoped storage)
2629
entity_table_id uuid NULL,
2730

2831
-- S3 connection config (NULL = use global env/plugin defaults)
@@ -52,4 +55,8 @@ CREATE TABLE metaschema_modules_public.storage_module (
5255

5356
CREATE INDEX storage_module_database_id_idx ON metaschema_modules_public.storage_module ( database_id );
5457

58+
-- Unique constraint on (database_id, membership_type) using COALESCE to handle NULLs.
59+
-- NULL membership_type = app-level (only one per database), non-NULL = entity-scoped (one per membership_type per database).
60+
CREATE UNIQUE INDEX storage_module_unique_scope ON metaschema_modules_public.storage_module ( database_id, COALESCE(membership_type, -1) );
61+
5562
COMMIT;

0 commit comments

Comments
 (0)