Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ exports[`db_meta_modules should have all expected module tables 1`] = `
"limits_module",
"membership_types_module",
"memberships_module",
"organization_settings_module",
"permissions_module",
"phone_numbers_module",
"profiles_module",
"rls_module",
"secrets_module",
"table_module",
"tokens_module",
"user_auth_module",
"user_profiles_module",
"user_settings_module",
"users_module",
"uuid_module",
],
Expand All @@ -31,8 +35,8 @@ exports[`db_meta_modules should have all expected module tables 1`] = `

exports[`db_meta_modules should verify all module tables exist in metaschema_modules_public schema 1`] = `
{
"moduleTablesCount": 22,
"totalTables": 23,
"moduleTablesCount": 26,
"totalTables": 27,
}
`;

Expand Down Expand Up @@ -87,13 +91,13 @@ exports[`db_meta_modules should verify emails_module table structure 1`] = `

exports[`db_meta_modules should verify module table structures have database_id foreign keys 1`] = `
{
"constraintCount": 57222,
"constraintCount": 78650,
}
`;

exports[`db_meta_modules should verify module tables have proper foreign key relationships 1`] = `
{
"constraintCount": 78690,
"constraintCount": 113921,
"foreignTables": [
"apis",
"database",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ CREATE TABLE metaschema_modules_public.field_module (
table_id uuid NOT NULL DEFAULT uuid_nil(),
field_id uuid NOT NULL DEFAULT uuid_nil(),

-- data = '{"regexp":"^kjhsdkjhsd$"}'
-- data = '{"min":10, "max": 20}'
node_type text NOT NULL,

data jsonb NOT NULL DEFAULT '{}',

triggers text[],
Expand All @@ -32,6 +32,7 @@ COMMENT ON CONSTRAINT table_fkey ON metaschema_modules_public.field_module IS E'
COMMENT ON CONSTRAINT field_fkey ON metaschema_modules_public.field_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.field_module IS E'@omit manyToMany';
CREATE INDEX field_module_database_id_idx ON metaschema_modules_public.field_module ( database_id );
CREATE INDEX field_module_node_type_idx ON metaschema_modules_public.field_module ( node_type );

COMMIT;

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Deploy schemas/metaschema_modules_public/tables/organization_settings_module/table to pg

-- requires: schemas/metaschema_modules_public/schema

BEGIN;

CREATE TABLE metaschema_modules_public.organization_settings_module (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (),
database_id uuid NOT NULL,

schema_id uuid NOT NULL DEFAULT uuid_nil(),
private_schema_id uuid NOT NULL DEFAULT uuid_nil(),

table_id uuid NOT NULL DEFAULT uuid_nil(),
owner_table_id uuid NOT NULL DEFAULT uuid_nil(),

table_name text NOT NULL,

--
CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
CONSTRAINT owner_table_fkey FOREIGN KEY (owner_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,
CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE
);

COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.organization_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT private_schema_fkey ON metaschema_modules_public.organization_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT table_fkey ON metaschema_modules_public.organization_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT owner_table_fkey ON metaschema_modules_public.organization_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.organization_settings_module IS E'@omit manyToMany';
CREATE INDEX organization_settings_module_database_id_idx ON metaschema_modules_public.organization_settings_module ( database_id );

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Deploy schemas/metaschema_modules_public/tables/table_module/table to pg

-- requires: schemas/metaschema_modules_public/schema

BEGIN;

CREATE TABLE metaschema_modules_public.table_module (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (),
database_id uuid NOT NULL,

private_schema_id uuid NOT NULL DEFAULT uuid_nil(),

table_id uuid NOT NULL,

node_type text NOT NULL,

data jsonb NOT NULL DEFAULT '{}',

fields uuid[],

--
CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE
);

COMMENT ON CONSTRAINT private_schema_fkey ON metaschema_modules_public.table_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT table_fkey ON metaschema_modules_public.table_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.table_module IS E'@omit manyToMany';
CREATE INDEX table_module_database_id_idx ON metaschema_modules_public.table_module ( database_id );
CREATE INDEX table_module_table_id_idx ON metaschema_modules_public.table_module ( table_id );
CREATE INDEX table_module_node_type_idx ON metaschema_modules_public.table_module ( node_type );

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Deploy schemas/metaschema_modules_public/tables/user_profiles_module/table to pg

-- requires: schemas/metaschema_modules_public/schema

BEGIN;

CREATE TABLE metaschema_modules_public.user_profiles_module (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (),
database_id uuid NOT NULL,

schema_id uuid NOT NULL DEFAULT uuid_nil(),
private_schema_id uuid NOT NULL DEFAULT uuid_nil(),

table_id uuid NOT NULL DEFAULT uuid_nil(),
owner_table_id uuid NOT NULL DEFAULT uuid_nil(),

table_name text NOT NULL,

--
CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
CONSTRAINT owner_table_fkey FOREIGN KEY (owner_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,
CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE
);

COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.user_profiles_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT private_schema_fkey ON metaschema_modules_public.user_profiles_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT table_fkey ON metaschema_modules_public.user_profiles_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT owner_table_fkey ON metaschema_modules_public.user_profiles_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.user_profiles_module IS E'@omit manyToMany';
CREATE INDEX user_profiles_module_database_id_idx ON metaschema_modules_public.user_profiles_module ( database_id );

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Deploy schemas/metaschema_modules_public/tables/user_settings_module/table to pg

-- requires: schemas/metaschema_modules_public/schema

BEGIN;

CREATE TABLE metaschema_modules_public.user_settings_module (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (),
database_id uuid NOT NULL,

schema_id uuid NOT NULL DEFAULT uuid_nil(),
private_schema_id uuid NOT NULL DEFAULT uuid_nil(),

table_id uuid NOT NULL DEFAULT uuid_nil(),
owner_table_id uuid NOT NULL DEFAULT uuid_nil(),

table_name text NOT NULL,

--
CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
CONSTRAINT owner_table_fkey FOREIGN KEY (owner_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,
CONSTRAINT private_schema_fkey FOREIGN KEY (private_schema_id) REFERENCES metaschema_public.schema (id) ON DELETE CASCADE
);

COMMENT ON CONSTRAINT schema_fkey ON metaschema_modules_public.user_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT private_schema_fkey ON metaschema_modules_public.user_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT table_fkey ON metaschema_modules_public.user_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT owner_table_fkey ON metaschema_modules_public.user_settings_module IS E'@omit manyToMany';
COMMENT ON CONSTRAINT db_fkey ON metaschema_modules_public.user_settings_module IS E'@omit manyToMany';
CREATE INDEX user_settings_module_database_id_idx ON metaschema_modules_public.user_settings_module ( database_id );

COMMIT;
4 changes: 4 additions & 0 deletions packages/metaschema-modules/pgpm.plan
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ schemas/metaschema_modules_public/tables/user_auth_module/table [schemas/metasch
schemas/metaschema_modules_public/tables/users_module/table [schemas/metaschema_modules_public/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # 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 <skitch@5b0c196eeb62> # 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 <skitch@5b0c196eeb62> # 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 <devin@cognition.ai> # add schemas/metaschema_modules_public/tables/table_module/table
schemas/metaschema_modules_public/tables/user_profiles_module/table [schemas/metaschema_modules_public/schema] 2026-01-14T00:00:00Z devin <devin@cognition.ai> # add schemas/metaschema_modules_public/tables/user_profiles_module/table
schemas/metaschema_modules_public/tables/user_settings_module/table [schemas/metaschema_modules_public/schema] 2026-01-14T00:00:00Z devin <devin@cognition.ai> # add schemas/metaschema_modules_public/tables/user_settings_module/table
schemas/metaschema_modules_public/tables/organization_settings_module/table [schemas/metaschema_modules_public/schema] 2026-01-14T00:00:00Z devin <devin@cognition.ai> # add schemas/metaschema_modules_public/tables/organization_settings_module/table
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert schemas/metaschema_modules_public/tables/organization_settings_module/table from pg

BEGIN;

DROP TABLE IF EXISTS metaschema_modules_public.organization_settings_module;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert schemas/metaschema_modules_public/tables/table_module/table from pg

BEGIN;

DROP TABLE IF EXISTS metaschema_modules_public.table_module;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert schemas/metaschema_modules_public/tables/user_profiles_module/table from pg

BEGIN;

DROP TABLE IF EXISTS metaschema_modules_public.user_profiles_module;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert schemas/metaschema_modules_public/tables/user_settings_module/table from pg

BEGIN;

DROP TABLE IF EXISTS metaschema_modules_public.user_settings_module;

COMMIT;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Verify schemas/metaschema_modules_public/tables/organization_settings_module/table on pg

BEGIN;

SELECT
id,
database_id,
schema_id,
private_schema_id,
table_id,
owner_table_id,
table_name
FROM metaschema_modules_public.organization_settings_module
WHERE FALSE;

ROLLBACK;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Verify schemas/metaschema_modules_public/tables/table_module/table on pg

BEGIN;

SELECT
id,
database_id,
private_schema_id,
table_id,
node_type,
data,
fields
FROM metaschema_modules_public.table_module
WHERE FALSE;

ROLLBACK;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Verify schemas/metaschema_modules_public/tables/user_profiles_module/table on pg

BEGIN;

SELECT
id,
database_id,
schema_id,
private_schema_id,
table_id,
owner_table_id,
table_name
FROM metaschema_modules_public.user_profiles_module
WHERE FALSE;

ROLLBACK;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- Verify schemas/metaschema_modules_public/tables/user_settings_module/table on pg

BEGIN;

SELECT
id,
database_id,
schema_id,
private_schema_id,
table_id,
owner_table_id,
table_name
FROM metaschema_modules_public.user_settings_module
WHERE FALSE;

ROLLBACK;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- requires: schemas/metaschema_public/schema
-- requires: schemas/metaschema_public/tables/database/table
-- requires: schemas/metaschema_public/tables/table/table
-- requires: schemas/metaschema_public/types/object_category

BEGIN;

Expand All @@ -15,7 +16,14 @@ CREATE TABLE metaschema_public.check_constraint (
type text,
field_ids uuid[] NOT NULL,
expr jsonb,
--

smart_tags jsonb,

category metaschema_public.object_category NOT NULL DEFAULT 'app',
module text NULL,
scope int NULL,

tags citext[] NOT NULL DEFAULT '{}',

CONSTRAINT db_fkey FOREIGN KEY (database_id) REFERENCES metaschema_public.database (id) ON DELETE CASCADE,
CONSTRAINT table_fkey FOREIGN KEY (table_id) REFERENCES metaschema_public.table (id) ON DELETE CASCADE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,10 @@

-- requires: schemas/metaschema_public/schema
-- requires: schemas/metaschema_public/tables/table/table
-- requires: schemas/metaschema_public/types/object_category

BEGIN;

-- TODO should we just query this table and make a view?
-- https://www.postgresql.org/docs/9.2/catalog-pg-attribute.html

-- IF YOU WANT TO REMOVE THIS TABLE, answer the qustion, how would you add RLS to this:
-- SELECT
-- attrelid::text AS tbl
-- , attname::text AS col
-- , p.attnum::int as id,
-- t.typname as typename

-- FROM pg_catalog.pg_attribute p
-- INNER JOIN pg_catalog.pg_type t ON (t.oid = p.atttypid)
-- WHERE attrelid = 'dude_schema.products'::regclass
-- AND p.attnum > 0
-- AND NOT attisdropped;

CREATE TYPE metaschema_public.field_category AS ENUM ('core', 'module', 'app');

CREATE TABLE metaschema_public.field (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4 (),
database_id uuid NOT NULL DEFAULT uuid_nil(),
Expand Down Expand Up @@ -58,11 +41,7 @@ CREATE TABLE metaschema_public.field (

tags citext[] NOT NULL DEFAULT '{}',

-- Field categorization for system/module/app fields (mirrors table categorization)
-- category: 'core' for system fields (id, entity_id, actor_id), 'module' for module-generated fields, 'app' for user-defined fields
-- module: the module name that created this field (e.g., 'users', 'permissions', 'memberships')
-- scope: membership_type int (1=app, 2=org, 3=group, NULL=not scoped)
category metaschema_public.field_category NOT NULL DEFAULT 'app',
category metaschema_public.object_category NOT NULL DEFAULT 'app',
module text NULL,
scope int NULL,

Expand Down
Loading