fix: harden v2 custom widgets and Workshop (#6480)

This commit is contained in:
Thomas authored and GitHub committed 2026-07-31 13:28:53 +02:00
1 parent e8a2c87c2d
commit 557ebe0a2f
138 files changed
+5151 -1976

No files matched your search

@@ -1,30 +0,0 @@
RENAME TABLE `custom_widget_definition` TO `legacy_custom_widget_definition`, `custom_widget_secret` TO `legacy_custom_widget_secret`;--> statement-breakpoint
ALTER TABLE `legacy_custom_widget_definition` DROP FOREIGN KEY `custom_widget_definition_creator_id_user_id_fk`;--> statement-breakpoint
ALTER TABLE `legacy_custom_widget_definition` ADD CONSTRAINT `legacy_cw_definition_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `legacy_custom_widget_secret` DROP FOREIGN KEY `cw_secret_definition_id_cw_definition_id_fk`;--> statement-breakpoint
ALTER TABLE `legacy_custom_widget_secret` ADD CONSTRAINT `legacy_cw_secret_definition_id_fk` FOREIGN KEY (`definition_id`) REFERENCES `legacy_custom_widget_definition`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE TABLE `custom_widget_definition` (
`id` varchar(64) NOT NULL,
`name` varchar(256) NOT NULL,
`description` text,
`icon_url` text,
`sources` text NOT NULL,
`requests` text NOT NULL,
`options` text NOT NULL,
`template` text NOT NULL,
`enabled` boolean DEFAULT true NOT NULL,
`created_at` timestamp DEFAULT (now()) NOT NULL,
`updated_at` timestamp DEFAULT (now()) NOT NULL,
`creator_id` varchar(64),
CONSTRAINT `custom_widget_definition_id` PRIMARY KEY(`id`)
);--> statement-breakpoint
CREATE TABLE `custom_widget_secret` (
`source_id` varchar(64) NOT NULL,
`kind` varchar(64) NOT NULL,
`encrypted_value` text NOT NULL,
`updated_at` timestamp NOT NULL,
`definition_id` varchar(64) NOT NULL,
CONSTRAINT `custom_widget_secret_definition_id_source_id_kind_pk` PRIMARY KEY(`definition_id`,`source_id`,`kind`)
);--> statement-breakpoint
ALTER TABLE `custom_widget_definition` ADD CONSTRAINT `custom_widget_definition_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `custom_widget_secret` ADD CONSTRAINT `cw_secret_definition_id_fk` FOREIGN KEY (`definition_id`) REFERENCES `custom_widget_definition`(`id`) ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,26 @@
CREATE TABLE `custom_widget_v2_definition` (
`id` varchar(64) NOT NULL,
`name` varchar(256) NOT NULL,
`description` text,
`icon_url` text,
`sources` text NOT NULL,
`requests` text NOT NULL,
`options` text NOT NULL,
`template` text NOT NULL,
`enabled` boolean DEFAULT true NOT NULL,
`created_at` timestamp DEFAULT (now()) NOT NULL,
`updated_at` timestamp DEFAULT (now()) NOT NULL,
`creator_id` varchar(64),
CONSTRAINT `custom_widget_v2_definition_id` PRIMARY KEY(`id`)
);--> statement-breakpoint
CREATE TABLE `custom_widget_v2_secret` (
`source_id` varchar(64) NOT NULL,
`kind` varchar(64) NOT NULL,
`encrypted_value` text NOT NULL,
`updated_at` timestamp NOT NULL,
`definition_id` varchar(64) NOT NULL,
CONSTRAINT `custom_widget_v2_secret_definition_id_source_id_kind_pk` PRIMARY KEY(`definition_id`,`source_id`,`kind`)
);--> statement-breakpoint
ALTER TABLE `custom_widget_v2_definition` ADD CONSTRAINT `custom_widget_v2_definition_creator_id_user_id_fk` FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `custom_widget_v2_secret` ADD CONSTRAINT `custom_widget_v2_secret_definition_id_fk` FOREIGN KEY (`definition_id`) REFERENCES `custom_widget_v2_definition`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
DELETE FROM `groupPermission` WHERE `permission` IN ('custom-widget-manage', 'custom-widget-secret-write');
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "mysql",
"id": "1a10d79c-6c82-4036-8717-0283ebaece10",
"id": "e2f11bb0-59e9-4fab-8ae1-5bf764795c74",
"prevId": "073d408e-ff80-4a57-8007-f1f32da1c71c",
"tables": {
"account": {
@@ -534,198 +534,8 @@
"uniqueConstraints": {},
"checkConstraint": {}
},
"legacy_custom_widget_definition": {
"name": "legacy_custom_widget_definition",
"columns": {
"id": {
"name": "id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"auth_type": {
"name": "auth_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"method": {
"name": "method",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"display_type": {
"name": "display_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "('{\"json\": {}}')"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"creator_id": {
"name": "creator_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_definition_creator_id_user_id_fk": {
"name": "legacy_cw_definition_creator_id_user_id_fk",
"tableFrom": "legacy_custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"legacy_custom_widget_definition_id": {
"name": "legacy_custom_widget_definition_id",
"columns": ["id"]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"legacy_custom_widget_secret": {
"name": "legacy_custom_widget_secret",
"columns": {
"kind": {
"name": "kind",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"definition_id": {
"name": "definition_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_secret_definition_id_fk": {
"name": "legacy_cw_secret_definition_id_fk",
"tableFrom": "legacy_custom_widget_secret",
"tableTo": "legacy_custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"legacy_custom_widget_secret_definition_id_kind_pk": {
"name": "legacy_custom_widget_secret_definition_id_kind_pk",
"columns": ["definition_id", "kind"]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"custom_widget_definition": {
"name": "custom_widget_definition",
"custom_widget_v2_definition": {
"name": "custom_widget_v2_definition",
"columns": {
"id": {
"name": "id",
@@ -817,9 +627,9 @@
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"custom_widget_v2_definition_creator_id_user_id_fk": {
"name": "custom_widget_v2_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_v2_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
@@ -828,16 +638,16 @@
}
},
"compositePrimaryKeys": {
"custom_widget_definition_id": {
"name": "custom_widget_definition_id",
"custom_widget_v2_definition_id": {
"name": "custom_widget_v2_definition_id",
"columns": ["id"]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"custom_widget_secret": {
"name": "custom_widget_secret",
"custom_widget_v2_secret": {
"name": "custom_widget_v2_secret",
"columns": {
"source_id": {
"name": "source_id",
@@ -877,10 +687,10 @@
},
"indexes": {},
"foreignKeys": {
"cw_secret_definition_id_fk": {
"name": "cw_secret_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"custom_widget_v2_secret_definition_id_fk": {
"name": "custom_widget_v2_secret_definition_id_fk",
"tableFrom": "custom_widget_v2_secret",
"tableTo": "custom_widget_v2_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
@@ -888,8 +698,8 @@
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_source_id_kind_pk": {
"name": "custom_widget_secret_definition_id_source_id_kind_pk",
"custom_widget_v2_secret_definition_id_source_id_kind_pk": {
"name": "custom_widget_v2_secret_definition_id_source_id_kind_pk",
"columns": ["definition_id", "source_id", "kind"]
}
},
@@ -1718,6 +1528,196 @@
"uniqueConstraints": {},
"checkConstraint": {}
},
"custom_widget_definition": {
"name": "custom_widget_definition",
"columns": {
"id": {
"name": "id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"auth_type": {
"name": "auth_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"method": {
"name": "method",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"display_type": {
"name": "display_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "('{\"json\": {}}')"
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(now())"
},
"creator_id": {
"name": "creator_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"custom_widget_definition_id": {
"name": "custom_widget_definition_id",
"columns": ["id"]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"custom_widget_secret": {
"name": "custom_widget_secret",
"columns": {
"kind": {
"name": "kind",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"definition_id": {
"name": "definition_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"cw_secret_definition_id_cw_definition_id_fk": {
"name": "cw_secret_definition_id_cw_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_kind_pk": {
"name": "custom_widget_secret_definition_id_kind_pk",
"columns": ["definition_id", "kind"]
}
},
"uniqueConstraints": {},
"checkConstraint": {}
},
"media": {
"name": "media",
"columns": {
@@ -314,7 +314,7 @@
"idx": 44,
"version": "5",
"when": 1784305537309,
"tag": "0044_custom_widget_v2_reset",
"tag": "0044_custom_widget_v2_tables",
"breakpoints": true
}
]
@@ -1,29 +0,0 @@
ALTER TABLE "custom_widget_definition" RENAME TO "legacy_custom_widget_definition";--> statement-breakpoint
ALTER TABLE "custom_widget_secret" RENAME TO "legacy_custom_widget_secret";--> statement-breakpoint
ALTER TABLE "legacy_custom_widget_definition" RENAME CONSTRAINT "custom_widget_definition_creator_id_user_id_fk" TO "legacy_cw_definition_creator_id_user_id_fk";--> statement-breakpoint
ALTER TABLE "legacy_custom_widget_secret" RENAME CONSTRAINT "custom_widget_secret_definition_id_custom_widget_definition_id_fk" TO "legacy_cw_secret_definition_id_fk";--> statement-breakpoint
ALTER TABLE "legacy_custom_widget_secret" RENAME CONSTRAINT "custom_widget_secret_definition_id_kind_pk" TO "legacy_custom_widget_secret_definition_id_kind_pk";--> statement-breakpoint
CREATE TABLE "custom_widget_definition" (
"id" varchar(64) PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
"description" text,
"icon_url" text,
"sources" text NOT NULL,
"requests" text NOT NULL,
"options" text NOT NULL,
"template" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"creator_id" varchar(64)
);--> statement-breakpoint
CREATE TABLE "custom_widget_secret" (
"source_id" varchar(64) NOT NULL,
"kind" varchar(64) NOT NULL,
"encrypted_value" text NOT NULL,
"updated_at" timestamp NOT NULL,
"definition_id" varchar(64) NOT NULL,
CONSTRAINT "custom_widget_secret_definition_id_source_id_kind_pk" PRIMARY KEY("definition_id","source_id","kind")
);--> statement-breakpoint
ALTER TABLE "custom_widget_definition" ADD CONSTRAINT "custom_widget_definition_creator_id_user_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "custom_widget_secret" ADD CONSTRAINT "cw_secret_definition_id_fk" FOREIGN KEY ("definition_id") REFERENCES "public"."custom_widget_definition"("id") ON DELETE cascade ON UPDATE no action;
@@ -0,0 +1,25 @@
CREATE TABLE "custom_widget_v2_definition" (
"id" varchar(64) PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
"description" text,
"icon_url" text,
"sources" text NOT NULL,
"requests" text NOT NULL,
"options" text NOT NULL,
"template" text NOT NULL,
"enabled" boolean DEFAULT true NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL,
"creator_id" varchar(64)
);--> statement-breakpoint
CREATE TABLE "custom_widget_v2_secret" (
"source_id" varchar(64) NOT NULL,
"kind" varchar(64) NOT NULL,
"encrypted_value" text NOT NULL,
"updated_at" timestamp NOT NULL,
"definition_id" varchar(64) NOT NULL,
CONSTRAINT "custom_widget_v2_secret_definition_id_source_id_kind_pk" PRIMARY KEY("definition_id","source_id","kind")
);--> statement-breakpoint
ALTER TABLE "custom_widget_v2_definition" ADD CONSTRAINT "custom_widget_v2_definition_creator_id_user_id_fk" FOREIGN KEY ("creator_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "custom_widget_v2_secret" ADD CONSTRAINT "custom_widget_v2_secret_definition_id_fk" FOREIGN KEY ("definition_id") REFERENCES "public"."custom_widget_v2_definition"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
DELETE FROM "groupPermission" WHERE "permission" IN ('custom-widget-manage', 'custom-widget-secret-write');
@@ -1,5 +1,5 @@
{
"id": "f2cd8146-b478-4617-870e-f601fb437d15",
"id": "99938d86-5059-41b3-a21c-ac767440ed00",
"prevId": "97bda61f-0a71-4e41-8e60-874aafe17115",
"version": "7",
"dialect": "postgresql",
@@ -498,180 +498,8 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.legacy_custom_widget_definition": {
"name": "legacy_custom_widget_definition",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(64)",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"auth_type": {
"name": "auth_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false
},
"method": {
"name": "method",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false
},
"display_type": {
"name": "display_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'{\"json\": {}}'"
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": 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()"
},
"creator_id": {
"name": "creator_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_definition_creator_id_user_id_fk": {
"name": "legacy_cw_definition_creator_id_user_id_fk",
"tableFrom": "legacy_custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.legacy_custom_widget_secret": {
"name": "legacy_custom_widget_secret",
"schema": "",
"columns": {
"kind": {
"name": "kind",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"definition_id": {
"name": "definition_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_secret_definition_id_fk": {
"name": "legacy_cw_secret_definition_id_fk",
"tableFrom": "legacy_custom_widget_secret",
"tableTo": "legacy_custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"legacy_custom_widget_secret_definition_id_kind_pk": {
"name": "legacy_custom_widget_secret_definition_id_kind_pk",
"columns": ["definition_id", "kind"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.custom_widget_definition": {
"name": "custom_widget_definition",
"public.custom_widget_v2_definition": {
"name": "custom_widget_v2_definition",
"schema": "",
"columns": {
"id": {
@@ -752,9 +580,9 @@
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"custom_widget_v2_definition_creator_id_user_id_fk": {
"name": "custom_widget_v2_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_v2_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
@@ -768,8 +596,8 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.custom_widget_secret": {
"name": "custom_widget_secret",
"public.custom_widget_v2_secret": {
"name": "custom_widget_v2_secret",
"schema": "",
"columns": {
"source_id": {
@@ -805,10 +633,10 @@
},
"indexes": {},
"foreignKeys": {
"cw_secret_definition_id_fk": {
"name": "cw_secret_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"custom_widget_v2_secret_definition_id_fk": {
"name": "custom_widget_v2_secret_definition_id_fk",
"tableFrom": "custom_widget_v2_secret",
"tableTo": "custom_widget_v2_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
@@ -816,8 +644,8 @@
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_source_id_kind_pk": {
"name": "custom_widget_secret_definition_id_source_id_kind_pk",
"custom_widget_v2_secret_definition_id_source_id_kind_pk": {
"name": "custom_widget_v2_secret_definition_id_source_id_kind_pk",
"columns": ["definition_id", "source_id", "kind"]
}
},
@@ -1632,6 +1460,178 @@
"checkConstraints": {},
"isRLSEnabled": false
},
"public.custom_widget_definition": {
"name": "custom_widget_definition",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "varchar(64)",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true
},
"auth_type": {
"name": "auth_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "varchar(256)",
"primaryKey": false,
"notNull": false
},
"method": {
"name": "method",
"type": "varchar(16)",
"primaryKey": false,
"notNull": true,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false
},
"display_type": {
"name": "display_type",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'{\"json\": {}}'"
},
"enabled": {
"name": "enabled",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"default": 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()"
},
"creator_id": {
"name": "creator_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.custom_widget_secret": {
"name": "custom_widget_secret",
"schema": "",
"columns": {
"kind": {
"name": "kind",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"definition_id": {
"name": "definition_id",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {
"custom_widget_secret_definition_id_custom_widget_definition_id_fk": {
"name": "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_kind_pk": {
"name": "custom_widget_secret_definition_id_kind_pk",
"columns": ["definition_id", "kind"]
}
},
"uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
},
"public.media": {
"name": "media",
"schema": "",
@@ -76,7 +76,7 @@
"idx": 10,
"version": "7",
"when": 1784305412862,
"tag": "0010_custom_widget_v2_reset",
"tag": "0010_custom_widget_v2_tables",
"breakpoints": true
}
]
@@ -1,7 +1,4 @@
PRAGMA foreign_keys=OFF;--> statement-breakpoint
ALTER TABLE `custom_widget_definition` RENAME TO `legacy_custom_widget_definition`;--> statement-breakpoint
ALTER TABLE `custom_widget_secret` RENAME TO `legacy_custom_widget_secret`;--> statement-breakpoint
CREATE TABLE `custom_widget_definition` (
CREATE TABLE `custom_widget_v2_definition` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`description` text,
@@ -16,13 +13,13 @@ CREATE TABLE `custom_widget_definition` (
`creator_id` text,
FOREIGN KEY (`creator_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE set null
);--> statement-breakpoint
CREATE TABLE `custom_widget_secret` (
CREATE TABLE `custom_widget_v2_secret` (
`source_id` text NOT NULL,
`kind` text NOT NULL,
`encrypted_value` text NOT NULL,
`updated_at` integer NOT NULL,
`definition_id` text NOT NULL,
PRIMARY KEY(`definition_id`, `source_id`, `kind`),
FOREIGN KEY (`definition_id`) REFERENCES `custom_widget_definition`(`id`) ON UPDATE no action ON DELETE cascade
FOREIGN KEY (`definition_id`) REFERENCES `custom_widget_v2_definition`(`id`) ON UPDATE no action ON DELETE cascade
);--> statement-breakpoint
PRAGMA foreign_keys=ON;
DELETE FROM `groupPermission` WHERE `permission` IN ('custom-widget-manage', 'custom-widget-secret-write');
@@ -1,7 +1,7 @@
{
"version": "6",
"dialect": "sqlite",
"id": "30bbf6f8-3a3c-4cb0-994e-9d8494e4fcd0",
"id": "51923913-fdc0-4ae7-9127-e86587e0b51f",
"prevId": "852e049b-72cc-4d7f-8be9-931c042fe019",
"tables": {
"account": {
@@ -515,193 +515,8 @@
"uniqueConstraints": {},
"checkConstraints": {}
},
"legacy_custom_widget_definition": {
"name": "legacy_custom_widget_definition",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"auth_type": {
"name": "auth_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"method": {
"name": "method",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"display_type": {
"name": "display_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'{\"json\": {}}'"
},
"enabled": {
"name": "enabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"creator_id": {
"name": "creator_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_definition_creator_id_user_id_fk": {
"name": "legacy_cw_definition_creator_id_user_id_fk",
"tableFrom": "legacy_custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"legacy_custom_widget_secret": {
"name": "legacy_custom_widget_secret",
"columns": {
"kind": {
"name": "kind",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"definition_id": {
"name": "definition_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"legacy_cw_secret_definition_id_fk": {
"name": "legacy_cw_secret_definition_id_fk",
"tableFrom": "legacy_custom_widget_secret",
"tableTo": "legacy_custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"legacy_custom_widget_secret_definition_id_kind_pk": {
"columns": ["definition_id", "kind"],
"name": "legacy_custom_widget_secret_definition_id_kind_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"custom_widget_definition": {
"name": "custom_widget_definition",
"custom_widget_v2_definition": {
"name": "custom_widget_v2_definition",
"columns": {
"id": {
"name": "id",
@@ -793,9 +608,9 @@
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"custom_widget_v2_definition_creator_id_user_id_fk": {
"name": "custom_widget_v2_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_v2_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
@@ -807,8 +622,8 @@
"uniqueConstraints": {},
"checkConstraints": {}
},
"custom_widget_secret": {
"name": "custom_widget_secret",
"custom_widget_v2_secret": {
"name": "custom_widget_v2_secret",
"columns": {
"source_id": {
"name": "source_id",
@@ -848,10 +663,10 @@
},
"indexes": {},
"foreignKeys": {
"cw_secret_definition_id_fk": {
"name": "cw_secret_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"custom_widget_v2_secret_definition_id_fk": {
"name": "custom_widget_v2_secret_definition_id_fk",
"tableFrom": "custom_widget_v2_secret",
"tableTo": "custom_widget_v2_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
@@ -859,9 +674,9 @@
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_source_id_kind_pk": {
"custom_widget_v2_secret_definition_id_source_id_kind_pk": {
"columns": ["definition_id", "source_id", "kind"],
"name": "custom_widget_secret_definition_id_source_id_kind_pk"
"name": "custom_widget_v2_secret_definition_id_source_id_kind_pk"
}
},
"uniqueConstraints": {},
@@ -1656,6 +1471,191 @@
"uniqueConstraints": {},
"checkConstraints": {}
},
"custom_widget_definition": {
"name": "custom_widget_definition",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"icon_url": {
"name": "icon_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"auth_type": {
"name": "auth_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'none'"
},
"header_name": {
"name": "header_name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"method": {
"name": "method",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'GET'"
},
"request_body": {
"name": "request_body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"display_type": {
"name": "display_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'singleValue'"
},
"display_config": {
"name": "display_config",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'{\"json\": {}}'"
},
"enabled": {
"name": "enabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(unixepoch())"
},
"creator_id": {
"name": "creator_id",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"custom_widget_definition_creator_id_user_id_fk": {
"name": "custom_widget_definition_creator_id_user_id_fk",
"tableFrom": "custom_widget_definition",
"tableTo": "user",
"columnsFrom": ["creator_id"],
"columnsTo": ["id"],
"onDelete": "set null",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"custom_widget_secret": {
"name": "custom_widget_secret",
"columns": {
"kind": {
"name": "kind",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"definition_id": {
"name": "definition_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"custom_widget_secret_definition_id_custom_widget_definition_id_fk": {
"name": "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
"tableFrom": "custom_widget_secret",
"tableTo": "custom_widget_definition",
"columnsFrom": ["definition_id"],
"columnsTo": ["id"],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"custom_widget_secret_definition_id_kind_pk": {
"columns": ["definition_id", "kind"],
"name": "custom_widget_secret_definition_id_kind_pk"
}
},
"uniqueConstraints": {},
"checkConstraints": {}
},
"media": {
"name": "media",
"columns": {
@@ -300,7 +300,7 @@
"idx": 42,
"version": "6",
"when": 1784305283910,
"tag": "0042_custom_widget_v2_reset",
"tag": "0042_custom_widget_v2_tables",
"breakpoints": true
}
]
+8 -8
View File
@@ -503,10 +503,10 @@ export const onboarding = mysqlTable("onboarding", {
/**
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
* They remain separate so legacy code can never execute in the v2 runtime.
* Their original physical table names keep the database readable by a v1 binary.
*/
export const legacyCustomWidgetDefinitions = mysqlTable(
"legacy_custom_widget_definition",
"custom_widget_definition",
{
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 256 }).notNull(),
@@ -528,13 +528,13 @@ export const legacyCustomWidgetDefinitions = mysqlTable(
creatorFk: foreignKey({
columns: [table.creatorId],
foreignColumns: [users.id],
name: "legacy_cw_definition_creator_id_user_id_fk",
name: "custom_widget_definition_creator_id_user_id_fk",
}).onDelete("set null"),
}),
);
export const legacyCustomWidgetSecrets = mysqlTable(
"legacy_custom_widget_secret",
"custom_widget_secret",
{
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
@@ -546,12 +546,12 @@ export const legacyCustomWidgetSecrets = mysqlTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [legacyCustomWidgetDefinitions.id],
name: "legacy_cw_secret_definition_id_fk",
name: "cw_secret_definition_id_cw_definition_id_fk",
}).onDelete("cascade"),
}),
);
export const customWidgetDefinitions = mysqlTable("custom_widget_definition", {
export const customWidgetDefinitions = mysqlTable("custom_widget_v2_definition", {
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 256 }).notNull(),
description: text(),
@@ -567,7 +567,7 @@ export const customWidgetDefinitions = mysqlTable("custom_widget_definition", {
});
export const customWidgetSecrets = mysqlTable(
"custom_widget_secret",
"custom_widget_v2_secret",
{
sourceId: varchar({ length: 64 }).notNull(),
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
@@ -584,7 +584,7 @@ export const customWidgetSecrets = mysqlTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [customWidgetDefinitions.id],
name: "cw_secret_definition_id_fk",
name: "custom_widget_v2_secret_definition_id_fk",
}).onDelete("cascade"),
}),
);
+8 -8
View File
@@ -502,10 +502,10 @@ export const onboarding = pgTable("onboarding", {
/**
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
* They remain separate so legacy code can never execute in the v2 runtime.
* Their original physical table names keep the database readable by a v1 binary.
*/
export const legacyCustomWidgetDefinitions = pgTable(
"legacy_custom_widget_definition",
"custom_widget_definition",
{
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 256 }).notNull(),
@@ -527,13 +527,13 @@ export const legacyCustomWidgetDefinitions = pgTable(
creatorFk: foreignKey({
columns: [table.creatorId],
foreignColumns: [users.id],
name: "legacy_cw_definition_creator_id_user_id_fk",
name: "custom_widget_definition_creator_id_user_id_fk",
}).onDelete("set null"),
}),
);
export const legacyCustomWidgetSecrets = pgTable(
"legacy_custom_widget_secret",
"custom_widget_secret",
{
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
@@ -545,12 +545,12 @@ export const legacyCustomWidgetSecrets = pgTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [legacyCustomWidgetDefinitions.id],
name: "legacy_cw_secret_definition_id_fk",
name: "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
}).onDelete("cascade"),
}),
);
export const customWidgetDefinitions = pgTable("custom_widget_definition", {
export const customWidgetDefinitions = pgTable("custom_widget_v2_definition", {
id: varchar({ length: 64 }).notNull().primaryKey(),
name: varchar({ length: 256 }).notNull(),
description: text(),
@@ -566,7 +566,7 @@ export const customWidgetDefinitions = pgTable("custom_widget_definition", {
});
export const customWidgetSecrets = pgTable(
"custom_widget_secret",
"custom_widget_v2_secret",
{
sourceId: varchar({ length: 64 }).notNull(),
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
@@ -583,7 +583,7 @@ export const customWidgetSecrets = pgTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [customWidgetDefinitions.id],
name: "cw_secret_definition_id_fk",
name: "custom_widget_v2_secret_definition_id_fk",
}).onDelete("cascade"),
}),
);
+8 -8
View File
@@ -487,10 +487,10 @@ export const onboarding = sqliteTable("onboarding", {
/**
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
* They remain separate so legacy code can never execute in the v2 runtime.
* Their original physical table names keep the database readable by a v1 binary.
*/
export const legacyCustomWidgetDefinitions = sqliteTable(
"legacy_custom_widget_definition",
"custom_widget_definition",
{
id: text().notNull().primaryKey(),
name: text().notNull(),
@@ -516,13 +516,13 @@ export const legacyCustomWidgetDefinitions = sqliteTable(
creatorFk: foreignKey({
columns: [table.creatorId],
foreignColumns: [users.id],
name: "legacy_cw_definition_creator_id_user_id_fk",
name: "custom_widget_definition_creator_id_user_id_fk",
}).onDelete("set null"),
}),
);
export const legacyCustomWidgetSecrets = sqliteTable(
"legacy_custom_widget_secret",
"custom_widget_secret",
{
kind: text().$type<CustomWidgetSecretKind>().notNull(),
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
@@ -534,12 +534,12 @@ export const legacyCustomWidgetSecrets = sqliteTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [legacyCustomWidgetDefinitions.id],
name: "legacy_cw_secret_definition_id_fk",
name: "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
}).onDelete("cascade"),
}),
);
export const customWidgetDefinitions = sqliteTable("custom_widget_definition", {
export const customWidgetDefinitions = sqliteTable("custom_widget_v2_definition", {
id: text().notNull().primaryKey(),
name: text().notNull(),
description: text(),
@@ -559,7 +559,7 @@ export const customWidgetDefinitions = sqliteTable("custom_widget_definition", {
});
export const customWidgetSecrets = sqliteTable(
"custom_widget_secret",
"custom_widget_v2_secret",
{
sourceId: text().notNull(),
kind: text().$type<CustomWidgetSecretKind>().notNull(),
@@ -576,7 +576,7 @@ export const customWidgetSecrets = sqliteTable(
definitionFk: foreignKey({
columns: [table.definitionId],
foreignColumns: [customWidgetDefinitions.id],
name: "cw_secret_definition_id_fk",
name: "custom_widget_v2_secret_definition_id_fk",
}).onDelete("cascade"),
}),
);
+86 -15
View File
@@ -4,6 +4,7 @@ import { MySqlContainer } from "@testcontainers/mysql";
import { drizzle } from "drizzle-orm/mysql2";
import { migrate } from "drizzle-orm/mysql2/migrator";
import mysql from "mysql2";
import SuperJSON from "superjson";
import { describe, expect, test } from "vitest";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
@@ -13,6 +14,16 @@ import type { Database } from "..";
import { seedDataAsync } from "../migrations/seed";
import { expectBundledCustomWidgetsSeeded } from "./custom-widget-seed-assertions";
const applyMigration = async (connection: mysql.Connection, fileName: string) => {
const migration = readFileSync(path.join(__dirname, "..", "migrations", "mysql", fileName), "utf8");
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
await connection.promise().query(statement);
}
};
describe("Mysql Migration", () => {
test("should add all tables and keys specified in migration files", async () => {
const mysqlContainer = await new MySqlContainer("mysql:latest").start();
@@ -40,12 +51,16 @@ describe("Mysql Migration", () => {
// Check if users table exists
await database.query.users.findMany();
await expectBundledCustomWidgetsSeeded(database as unknown as Database);
const [customWidgetTables] = await connection
.promise()
.query<mysql.RowDataPacket[]>("SHOW TABLES LIKE 'custom_widget%'");
expect(customWidgetTables).toHaveLength(4);
connection.end();
await mysqlContainer.stop();
}, 90_000);
test("preserves populated v1 custom widgets and encrypted secrets", async () => {
test("Custom Widget v2 migration preserves v1 data and board references", async () => {
const mysqlContainer = await new MySqlContainer("mysql:latest").start();
const connection = mysql.createConnection({
host: mysqlContainer.getHost(),
@@ -57,8 +72,18 @@ describe("Mysql Migration", () => {
});
const sql = connection.promise();
try {
const legacyPlacementOptions = SuperJSON.stringify({ definitionId: "legacy-weather", refreshInterval: 30 });
await sql.query(`
CREATE TABLE \`user\` (\`id\` varchar(64) NOT NULL PRIMARY KEY);
CREATE TABLE \`groupPermission\` (
\`group_id\` varchar(64) NOT NULL,
\`permission\` text NOT NULL
);
CREATE TABLE \`item\` (
\`id\` varchar(64) NOT NULL PRIMARY KEY,
\`kind\` varchar(64) NOT NULL,
\`options\` text NOT NULL
);
CREATE TABLE \`custom_widget_definition\` (
\`id\` varchar(64) NOT NULL PRIMARY KEY,
\`name\` varchar(256) NOT NULL,
@@ -98,31 +123,77 @@ describe("Mysql Migration", () => {
);
INSERT INTO \`custom_widget_secret\` (\`kind\`, \`value\`, \`updated_at\`, \`definition_id\`)
VALUES ('apiKey', 'encrypted.value', '2023-11-14 00:00:01', 'legacy-weather');
INSERT INTO \`groupPermission\` (\`group_id\`, \`permission\`) VALUES
('editors', 'custom-widget-manage'),
('editors', 'custom-widget-secret-write'),
('editors', 'board-create');
`);
await sql.execute("INSERT INTO `item` (`id`, `kind`, `options`) VALUES ('weather-item', 'customApi', ?)", [
legacyPlacementOptions,
]);
await applyMigration(connection, "0044_custom_widget_v2_tables.sql");
await sql.query(`
INSERT INTO \`custom_widget_v2_definition\` (
\`id\`, \`name\`, \`sources\`, \`requests\`, \`options\`, \`template\`, \`enabled\`,
\`created_at\`, \`updated_at\`, \`creator_id\`
) VALUES (
'legacy-weather', 'Weather v2', '[]', '[]', '[]', '<Text>Weather</Text>', true,
'2023-11-14 00:00:02', '2023-11-14 00:00:03', 'owner'
);
INSERT INTO \`custom_widget_v2_secret\` (
\`source_id\`, \`kind\`, \`encrypted_value\`, \`updated_at\`, \`definition_id\`
) VALUES ('weather', 'apiKey', 'encrypted.v2-value', '2023-11-14 00:00:03', 'legacy-weather');
`);
const migration = readFileSync(
path.join(__dirname, "..", "migrations", "mysql", "0044_custom_widget_v2_reset.sql"),
"utf8",
);
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
await sql.query(statement);
}
const [definitions] = await sql.query<mysql.RowDataPacket[]>(
"SELECT id, name, enabled, creator_id FROM legacy_custom_widget_definition",
"SELECT id, name, url, enabled, creator_id FROM custom_widget_definition",
);
const [secrets] = await sql.query<mysql.RowDataPacket[]>(
"SELECT definition_id, kind, value FROM legacy_custom_widget_secret",
"SELECT definition_id, kind, value FROM custom_widget_secret",
);
expect(definitions).toEqual([
expect.objectContaining({ id: "legacy-weather", name: "Weather", enabled: 1, creator_id: "owner" }),
expect.objectContaining({
id: "legacy-weather",
name: "Weather",
url: "https://example.test/weather",
enabled: 1,
creator_id: "owner",
}),
]);
expect(secrets).toEqual([
expect.objectContaining({ definition_id: "legacy-weather", kind: "apiKey", value: "encrypted.value" }),
]);
const [v2Definitions] = await sql.query<mysql.RowDataPacket[]>(
"SELECT id, name, template FROM custom_widget_v2_definition",
);
const [v2Secrets] = await sql.query<mysql.RowDataPacket[]>(
"SELECT definition_id, source_id, kind, encrypted_value FROM custom_widget_v2_secret",
);
expect(v2Definitions).toEqual([
expect.objectContaining({ id: "legacy-weather", name: "Weather v2", template: "<Text>Weather</Text>" }),
]);
expect(v2Secrets).toEqual([
expect.objectContaining({
definition_id: "legacy-weather",
source_id: "weather",
kind: "apiKey",
encrypted_value: "encrypted.v2-value",
}),
]);
const [items] = await sql.query<mysql.RowDataPacket[]>("SELECT options FROM item WHERE id = 'weather-item'");
expect(items).toEqual([{ options: legacyPlacementOptions }]);
const [permissions] = await sql.query<mysql.RowDataPacket[]>(
"SELECT permission FROM groupPermission ORDER BY permission",
);
expect(permissions).toEqual([{ permission: "board-create" }]);
const [v1Columns] = await sql.query<mysql.RowDataPacket[]>("SHOW COLUMNS FROM custom_widget_definition");
expect(v1Columns.map((column) => column.Field)).toEqual(
expect.arrayContaining(["id", "url", "auth_type", "display_type", "display_config"]),
);
expect(v1Columns.map((column) => column.Field)).not.toContain("sources");
const [legacyTables] = await sql.query<mysql.RowDataPacket[]>("SHOW TABLES LIKE 'legacy_custom_widget%'");
expect(legacyTables).toEqual([]);
} finally {
await sql.end();
await mysqlContainer.stop();
+92 -15
View File
@@ -4,6 +4,7 @@ import { PostgreSqlContainer } from "@testcontainers/postgresql";
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import { Pool } from "pg";
import SuperJSON from "superjson";
import { describe, expect, test } from "vitest";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
@@ -13,6 +14,16 @@ import type { Database } from "..";
import { seedDataAsync } from "../migrations/seed";
import { expectBundledCustomWidgetsSeeded } from "./custom-widget-seed-assertions";
const applyMigration = async (pool: Pool, fileName: string) => {
const migration = readFileSync(path.join(__dirname, "..", "migrations", "postgresql", fileName), "utf8");
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
await pool.query(statement);
}
};
describe("PostgreSql Migration", () => {
test("should add all tables and keys specified in migration files", async () => {
const container = new PostgreSqlContainer("postgres:latest");
@@ -45,6 +56,13 @@ describe("PostgreSql Migration", () => {
// Check if users table exists
await database.query.users.findMany();
await expectBundledCustomWidgetsSeeded(database as unknown as Database);
expect(
(
await pool.query(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'custom_widget%'",
)
).rows,
).toHaveLength(4);
// Close the pool to release resources
await pool.end();
@@ -52,7 +70,7 @@ describe("PostgreSql Migration", () => {
await postgreSqlContainer.stop();
}, 40_000);
test("preserves populated v1 custom widgets and encrypted secrets", async () => {
test("Custom Widget v2 migration preserves v1 data and board references", async () => {
const postgreSqlContainer = await new PostgreSqlContainer("postgres:latest").start();
const pool = new Pool({
user: postgreSqlContainer.getUsername(),
@@ -62,8 +80,18 @@ describe("PostgreSql Migration", () => {
host: postgreSqlContainer.getHost(),
});
try {
const legacyPlacementOptions = SuperJSON.stringify({ definitionId: "legacy-weather", refreshInterval: 30 });
await pool.query(`
CREATE TABLE "user" ("id" varchar(64) PRIMARY KEY NOT NULL);
CREATE TABLE "groupPermission" (
"group_id" varchar(64) NOT NULL,
"permission" text NOT NULL
);
CREATE TABLE "item" (
"id" varchar(64) PRIMARY KEY NOT NULL,
"kind" varchar(64) NOT NULL,
"options" text NOT NULL
);
CREATE TABLE "custom_widget_definition" (
"id" varchar(64) PRIMARY KEY NOT NULL,
"name" varchar(256) NOT NULL,
@@ -103,27 +131,76 @@ describe("PostgreSql Migration", () => {
);
INSERT INTO "custom_widget_secret" ("kind", "value", "updated_at", "definition_id")
VALUES ('apiKey', 'encrypted.value', '2023-11-14 00:00:01', 'legacy-weather');
INSERT INTO "groupPermission" ("group_id", "permission") VALUES
('editors', 'custom-widget-manage'),
('editors', 'custom-widget-secret-write'),
('editors', 'board-create');
`);
await pool.query(`INSERT INTO "item" ("id", "kind", "options") VALUES ('weather-item', 'customApi', $1)`, [
legacyPlacementOptions,
]);
await applyMigration(pool, "0010_custom_widget_v2_tables.sql");
await pool.query(`
INSERT INTO "custom_widget_v2_definition" (
"id", "name", "sources", "requests", "options", "template", "enabled",
"created_at", "updated_at", "creator_id"
) VALUES (
'legacy-weather', 'Weather v2', '[]', '[]', '[]', '<Text>Weather</Text>', true,
'2023-11-14 00:00:02', '2023-11-14 00:00:03', 'owner'
);
INSERT INTO "custom_widget_v2_secret" (
"source_id", "kind", "encrypted_value", "updated_at", "definition_id"
) VALUES ('weather', 'apiKey', 'encrypted.v2-value', '2023-11-14 00:00:03', 'legacy-weather');
`);
const migration = readFileSync(
path.join(__dirname, "..", "migrations", "postgresql", "0010_custom_widget_v2_reset.sql"),
"utf8",
);
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
await pool.query(statement);
}
expect(
(await pool.query("SELECT id, name, enabled, creator_id FROM legacy_custom_widget_definition")).rows,
(await pool.query("SELECT id, name, url, enabled, creator_id FROM custom_widget_definition")).rows,
).toEqual([
expect.objectContaining({ id: "legacy-weather", name: "Weather", enabled: true, creator_id: "owner" }),
expect.objectContaining({
id: "legacy-weather",
name: "Weather",
url: "https://example.test/weather",
enabled: true,
creator_id: "owner",
}),
]);
expect((await pool.query("SELECT definition_id, kind, value FROM legacy_custom_widget_secret")).rows).toEqual([
expect((await pool.query("SELECT definition_id, kind, value FROM custom_widget_secret")).rows).toEqual([
expect.objectContaining({ definition_id: "legacy-weather", kind: "apiKey", value: "encrypted.value" }),
]);
expect((await pool.query("SELECT id, name, template FROM custom_widget_v2_definition")).rows).toEqual([
expect.objectContaining({ id: "legacy-weather", name: "Weather v2", template: "<Text>Weather</Text>" }),
]);
expect(
(await pool.query("SELECT definition_id, source_id, kind, encrypted_value FROM custom_widget_v2_secret")).rows,
).toEqual([
expect.objectContaining({
definition_id: "legacy-weather",
source_id: "weather",
kind: "apiKey",
encrypted_value: "encrypted.v2-value",
}),
]);
expect((await pool.query("SELECT options FROM item WHERE id = 'weather-item'")).rows).toEqual([
{ options: legacyPlacementOptions },
]);
expect((await pool.query('SELECT "permission" FROM "groupPermission" ORDER BY "permission"')).rows).toEqual([
{ permission: "board-create" },
]);
const v1Columns = (
await pool.query(
"SELECT column_name FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'custom_widget_definition'",
)
).rows.map((column: { column_name: string }) => column.column_name);
expect(v1Columns).toEqual(expect.arrayContaining(["id", "url", "auth_type", "display_type", "display_config"]));
expect(v1Columns).not.toContain("sources");
expect(
(
await pool.query(
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name LIKE 'legacy_custom_widget%'",
)
).rows,
).toEqual([]);
} finally {
await pool.end();
await postgreSqlContainer.stop();
+90 -16
View File
@@ -3,6 +3,7 @@ import { readFileSync } from "node:fs";
import BetterSqlite3 from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import SuperJSON from "superjson";
import { expect, test } from "vitest";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
@@ -12,6 +13,16 @@ import { seedDataAsync } from "../migrations/seed";
import * as sqliteSchema from "../schema/sqlite";
import { expectBundledCustomWidgetsSeeded } from "./custom-widget-seed-assertions";
const applyMigration = (connection: BetterSqlite3.Database, fileName: string) => {
const migration = readFileSync(path.join(__dirname, "..", "migrations", "sqlite", fileName), "utf8");
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
connection.exec(statement);
}
};
test("SQLite migrations seed the five disabled bundled custom widgets", async () => {
const connection = new BetterSqlite3(":memory:");
const database = drizzle(connection, { schema: sqliteSchema, casing: DB_CASING });
@@ -20,14 +31,34 @@ test("SQLite migrations seed the five disabled bundled custom widgets", async ()
await seedDataAsync(database as unknown as Database);
await expectBundledCustomWidgetsSeeded(database as unknown as Database);
expect(
connection
.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE 'custom_widget%' ORDER BY name")
.all(),
).toEqual([
{ name: "custom_widget_definition" },
{ name: "custom_widget_secret" },
{ name: "custom_widget_v2_definition" },
{ name: "custom_widget_v2_secret" },
]);
connection.close();
});
test("Custom JSX v2 migration preserves populated v1 definitions and secrets", () => {
test("Custom Widget v2 migration preserves v1 data and board references", () => {
const connection = new BetterSqlite3(":memory:");
const legacyPlacementOptions = SuperJSON.stringify({ definitionId: "legacy-weather", refreshInterval: 30 });
connection.exec(`
CREATE TABLE user (id text PRIMARY KEY NOT NULL);
CREATE TABLE groupPermission (
group_id text NOT NULL,
permission text NOT NULL
);
CREATE TABLE item (
id text PRIMARY KEY NOT NULL,
kind text NOT NULL,
options text NOT NULL
);
CREATE TABLE custom_widget_definition (
id text PRIMARY KEY NOT NULL,
name text NOT NULL,
@@ -59,32 +90,75 @@ test("Custom JSX v2 migration preserves populated v1 definitions and secrets", (
'{"type":"singleValue","jsonPath":"$.temperature"}', true, 1700000000, 1700000001, 'owner');
INSERT INTO custom_widget_secret (kind, value, updated_at, definition_id)
VALUES ('apiKey', 'encrypted.value', 1700000001, 'legacy-weather');
INSERT INTO groupPermission (group_id, permission) VALUES
('editors', 'custom-widget-manage'),
('editors', 'custom-widget-secret-write'),
('editors', 'board-create');
`);
connection
.prepare("INSERT INTO item (id, kind, options) VALUES ('weather-item', 'customApi', ?)")
.run(legacyPlacementOptions);
applyMigration(connection, "0042_custom_widget_v2_tables.sql");
connection.exec(`
INSERT INTO custom_widget_v2_definition (
id, name, sources, requests, options, template, enabled, created_at, updated_at, creator_id
) VALUES (
'legacy-weather', 'Weather v2', '[]', '[]', '[]', '<Text>Weather</Text>', true,
1700000002, 1700000003, 'owner'
);
INSERT INTO custom_widget_v2_secret (source_id, kind, encrypted_value, updated_at, definition_id)
VALUES ('weather', 'apiKey', 'encrypted.v2-value', 1700000003, 'legacy-weather');
`);
const migration = readFileSync(
path.join(__dirname, "..", "migrations", "sqlite", "0042_custom_widget_v2_reset.sql"),
"utf8",
);
for (const statement of migration
.split("--> statement-breakpoint")
.map((value) => value.trim())
.filter(Boolean)) {
connection.exec(statement);
}
expect(connection.prepare("SELECT * FROM legacy_custom_widget_definition").get()).toMatchObject({
expect(connection.prepare("SELECT * FROM custom_widget_definition").get()).toMatchObject({
id: "legacy-weather",
name: "Weather",
url: "https://example.test/weather",
enabled: 1,
creator_id: "owner",
});
expect(connection.prepare("SELECT * FROM legacy_custom_widget_secret").get()).toMatchObject({
expect(connection.prepare("SELECT * FROM custom_widget_secret").get()).toMatchObject({
definition_id: "legacy-weather",
kind: "apiKey",
value: "encrypted.value",
});
expect(connection.prepare("SELECT count(*) AS count FROM custom_widget_definition").get()).toEqual({ count: 0 });
expect(connection.prepare("SELECT count(*) AS count FROM custom_widget_secret").get()).toEqual({ count: 0 });
expect(connection.prepare("SELECT * FROM custom_widget_v2_definition").get()).toMatchObject({
id: "legacy-weather",
name: "Weather v2",
template: "<Text>Weather</Text>",
});
expect(connection.prepare("SELECT * FROM custom_widget_v2_secret").get()).toMatchObject({
definition_id: "legacy-weather",
source_id: "weather",
encrypted_value: "encrypted.v2-value",
});
expect(connection.prepare("SELECT options FROM item WHERE id = 'weather-item'").get()).toEqual({
options: legacyPlacementOptions,
});
expect(connection.prepare("SELECT permission FROM groupPermission ORDER BY permission").all()).toEqual([
{ permission: "board-create" },
]);
expect(
connection
.prepare(
`SELECT id, name, url, auth_type, header_name, method, request_body, display_type, display_config,
enabled, created_at, updated_at, creator_id
FROM custom_widget_definition`,
)
.get(),
).toMatchObject({
id: "legacy-weather",
auth_type: "bearer",
display_type: "singleValue",
});
expect(
connection
.prepare(
"SELECT name FROM sqlite_master WHERE type = 'table' AND name LIKE 'legacy_custom_widget%' ORDER BY name",
)
.all(),
).toEqual([]);
connection.close();
});