This commit is contained in:
Lakee Sivaraya
2026-01-17 10:16:45 -08:00
parent d0c3c6aec7
commit 6e8dc771fe
7 changed files with 492 additions and 10357 deletions

View File

@@ -1,24 +0,0 @@
-- Drop deleted_at column if it exists (from 0139)
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'user_table_definitions' AND column_name = 'deleted_at'
) THEN
ALTER TABLE "user_table_definitions" DROP COLUMN "deleted_at";
END IF;
END $$;
--> statement-breakpoint
-- Drop row_count column if it exists (from 0139, will be re-added in 0141)
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'user_table_definitions' AND column_name = 'row_count'
) THEN
ALTER TABLE "user_table_definitions" DROP COLUMN "row_count";
END IF;
END $$;
--> statement-breakpoint
-- Drop the deleted_at index if it exists
DROP INDEX IF EXISTS "user_table_def_deleted_at_idx";

View File

@@ -1,52 +0,0 @@
-- Add row_count column if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'user_table_definitions' AND column_name = 'row_count'
) THEN
ALTER TABLE "user_table_definitions" ADD COLUMN "row_count" integer DEFAULT 0 NOT NULL;
END IF;
END $$;
--> statement-breakpoint
-- Backfill existing row counts
UPDATE user_table_definitions t
SET row_count = (
SELECT COUNT(*)
FROM user_table_rows r
WHERE r.table_id = t.id
);
--> statement-breakpoint
-- Create function to increment row count on insert
CREATE OR REPLACE FUNCTION increment_table_row_count()
RETURNS TRIGGER AS $$
BEGIN
UPDATE user_table_definitions
SET row_count = row_count + 1
WHERE id = NEW.table_id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
--> statement-breakpoint
-- Create trigger for insert
CREATE TRIGGER trg_increment_row_count
AFTER INSERT ON user_table_rows
FOR EACH ROW
EXECUTE FUNCTION increment_table_row_count();
--> statement-breakpoint
-- Create function to decrement row count on delete
CREATE OR REPLACE FUNCTION decrement_table_row_count()
RETURNS TRIGGER AS $$
BEGIN
UPDATE user_table_definitions
SET row_count = GREATEST(0, row_count - 1)
WHERE id = OLD.table_id;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
--> statement-breakpoint
-- Create trigger for delete
CREATE TRIGGER trg_decrement_row_count
AFTER DELETE ON user_table_rows
FOR EACH ROW
EXECUTE FUNCTION decrement_table_row_count();

View File

