diff --git a/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap b/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap index ff24151c..4de23994 100644 --- a/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap +++ b/packages/metaschema-modules/__tests__/__snapshots__/modules.test.ts.snap @@ -21,9 +21,9 @@ exports[`db_meta_modules should have all expected module tables 1`] = ` "profiles_module", "rls_module", "secrets_module", + "sessions_module", "table_module", "table_template_module", - "tokens_module", "user_auth_module", "users_module", "uuid_module", @@ -87,6 +87,67 @@ exports[`db_meta_modules should verify emails_module table structure 1`] = ` } `; +exports[`db_meta_modules should verify field_module table structure 1`] = ` +{ + "columns": [ + { + "column_default": "uuid_generate_v4()", + "column_name": "id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "database_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "private_schema_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "field_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "node_type", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": "'{}'::jsonb", + "column_name": "data", + "data_type": "jsonb", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "triggers", + "data_type": "ARRAY", + "is_nullable": "YES", + }, + { + "column_default": null, + "column_name": "functions", + "data_type": "ARRAY", + "is_nullable": "YES", + }, + ], +} +`; + exports[`db_meta_modules should verify module table structures have database_id foreign keys 1`] = ` { "constraintCount": 69984, @@ -95,7 +156,7 @@ exports[`db_meta_modules should verify module table structures have database_id exports[`db_meta_modules should verify module tables have proper foreign key relationships 1`] = ` { - "constraintCount": 99629, + "constraintCount": 98022, "foreignTables": [ "apis", "database", @@ -108,30 +169,46 @@ exports[`db_meta_modules should verify module tables have proper foreign key rel exports[`db_meta_modules should verify specific module table column defaults 1`] = ` { - "tokensDefaults": [ + "sessionsDefaults": [ { - "column_default": "uuid_generate_v4()", - "column_name": "id", + "column_default": "'app_auth_settings'::text", + "column_name": "auth_settings_table", }, { "column_default": "uuid_nil()", - "column_name": "owned_table_id", + "column_name": "auth_settings_table_id", + }, + { + "column_default": "uuid_generate_v4()", + "column_name": "id", }, { "column_default": "uuid_nil()", "column_name": "schema_id", }, + { + "column_default": "'session_credentials'::text", + "column_name": "session_credentials_table", + }, { "column_default": "uuid_nil()", - "column_name": "table_id", + "column_name": "session_credentials_table_id", + }, + { + "column_default": "'30 days'::interval", + "column_name": "sessions_default_expiration", }, { - "column_default": "'3 days'::interval", - "column_name": "tokens_default_expiration", + "column_default": "'sessions'::text", + "column_name": "sessions_table", }, { - "column_default": "'api_tokens'::text", - "column_name": "tokens_table", + "column_default": "uuid_nil()", + "column_name": "sessions_table_id", + }, + { + "column_default": "uuid_nil()", + "column_name": "users_table_id", }, ], "usersDefaults": [ @@ -163,7 +240,56 @@ exports[`db_meta_modules should verify specific module table column defaults 1`] } `; -exports[`db_meta_modules should verify tokens_module table structure 1`] = ` +exports[`db_meta_modules should verify table_module table structure 1`] = ` +{ + "columns": [ + { + "column_default": "uuid_generate_v4()", + "column_name": "id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "database_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "private_schema_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "node_type", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": "'{}'::jsonb", + "column_name": "data", + "data_type": "jsonb", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "fields", + "data_type": "ARRAY", + "is_nullable": "YES", + }, + ], +} +`; + +exports[`db_meta_modules should verify table_template_module table structure 1`] = ` { "columns": [ { @@ -184,6 +310,12 @@ exports[`db_meta_modules should verify tokens_module table structure 1`] = ` "data_type": "uuid", "is_nullable": "NO", }, + { + "column_default": "uuid_nil()", + "column_name": "private_schema_id", + "data_type": "uuid", + "is_nullable": "NO", + }, { "column_default": "uuid_nil()", "column_name": "table_id", @@ -192,19 +324,98 @@ exports[`db_meta_modules should verify tokens_module table structure 1`] = ` }, { "column_default": "uuid_nil()", - "column_name": "owned_table_id", + "column_name": "owner_table_id", "data_type": "uuid", "is_nullable": "NO", }, { - "column_default": "'3 days'::interval", - "column_name": "tokens_default_expiration", + "column_default": null, + "column_name": "table_name", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "node_type", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": "'{}'::jsonb", + "column_name": "data", + "data_type": "jsonb", + "is_nullable": "NO", + }, + ], +} +`; + +exports[`db_meta_modules should verify sessions_module table structure 1`] = ` +{ + "columns": [ + { + "column_default": "uuid_generate_v4()", + "column_name": "id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": null, + "column_name": "database_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "schema_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "sessions_table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "session_credentials_table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "auth_settings_table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "uuid_nil()", + "column_name": "users_table_id", + "data_type": "uuid", + "is_nullable": "NO", + }, + { + "column_default": "'30 days'::interval", + "column_name": "sessions_default_expiration", "data_type": "interval", "is_nullable": "NO", }, { - "column_default": "'api_tokens'::text", - "column_name": "tokens_table", + "column_default": "'sessions'::text", + "column_name": "sessions_table", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": "'session_credentials'::text", + "column_name": "session_credentials_table", + "data_type": "text", + "is_nullable": "NO", + }, + { + "column_default": "'app_auth_settings'::text", + "column_name": "auth_settings_table", "data_type": "text", "is_nullable": "NO", }, diff --git a/packages/metaschema-modules/__tests__/modules.test.ts b/packages/metaschema-modules/__tests__/modules.test.ts index ed21d8bf..e202d0aa 100644 --- a/packages/metaschema-modules/__tests__/modules.test.ts +++ b/packages/metaschema-modules/__tests__/modules.test.ts @@ -21,30 +21,30 @@ describe('db_meta_modules', () => { }); it('should have all expected module tables', async () => { - const expectedModules = [ - 'connected_accounts_module', - 'crypto_addresses_module', - 'crypto_auth_module', - 'default_ids_module', - 'emails_module', - 'encrypted_secrets_module', - 'field_module', - 'hierarchy_module', - 'invites_module', - 'levels_module', - 'limits_module', - 'membership_types_module', - 'memberships_module', - 'permissions_module', - 'phone_numbers_module', - 'profiles_module', - 'rls_module', - 'secrets_module', - 'tokens_module', - 'user_auth_module', - 'users_module', - 'uuid_module' - ]; + const expectedModules = [ + 'connected_accounts_module', + 'crypto_addresses_module', + 'crypto_auth_module', + 'default_ids_module', + 'emails_module', + 'encrypted_secrets_module', + 'field_module', + 'invites_module', + 'levels_module', + 'limits_module', + 'membership_types_module', + 'memberships_module', + 'permissions_module', + 'phone_numbers_module', + 'rls_module', + 'secrets_module', + 'sessions_module', + 'table_module', + 'table_template_module', + 'user_auth_module', + 'users_module', + 'uuid_module' + ]; // Query for all module tables in metaschema_modules_public schema const moduleTables = await pg.any(` @@ -90,7 +90,7 @@ describe('db_meta_modules', () => { expect(snapshot({ columns })).toMatchSnapshot(); }); - it('should verify tokens_module table structure', async () => { + it('should verify sessions_module table structure', async () => { const columns = await pg.any(` SELECT column_name, @@ -99,7 +99,7 @@ describe('db_meta_modules', () => { column_default FROM information_schema.columns WHERE table_schema = 'metaschema_modules_public' - AND table_name = 'tokens_module' + AND table_name = 'sessions_module' ORDER BY ordinal_position `); @@ -108,9 +108,8 @@ describe('db_meta_modules', () => { expect(columnNames).toContain('id'); expect(columnNames).toContain('database_id'); expect(columnNames).toContain('schema_id'); - expect(columnNames).toContain('table_id'); - expect(columnNames).toContain('tokens_table'); - expect(columnNames).toContain('tokens_default_expiration'); + expect(columnNames).toContain('sessions_table'); + expect(columnNames).toContain('session_credentials_table'); expect(snapshot({ columns })).toMatchSnapshot(); }); @@ -193,51 +192,47 @@ describe('db_meta_modules', () => { })).toMatchSnapshot(); }); - it( - 'should verify module tables have proper foreign key relationships', - async () => { - // Get all foreign key constraints for module tables - const fkConstraints = await pg.any(` - SELECT - tc.table_name, - kcu.column_name, - ccu.table_name AS foreign_table_name, - ccu.column_name AS foreign_column_name - FROM information_schema.table_constraints AS tc - JOIN information_schema.key_column_usage AS kcu - ON tc.constraint_name = kcu.constraint_name - JOIN information_schema.constraint_column_usage AS ccu - ON ccu.constraint_name = tc.constraint_name - WHERE tc.table_schema = 'metaschema_modules_public' - AND tc.table_name LIKE '%_module' - AND tc.constraint_type = 'FOREIGN KEY' - ORDER BY tc.table_name, kcu.column_name - `); - - // Should have many foreign key relationships - expect(fkConstraints.length).toBeGreaterThan(20); - - // Group by foreign table to see what they reference - const foreignTables = [...new Set(fkConstraints.map(fk => fk.foreign_table_name))]; - expect(foreignTables).toContain('database'); - expect(foreignTables).toContain('schema'); - expect(foreignTables).toContain('table'); - - expect(snapshot({ - constraintCount: fkConstraints.length, - foreignTables: foreignTables.sort() - })).toMatchSnapshot(); - }, - 30000 - ); + it('should verify module tables have proper foreign key relationships', async () => { + // Get all foreign key constraints for module tables + const fkConstraints = await pg.any(` + SELECT + tc.table_name, + kcu.column_name, + ccu.table_name AS foreign_table_name, + ccu.column_name AS foreign_column_name + FROM information_schema.table_constraints AS tc + JOIN information_schema.key_column_usage AS kcu + ON tc.constraint_name = kcu.constraint_name + JOIN information_schema.constraint_column_usage AS ccu + ON ccu.constraint_name = tc.constraint_name + WHERE tc.table_schema = 'metaschema_modules_public' + AND tc.table_name LIKE '%_module' + AND tc.constraint_type = 'FOREIGN KEY' + ORDER BY tc.table_name, kcu.column_name + `); + + // Should have many foreign key relationships + expect(fkConstraints.length).toBeGreaterThan(20); + + // Group by foreign table to see what they reference + const foreignTables = [...new Set(fkConstraints.map(fk => fk.foreign_table_name))]; + expect(foreignTables).toContain('database'); + expect(foreignTables).toContain('schema'); + expect(foreignTables).toContain('table'); + + expect(snapshot({ + constraintCount: fkConstraints.length, + foreignTables: foreignTables.sort() + })).toMatchSnapshot(); + }, 30000); it('should verify specific module table column defaults', async () => { // Check that modules have sensible defaults - const tokensDefaults = await pg.any(` + const sessionsDefaults = await pg.any(` SELECT column_name, column_default FROM information_schema.columns WHERE table_schema = 'metaschema_modules_public' - AND table_name = 'tokens_module' + AND table_name = 'sessions_module' AND column_default IS NOT NULL ORDER BY column_name `); @@ -252,12 +247,96 @@ describe('db_meta_modules', () => { `); // Should have some default values set - expect(tokensDefaults.length).toBeGreaterThan(3); + expect(sessionsDefaults.length).toBeGreaterThan(3); expect(usersDefaults.length).toBeGreaterThan(3); expect(snapshot({ - tokensDefaults, + sessionsDefaults, usersDefaults })).toMatchSnapshot(); }); -}); \ No newline at end of file + + // Test for unified field_module with node_type + it('should verify field_module table structure', async () => { + const columns = await pg.any(` + SELECT + column_name, + data_type, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_schema = 'metaschema_modules_public' + AND table_name = 'field_module' + ORDER BY ordinal_position + `); + + // Check that key columns exist + const columnNames = columns.map(c => c.column_name); + expect(columnNames).toContain('id'); + expect(columnNames).toContain('database_id'); + expect(columnNames).toContain('table_id'); + expect(columnNames).toContain('field_id'); + expect(columnNames).toContain('node_type'); + expect(columnNames).toContain('data'); + expect(columnNames).toContain('triggers'); + expect(columnNames).toContain('functions'); + + expect(snapshot({ columns })).toMatchSnapshot(); + }); + + // Test for unified table_module with node_type + it('should verify table_module table structure', async () => { + const columns = await pg.any(` + SELECT + column_name, + data_type, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_schema = 'metaschema_modules_public' + AND table_name = 'table_module' + ORDER BY ordinal_position + `); + + // Check that key columns exist + const columnNames = columns.map(c => c.column_name); + expect(columnNames).toContain('id'); + expect(columnNames).toContain('database_id'); + expect(columnNames).toContain('private_schema_id'); + expect(columnNames).toContain('table_id'); + expect(columnNames).toContain('node_type'); + expect(columnNames).toContain('data'); + expect(columnNames).toContain('fields'); + + expect(snapshot({ columns })).toMatchSnapshot(); + }); + + // Test for table_template_module with node_type for table creation templates + it('should verify table_template_module table structure', async () => { + const columns = await pg.any(` + SELECT + column_name, + data_type, + is_nullable, + column_default + FROM information_schema.columns + WHERE table_schema = 'metaschema_modules_public' + AND table_name = 'table_template_module' + ORDER BY ordinal_position + `); + + // Check that key columns exist + const columnNames = columns.map(c => c.column_name); + expect(columnNames).toContain('id'); + expect(columnNames).toContain('database_id'); + expect(columnNames).toContain('schema_id'); + expect(columnNames).toContain('private_schema_id'); + expect(columnNames).toContain('table_id'); + expect(columnNames).toContain('owner_table_id'); + expect(columnNames).toContain('table_name'); + expect(columnNames).toContain('node_type'); + expect(columnNames).toContain('data'); + + expect(snapshot({ columns })).toMatchSnapshot(); + }); +}); \ No newline at end of file diff --git a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/crypto_auth_module/table.sql b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/crypto_auth_module/table.sql index bab5d175..dc5e9f55 100644 --- a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/crypto_auth_module/table.sql +++ b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/crypto_auth_module/table.sql @@ -11,8 +11,10 @@ CREATE TABLE metaschema_modules_public.crypto_auth_module ( schema_id uuid NOT NULL DEFAULT uuid_nil(), users_table_id uuid NOT NULL DEFAULT uuid_nil(), - tokens_table_id uuid NOT NULL DEFAULT uuid_nil(), + -- TOKENS_REMOVAL: tokens_table_id removed - crypto auth now uses sessions_module secrets_table_id uuid NOT NULL DEFAULT uuid_nil(), + sessions_table_id uuid NOT NULL DEFAULT uuid_nil(), + session_credentials_table_id uuid NOT NULL DEFAULT uuid_nil(), addresses_table_id uuid NOT NULL DEFAULT uuid_nil(), user_field text NOT NULL, @@ -27,14 +29,18 @@ CREATE TABLE metaschema_modules_public.crypto_auth_module ( CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE, CONSTRAINT secrets_table_fkey FOREIGN KEY (secrets_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, CONSTRAINT users_table_fkey FOREIGN KEY (users_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, - CONSTRAINT tokens_table_fkey FOREIGN KEY (tokens_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + -- TOKENS_REMOVAL: tokens_table_fkey removed - crypto auth now uses sessions_module + CONSTRAINT sessions_table_fkey FOREIGN KEY (sessions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT session_credentials_table_fkey FOREIGN KEY (session_credentials_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE ); COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; COMMENT ON CONSTRAINT secrets_table_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; COMMENT ON CONSTRAINT users_table_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; -COMMENT ON CONSTRAINT tokens_table_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; +-- TOKENS_REMOVAL: tokens_table_fkey comment removed +COMMENT ON CONSTRAINT sessions_table_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; +COMMENT ON CONSTRAINT session_credentials_table_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.crypto_auth_module IS E'@omit manyToMany'; CREATE INDEX crypto_auth_module_database_id_idx ON metaschema_modules_public.crypto_auth_module ( database_id ); diff --git a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/sessions_module/table.sql b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/sessions_module/table.sql new file mode 100644 index 00000000..f04e65ed --- /dev/null +++ b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/sessions_module/table.sql @@ -0,0 +1,45 @@ +-- Deploy schemas/metaschema_modules_public/tables/sessions_module/table to pg + +-- requires: schemas/metaschema_modules_public/schema + +BEGIN; + +CREATE TABLE metaschema_modules_public.sessions_module ( + id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (), + database_id uuid NOT NULL, + + -- + schema_id uuid NOT NULL DEFAULT uuid_nil(), + sessions_table_id uuid NOT NULL DEFAULT uuid_nil(), + session_credentials_table_id uuid NOT NULL DEFAULT uuid_nil(), + auth_settings_table_id uuid NOT NULL DEFAULT uuid_nil(), + users_table_id uuid NOT NULL DEFAULT uuid_nil(), + + sessions_default_expiration interval NOT NULL DEFAULT '30 days'::interval, + sessions_table text NOT NULL DEFAULT 'sessions', + session_credentials_table text NOT NULL DEFAULT 'session_credentials', + auth_settings_table text NOT NULL DEFAULT 'app_auth_settings', + -- + + CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE, + CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, + CONSTRAINT sessions_table_fkey FOREIGN KEY (sessions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT session_credentials_table_fkey FOREIGN KEY (session_credentials_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT auth_settings_table_fkey FOREIGN KEY (auth_settings_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT users_table_fkey FOREIGN KEY (users_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE +); + +COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.sessions_module IS E'@omit manyToMany'; +COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.sessions_module IS E'@omit manyToMany'; +CREATE INDEX sessions_module_database_id_idx ON metaschema_modules_public.sessions_module ( database_id ); + +COMMENT ON CONSTRAINT sessions_table_fkey + ON metaschema_modules_public.sessions_module IS E'@fieldName sessionsTableBySessionsTableId\n@omit manyToMany'; +COMMENT ON CONSTRAINT session_credentials_table_fkey + ON metaschema_modules_public.sessions_module IS E'@fieldName sessionCredentialsTableBySessionCredentialsTableId\n@omit manyToMany'; +COMMENT ON CONSTRAINT auth_settings_table_fkey + ON metaschema_modules_public.sessions_module IS E'@fieldName authSettingsTableByAuthSettingsTableId\n@omit manyToMany'; +COMMENT ON CONSTRAINT users_table_fkey + ON metaschema_modules_public.sessions_module IS E'@omit manyToMany'; + +COMMIT; diff --git a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/tokens_module/table.sql b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/tokens_module/table.sql deleted file mode 100644 index 1a77c19f..00000000 --- a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/tokens_module/table.sql +++ /dev/null @@ -1,35 +0,0 @@ --- Deploy schemas/metaschema_modules_public/tables/tokens_module/table to pg - --- requires: schemas/metaschema_modules_public/schema - -BEGIN; - -CREATE TABLE metaschema_modules_public.tokens_module ( - id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (), - database_id uuid NOT NULL, - - -- - schema_id uuid NOT NULL DEFAULT uuid_nil(), - table_id uuid NOT NULL DEFAULT uuid_nil(), - owned_table_id uuid NOT NULL DEFAULT uuid_nil(), - - tokens_default_expiration interval NOT NULL DEFAULT '3 days'::interval, - tokens_table text NOT NULL DEFAULT 'api_tokens', - -- - - CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE, - CONSTRAINT schema_fkey FOREIGN KEY (schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE, - CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, - CONSTRAINT owned_table_fkey FOREIGN KEY (owned_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE -); - -COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.tokens_module IS E'@omit manyToMany'; -COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.tokens_module IS E'@omit manyToMany'; -CREATE INDEX tokens_module_database_id_idx ON metaschema_modules_public.tokens_module ( database_id ); - -COMMENT ON CONSTRAINT owned_table_fkey - ON metaschema_modules_public.tokens_module IS E'@omit manyToMany'; -COMMENT ON CONSTRAINT table_fkey - ON metaschema_modules_public.tokens_module IS E'@omit manyToMany'; - -COMMIT; diff --git a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql index c1508c18..37ecb043 100644 --- a/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql +++ b/packages/metaschema-modules/deploy/schemas/metaschema_modules_public/tables/user_auth_module/table.sql @@ -13,7 +13,10 @@ CREATE TABLE metaschema_modules_public.user_auth_module ( users_table_id uuid NOT NULL DEFAULT uuid_nil(), secrets_table_id uuid NOT NULL DEFAULT uuid_nil(), encrypted_table_id uuid NOT NULL DEFAULT uuid_nil(), - tokens_table_id uuid NOT NULL DEFAULT uuid_nil(), + -- TOKENS_REMOVAL: tokens_table_id removed - all auth now uses sessions_module + -- SESSION_MIGRATION: sessions and session_credentials for session-centric auth + sessions_table_id uuid NOT NULL DEFAULT uuid_nil(), + session_credentials_table_id uuid NOT NULL DEFAULT uuid_nil(), audits_table_id uuid NOT NULL DEFAULT uuid_nil(), audits_table_name text NOT NULL DEFAULT 'audit_logs', @@ -47,7 +50,10 @@ CREATE TABLE metaschema_modules_public.user_auth_module ( CONSTRAINT users_table_fkey FOREIGN KEY (users_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, CONSTRAINT secrets_table_fkey FOREIGN KEY (secrets_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, CONSTRAINT encrypted_table_fkey FOREIGN KEY (encrypted_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, - CONSTRAINT tokens_table_fkey FOREIGN KEY (tokens_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE + -- TOKENS_REMOVAL: tokens_table_fkey removed - all auth now uses sessions_module + -- SESSION_MIGRATION: foreign keys for sessions and session_credentials + CONSTRAINT sessions_table_fkey FOREIGN KEY (sessions_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE, + CONSTRAINT session_credentials_table_fkey FOREIGN KEY (session_credentials_table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE ); COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.user_auth_module IS E'@omit manyToMany'; @@ -62,7 +68,11 @@ COMMENT ON CONSTRAINT secrets_table_fkey ON metaschema_modules_public.user_auth_module IS E'@omit'; COMMENT ON CONSTRAINT encrypted_table_fkey ON metaschema_modules_public.user_auth_module IS E'@omit'; -COMMENT ON CONSTRAINT tokens_table_fkey +-- TOKENS_REMOVAL: tokens_table_fkey comment removed +-- SESSION_MIGRATION: omit comments for sessions and session_credentials foreign keys +COMMENT ON CONSTRAINT sessions_table_fkey + ON metaschema_modules_public.user_auth_module IS E'@omit'; +COMMENT ON CONSTRAINT session_credentials_table_fkey ON metaschema_modules_public.user_auth_module IS E'@omit'; COMMIT; diff --git a/packages/metaschema-modules/pgpm.plan b/packages/metaschema-modules/pgpm.plan index f26dc7f1..9625f3e6 100644 --- a/packages/metaschema-modules/pgpm.plan +++ b/packages/metaschema-modules/pgpm.plan @@ -1,7 +1,7 @@ %syntax-version=1.0.0 %project=metaschema-modules %uri=metaschema-modules - + schemas/services_private/schema [services:schemas/services_public/tables/site_themes/table] 2017-08-11T08:11:51Z skitch # add schemas/services_private/schema schemas/services_public/schema 2017-08-11T08:11:51Z skitch # add schemas/services_public/schema schemas/metaschema_modules_public/schema 2026-01-04T08:28:00Z devin # add schemas/metaschema_modules_public/schema @@ -14,6 +14,7 @@ schemas/metaschema_modules_public/tables/denormalized_table_field/table [schemas schemas/metaschema_modules_public/tables/emails_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/emails_module/table schemas/metaschema_modules_public/tables/encrypted_secrets_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/encrypted_secrets_module/table schemas/metaschema_modules_public/tables/field_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/field_module/table +schemas/metaschema_modules_public/tables/table_module/table [schemas/metaschema_modules_public/schema] 2026-01-12T00:00:00Z devin # add schemas/metaschema_modules_public/tables/table_module/table schemas/metaschema_modules_public/tables/invites_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/invites_module/table schemas/metaschema_modules_public/tables/levels_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/levels_module/table schemas/metaschema_modules_public/tables/limits_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/limits_module/table @@ -25,10 +26,9 @@ schemas/metaschema_modules_public/tables/profiles_module/table [schemas/metasche schemas/metaschema_modules_public/tables/rls_module/table [schemas/metaschema_modules_public/schema schemas/services_public/tables/apis/table] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/rls_module/table schemas/metaschema_modules_public/tables/secrets_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/secrets_module/table schemas/services_public/tables/sites/table [schemas/services_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/services_public/tables/sites/table -schemas/metaschema_modules_public/tables/tokens_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/tokens_module/table +schemas/metaschema_modules_public/tables/sessions_module/table [schemas/metaschema_modules_public/schema] 2026-01-24T00:00:00Z devin # add schemas/metaschema_modules_public/tables/sessions_module/table schemas/metaschema_modules_public/tables/user_auth_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/user_auth_module/table schemas/metaschema_modules_public/tables/users_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/users_module/table schemas/metaschema_modules_public/tables/uuid_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch # add schemas/metaschema_modules_public/tables/uuid_module/table schemas/metaschema_modules_public/tables/hierarchy_module/table [schemas/metaschema_modules_public/schema] 2024-12-28T00:00:00Z skitch # add schemas/metaschema_modules_public/tables/hierarchy_module/table -schemas/metaschema_modules_public/tables/table_module/table [schemas/metaschema_modules_public/schema] 2026-01-14T00:00:00Z devin # add schemas/metaschema_modules_public/tables/table_module/table schemas/metaschema_modules_public/tables/table_template_module/table [schemas/metaschema_modules_public/schema] 2026-01-14T00:00:00Z devin # add schemas/metaschema_modules_public/tables/table_template_module/table diff --git a/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/sessions_module/table.sql b/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/sessions_module/table.sql new file mode 100644 index 00000000..7a945fd5 --- /dev/null +++ b/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/sessions_module/table.sql @@ -0,0 +1,7 @@ +-- Revert schemas/metaschema_modules_public/tables/sessions_module/table from pg + +BEGIN; + +DROP TABLE metaschema_modules_public.sessions_module; + +COMMIT; diff --git a/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/tokens_module/table.sql b/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/tokens_module/table.sql deleted file mode 100644 index fc8eb14e..00000000 --- a/packages/metaschema-modules/revert/schemas/metaschema_modules_public/tables/tokens_module/table.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Revert schemas/metaschema_modules_public/tables/tokens_module/table from pg - -BEGIN; - -DROP TABLE metaschema_modules_public.tokens_module; - -COMMIT; diff --git a/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/sessions_module/table.sql b/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/sessions_module/table.sql new file mode 100644 index 00000000..199463ca --- /dev/null +++ b/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/sessions_module/table.sql @@ -0,0 +1,7 @@ +-- Verify schemas/metaschema_modules_public/tables/sessions_module/table on pg + +BEGIN; + +SELECT verify_table ('metaschema_modules_public.sessions_module'); + +ROLLBACK; diff --git a/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/tokens_module/table.sql b/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/tokens_module/table.sql deleted file mode 100644 index 78b082ed..00000000 --- a/packages/metaschema-modules/verify/schemas/metaschema_modules_public/tables/tokens_module/table.sql +++ /dev/null @@ -1,7 +0,0 @@ --- Verify schemas/metaschema_modules_public/tables/tokens_module/table on pg - -BEGIN; - -SELECT verify_table ('metaschema_modules_public.tokens_module'); - -ROLLBACK;