@@ -0,0 +1,89 @@
CREATE TABLE "user_table_definitions" (
"id" text PRIMARY KEY NOT NULL,
"workspace_id" text NOT NULL,
"name" text NOT NULL,
"description" text,
"schema" jsonb NOT NULL,
"max_rows" integer DEFAULT 10000 NOT NULL,
"row_count" integer DEFAULT 0 NOT NULL,
"created_by" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "user_table_rows" (
"id" text PRIMARY KEY NOT NULL,
"table_id" text NOT NULL,
"workspace_id" text NOT NULL,
"data" jsonb NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"created_by" text
);
--> statement-breakpoint
ALTER TABLE "user_table_definitions" ADD CONSTRAINT "user_table_definitions_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_table_definitions" ADD CONSTRAINT "user_table_definitions_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_table_rows" ADD CONSTRAINT "user_table_rows_table_id_user_table_definitions_id_fk" FOREIGN KEY ("table_id") REFERENCES "public"."user_table_definitions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_table_rows" ADD CONSTRAINT "user_table_rows_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "user_table_rows" ADD CONSTRAINT "user_table_rows_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "user_table_def_workspace_id_idx" ON "user_table_definitions" USING btree ("workspace_id");--> statement-breakpoint
CREATE UNIQUE INDEX "user_table_def_workspace_name_unique" ON "user_table_definitions" USING btree ("workspace_id","name");--> statement-breakpoint
CREATE INDEX "user_table_rows_table_id_idx" ON "user_table_rows" USING btree ("table_id");--> statement-breakpoint
CREATE INDEX "user_table_rows_workspace_id_idx" ON "user_table_rows" USING btree ("workspace_id");--> statement-breakpoint
CREATE INDEX "user_table_rows_data_gin_idx" ON "user_table_rows" USING gin ("data");--> statement-breakpoint
CREATE INDEX "user_table_rows_workspace_table_idx" ON "user_table_rows" USING btree ("workspace_id","table_id");--> statement-breakpoint
-- Trigger function to increment row_count on INSERT
CREATE OR REPLACE FUNCTION increment_user_table_row_count()
RETURNS TRIGGER AS $$
DECLARE
current_count INTEGER;
max_allowed INTEGER;
BEGIN
-- Get current count and max_rows
SELECT row_count, max_rows INTO current_count, max_allowed
FROM user_table_definitions
WHERE id = NEW.table_id;
-- Check if we would exceed max_rows
IF current_count >= max_allowed THEN
RAISE EXCEPTION 'Maximum row limit (%) reached for table %', max_allowed, NEW.table_id;
END IF;
-- Increment the row count
UPDATE user_table_definitions
SET row_count = row_count + 1,
updated_at = now()
WHERE id = NEW.table_id;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
--> statement-breakpoint
-- Trigger function to decrement row_count on DELETE
CREATE OR REPLACE FUNCTION decrement_user_table_row_count()
RETURNS TRIGGER AS $$
BEGIN
UPDATE user_table_definitions
SET row_count = GREATEST(row_count - 1, 0),
updated_at = now()
WHERE id = OLD.table_id;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
--> statement-breakpoint
-- Create trigger for INSERT
CREATE TRIGGER user_table_rows_insert_trigger
BEFORE INSERT ON user_table_rows
FOR EACH ROW
EXECUTE FUNCTION increment_user_table_row_count();
--> statement-breakpoint
-- Create trigger for DELETE
CREATE TRIGGER user_table_rows_delete_trigger
AFTER DELETE ON user_table_rows
FOR EACH ROW
EXECUTE FUNCTION decrement_user_table_row_count();

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"id": "b0ccee95-4d64-421e-8631-65984c6b80c7",
"prevId": "cffb4dda-dfcc-474d-a6d8-fdb2b749edaf",
"id": "60cd2b70-8665-4541-a747-db49939aaf8f",
"prevId": "c7f4dbd0-6742-4e4d-8764-576026d265f0",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -4787,6 +4787,13 @@
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"auto_add_new_members": {
"name": "auto_add_new_members",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
}
},
"indexes": {
@@ -4840,6 +4847,22 @@
"concurrently": false,
"method": "btree",
"with": {}
},
"permission_group_org_auto_add_unique": {
"name": "permission_group_org_auto_add_unique",
"columns": [
{
"expression": "organization_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"where": "auto_add_new_members = true",
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
@@ -6907,6 +6930,291 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user_table_definitions": {
"name": "user_table_definitions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"workspace_id": {
"name": "workspace_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"schema": {
"name": "schema",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"max_rows": {
"name": "max_rows",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 10000
},
"row_count": {
"name": "row_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"default": 0
},
"created_by": {
"name": "created_by",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {
"user_table_def_workspace_id_idx": {
"name": "user_table_def_workspace_id_idx",
"columns": [
{
"expression": "workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"user_table_def_workspace_name_unique": {
"name": "user_table_def_workspace_name_unique",
"columns": [
{
"expression": "workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "name",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"user_table_definitions_workspace_id_workspace_id_fk": {
"name": "user_table_definitions_workspace_id_workspace_id_fk",
"tableFrom": "user_table_definitions",
"tableTo": "workspace",
"columnsFrom": ["workspace_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
"user_table_definitions_created_by_user_id_fk": {
"name": "user_table_definitions_created_by_user_id_fk",
"tableFrom": "user_table_definitions",
"tableTo": "user",
"columnsFrom": ["created_by"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.user_table_rows": {
"name": "user_table_rows",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"table_id": {
"name": "table_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"workspace_id": {
"name": "workspace_id",
"type": "text",
"primaryKey": false,
"notNull": true
},
"data": {
"name": "data",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"created_by": {
"name": "created_by",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {
"user_table_rows_table_id_idx": {
"name": "user_table_rows_table_id_idx",
"columns": [
{
"expression": "table_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"user_table_rows_workspace_id_idx": {
"name": "user_table_rows_workspace_id_idx",
"columns": [
{
"expression": "workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"user_table_rows_data_gin_idx": {
"name": "user_table_rows_data_gin_idx",
"columns": [
{
"expression": "data",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "gin",
"with": {}
},
"user_table_rows_workspace_table_idx": {
"name": "user_table_rows_workspace_table_idx",
"columns": [
{
"expression": "workspace_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "table_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
"user_table_rows_table_id_user_table_definitions_id_fk": {
"name": "user_table_rows_table_id_user_table_definitions_id_fk",
"tableFrom": "user_table_rows",
"tableTo": "user_table_definitions",
"columnsFrom": ["table_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
"user_table_rows_workspace_id_workspace_id_fk": {
"name": "user_table_rows_workspace_id_workspace_id_fk",
"tableFrom": "user_table_rows",
"tableTo": "workspace",
"columnsFrom": ["workspace_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
},
"user_table_rows_created_by_user_id_fk": {
"name": "user_table_rows_created_by_user_id_fk",
"tableFrom": "user_table_rows",
"tableTo": "user",
"columnsFrom": ["created_by"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.verification": {
"name": "verification",
"schema": "",
@@ -7055,6 +7363,12 @@
"primaryKey": false,
"notNull": true
},
"deployment_version_id": {
"name": "deployment_version_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"block_id": {
"name": "block_id",
"type": "text",
@@ -7121,14 +7435,20 @@
}
},
"indexes": {
"path_idx": {
"name": "path_idx",
"path_deployment_unique": {
"name": "path_deployment_unique",
"columns": [
{
"expression": "path",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "deployment_version_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
@@ -7157,6 +7477,27 @@
"method": "btree",
"with": {}
},
"webhook_workflow_deployment_idx": {
"name": "webhook_workflow_deployment_idx",
"columns": [
{
"expression": "workflow_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "deployment_version_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
},
"webhook_credential_set_id_idx": {
"name": "webhook_credential_set_id_idx",
"columns": [
@@ -7183,11 +7524,11 @@
"onDelete": "cascade",
"onUpdate": "no action"
},
"webhook_block_id_workflow_blocks_id_fk": {
"name": "webhook_block_id_workflow_blocks_id_fk",
"webhook_deployment_version_id_workflow_deployment_version_id_fk": {
"name": "webhook_deployment_version_id_workflow_deployment_version_id_fk",
"tableFrom": "webhook",
"tableTo": "workflow_blocks",
"columnsFrom": ["block_id"],
"tableTo": "workflow_deployment_version",
"columnsFrom": ["deployment_version_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
@@ -8701,6 +9042,13 @@
"primaryKey": false,
"notNull": false
},
"is_public": {
"name": "is_public",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": false
},
"created_at": {
"name": "created_at",
"type": "timestamp",
@@ -8925,6 +9273,12 @@
"primaryKey": false,
"notNull": true
},
"deployment_version_id": {
"name": "deployment_version_id",
"type": "text",
"primaryKey": false,
"notNull": false
},
"block_id": {
"name": "block_id",
"type": "text",
@@ -9004,8 +9358,8 @@
}
},
"indexes": {
"workflow_schedule_workflow_block_unique": {
"name": "workflow_schedule_workflow_block_unique",
"workflow_schedule_workflow_block_deployment_unique": {
"name": "workflow_schedule_workflow_block_deployment_unique",
"columns": [
{
"expression": "workflow_id",
@@ -9018,12 +9372,39 @@
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "deployment_version_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": true,
"concurrently": false,
"method": "btree",
"with": {}
},
"workflow_schedule_workflow_deployment_idx": {
"name": "workflow_schedule_workflow_deployment_idx",
"columns": [
{
"expression": "workflow_id",
"isExpression": false,
"asc": true,
"nulls": "last"
},
{
"expression": "deployment_version_id",
"isExpression": false,
"asc": true,
"nulls": "last"
}
],
"isUnique": false,
"concurrently": false,
"method": "btree",
"with": {}
}
},
"foreignKeys": {
@@ -9036,11 +9417,11 @@
"onDelete": "cascade",
"onUpdate": "no action"
},
"workflow_schedule_block_id_workflow_blocks_id_fk": {
"name": "workflow_schedule_block_id_workflow_blocks_id_fk",
"workflow_schedule_deployment_version_id_workflow_deployment_version_id_fk": {
"name": "workflow_schedule_deployment_version_id_workflow_deployment_version_id_fk",
"tableFrom": "workflow_schedule",
"tableTo": "workflow_blocks",
"columnsFrom": ["block_id"],
"tableTo": "workflow_deployment_version",
"columnsFrom": ["deployment_version_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"

View File

@@ -1016,6 +1016,13 @@
"when": 1768602646955,
"tag": "0145_messy_archangel",
"breakpoints": true
},
{
"idx": 146,
"version": "7",
"when": 1768673628844,
"tag": "0146_overconfident_lorna_dane",
"breakpoints": true
}
]
}

View File

@@ -1,3 +1,4 @@
/// <reference types="node" />
/**
* Seed script to populate the stress_test_users table.
*