fix(custom-widgets): address v2 merge review
This commit is contained in:
1 parent
6aceb2fd1f
commit
48ce83806d
122 files changed
+8534
-1447
No files matched your search
@@ -1,5 +1,8 @@
|
||||
DROP TABLE `custom_widget_secret`;--> statement-breakpoint
|
||||
DROP TABLE `custom_widget_definition`;--> statement-breakpoint
|
||||
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,
|
||||
@@ -24,4 +27,4 @@ CREATE TABLE `custom_widget_secret` (
|
||||
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_cw_definition_id_fk` FOREIGN KEY (`definition_id`) REFERENCES `custom_widget_definition`(`id`) ON DELETE cascade ON UPDATE no action;
|
||||
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;
|
||||
@@ -534,6 +534,196 @@
|
||||
"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",
|
||||
"columns": {
|
||||
@@ -687,8 +877,8 @@
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"custom_widget_secret_definition_id_custom_widget_definition_id_fk": {
|
||||
"name": "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
|
||||
"cw_secret_definition_id_fk": {
|
||||
"name": "cw_secret_definition_id_fk",
|
||||
"tableFrom": "custom_widget_secret",
|
||||
"tableTo": "custom_widget_definition",
|
||||
"columnsFrom": ["definition_id"],
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
DROP TABLE "custom_widget_secret";--> statement-breakpoint
|
||||
DROP TABLE "custom_widget_definition";--> 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
|
||||
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,
|
||||
@@ -23,4 +26,4 @@ CREATE TABLE "custom_widget_secret" (
|
||||
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 "custom_widget_secret_definition_id_custom_widget_definition_id_fk" FOREIGN KEY ("definition_id") REFERENCES "public"."custom_widget_definition"("id") ON DELETE cascade ON UPDATE no action;
|
||||
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;
|
||||
@@ -498,6 +498,178 @@
|
||||
"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",
|
||||
"schema": "",
|
||||
@@ -633,8 +805,8 @@
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"custom_widget_secret_definition_id_custom_widget_definition_id_fk": {
|
||||
"name": "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
|
||||
"cw_secret_definition_id_fk": {
|
||||
"name": "cw_secret_definition_id_fk",
|
||||
"tableFrom": "custom_widget_secret",
|
||||
"tableTo": "custom_widget_definition",
|
||||
"columnsFrom": ["definition_id"],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
PRAGMA foreign_keys=OFF;--> statement-breakpoint
|
||||
DROP TABLE `custom_widget_secret`;--> statement-breakpoint
|
||||
DROP TABLE `custom_widget_definition`;--> 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` (
|
||||
`id` text PRIMARY KEY NOT NULL,
|
||||
`name` text NOT NULL,
|
||||
|
||||
@@ -515,6 +515,191 @@
|
||||
"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",
|
||||
"columns": {
|
||||
@@ -663,8 +848,8 @@
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"custom_widget_secret_definition_id_custom_widget_definition_id_fk": {
|
||||
"name": "custom_widget_secret_definition_id_custom_widget_definition_id_fk",
|
||||
"cw_secret_definition_id_fk": {
|
||||
"name": "cw_secret_definition_id_fk",
|
||||
"tableFrom": "custom_widget_secret",
|
||||
"tableTo": "custom_widget_definition",
|
||||
"columnsFrom": ["definition_id"],
|
||||
|
||||
@@ -51,6 +51,8 @@ export const {
|
||||
cronJobConfigurations,
|
||||
customWidgetDefinitions,
|
||||
customWidgetSecrets,
|
||||
legacyCustomWidgetDefinitions,
|
||||
legacyCustomWidgetSecrets,
|
||||
widgetSecrets,
|
||||
} = schema;
|
||||
|
||||
@@ -62,3 +64,5 @@ export type Integration = InferSelectModel<typeof schema.integrations>;
|
||||
export type IntegrationSecret = InferSelectModel<typeof schema.integrationSecrets>;
|
||||
export type CustomWidgetDefinition = InferSelectModel<typeof schema.customWidgetDefinitions>;
|
||||
export type CustomWidgetSecret = InferSelectModel<typeof schema.customWidgetSecrets>;
|
||||
export type LegacyCustomWidgetDefinition = InferSelectModel<typeof schema.legacyCustomWidgetDefinitions>;
|
||||
export type LegacyCustomWidgetSecret = InferSelectModel<typeof schema.legacyCustomWidgetSecrets>;
|
||||
@@ -6,6 +6,7 @@ import type { AnyMySqlColumn } from "drizzle-orm/mysql-core";
|
||||
import {
|
||||
boolean,
|
||||
customType,
|
||||
foreignKey,
|
||||
index,
|
||||
int,
|
||||
mysqlTable,
|
||||
@@ -206,8 +207,8 @@ export const integrations = mysqlTable(
|
||||
kind: varchar({ length: 128 }).$type<IntegrationKind>().notNull(),
|
||||
appId: varchar({ length: 128 }).references(() => apps.id, { onDelete: "set null" }),
|
||||
},
|
||||
(integrations) => ({
|
||||
kindIdx: index("integration__kind_idx").on(integrations.kind),
|
||||
(table) => ({
|
||||
kindIdx: index("integration__kind_idx").on(table.kind),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -500,6 +501,56 @@ export const onboarding = mysqlTable("onboarding", {
|
||||
previousStep: varchar({ length: 64 }).$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
|
||||
* They remain separate so legacy code can never execute in the v2 runtime.
|
||||
*/
|
||||
export const legacyCustomWidgetDefinitions = mysqlTable(
|
||||
"legacy_custom_widget_definition",
|
||||
{
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: varchar({ length: 32 }).notNull().default("none"),
|
||||
headerName: varchar({ length: 256 }),
|
||||
method: varchar({ length: 16 }).notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: varchar({ length: 32 }).notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: boolean().notNull().default(true),
|
||||
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
creatorId: varchar({ length: 64 }),
|
||||
},
|
||||
(table) => ({
|
||||
creatorFk: foreignKey({
|
||||
columns: [table.creatorId],
|
||||
foreignColumns: [users.id],
|
||||
name: "legacy_cw_definition_creator_id_user_id_fk",
|
||||
}).onDelete("set null"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const legacyCustomWidgetSecrets = mysqlTable(
|
||||
"legacy_custom_widget_secret",
|
||||
{
|
||||
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
|
||||
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: timestamp().notNull(),
|
||||
definitionId: varchar({ length: 64 }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({ columns: [table.definitionId, table.kind] }),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [legacyCustomWidgetDefinitions.id],
|
||||
name: "legacy_cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const customWidgetDefinitions = mysqlTable("custom_widget_definition", {
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
@@ -524,14 +575,17 @@ export const customWidgetSecrets = mysqlTable(
|
||||
updatedAt: timestamp()
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
definitionId: varchar({ length: 64 }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.sourceId, table.kind],
|
||||
}),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [customWidgetDefinitions.id],
|
||||
name: "cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -847,3 +901,18 @@ export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetDefinitionRelations = relations(legacyCustomWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(legacyCustomWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [legacyCustomWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetSecretRelations = relations(legacyCustomWidgetSecrets, ({ one }) => ({
|
||||
definition: one(legacyCustomWidgetDefinitions, {
|
||||
fields: [legacyCustomWidgetSecrets.definitionId],
|
||||
references: [legacyCustomWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
@@ -6,6 +6,7 @@ import type { AnyPgColumn } from "drizzle-orm/pg-core";
|
||||
import {
|
||||
boolean,
|
||||
customType,
|
||||
foreignKey,
|
||||
index,
|
||||
integer,
|
||||
pgTable,
|
||||
@@ -205,8 +206,8 @@ export const integrations = pgTable(
|
||||
kind: varchar({ length: 128 }).$type<IntegrationKind>().notNull(),
|
||||
appId: varchar({ length: 128 }).references(() => apps.id, { onDelete: "set null" }),
|
||||
},
|
||||
(integrations) => ({
|
||||
kindIdx: index("integration__kind_idx").on(integrations.kind),
|
||||
(table) => ({
|
||||
kindIdx: index("integration__kind_idx").on(table.kind),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -499,6 +500,56 @@ export const onboarding = pgTable("onboarding", {
|
||||
previousStep: varchar({ length: 64 }).$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
|
||||
* They remain separate so legacy code can never execute in the v2 runtime.
|
||||
*/
|
||||
export const legacyCustomWidgetDefinitions = pgTable(
|
||||
"legacy_custom_widget_definition",
|
||||
{
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: varchar({ length: 32 }).notNull().default("none"),
|
||||
headerName: varchar({ length: 256 }),
|
||||
method: varchar({ length: 16 }).notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: varchar({ length: 32 }).notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: boolean().notNull().default(true),
|
||||
createdAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ mode: "date" }).notNull().defaultNow(),
|
||||
creatorId: varchar({ length: 64 }),
|
||||
},
|
||||
(table) => ({
|
||||
creatorFk: foreignKey({
|
||||
columns: [table.creatorId],
|
||||
foreignColumns: [users.id],
|
||||
name: "legacy_cw_definition_creator_id_user_id_fk",
|
||||
}).onDelete("set null"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const legacyCustomWidgetSecrets = pgTable(
|
||||
"legacy_custom_widget_secret",
|
||||
{
|
||||
kind: varchar({ length: 64 }).$type<CustomWidgetSecretKind>().notNull(),
|
||||
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: timestamp().notNull(),
|
||||
definitionId: varchar({ length: 64 }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({ columns: [table.definitionId, table.kind] }),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [legacyCustomWidgetDefinitions.id],
|
||||
name: "legacy_cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const customWidgetDefinitions = pgTable("custom_widget_definition", {
|
||||
id: varchar({ length: 64 }).notNull().primaryKey(),
|
||||
name: varchar({ length: 256 }).notNull(),
|
||||
@@ -523,14 +574,17 @@ export const customWidgetSecrets = pgTable(
|
||||
updatedAt: timestamp()
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: varchar({ length: 64 })
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
definitionId: varchar({ length: 64 }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.sourceId, table.kind],
|
||||
}),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [customWidgetDefinitions.id],
|
||||
name: "cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -846,3 +900,18 @@ export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetDefinitionRelations = relations(legacyCustomWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(legacyCustomWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [legacyCustomWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetSecretRelations = relations(legacyCustomWidgetSecrets, ({ one }) => ({
|
||||
definition: one(legacyCustomWidgetDefinitions, {
|
||||
fields: [legacyCustomWidgetSecrets.definitionId],
|
||||
references: [legacyCustomWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
@@ -3,7 +3,7 @@ import type { MantineSize } from "@mantine/core";
|
||||
import type { DayOfWeek } from "@mantine/dates";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import type { AnySQLiteColumn } from "drizzle-orm/sqlite-core";
|
||||
import { blob, index, int, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
import { blob, foreignKey, index, int, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
|
||||
import {
|
||||
backgroundImageAttachments,
|
||||
@@ -192,8 +192,8 @@ export const integrations = sqliteTable(
|
||||
kind: text().$type<IntegrationKind>().notNull(),
|
||||
appId: text().references(() => apps.id, { onDelete: "set null" }),
|
||||
},
|
||||
(integrations) => ({
|
||||
kindIdx: index("integration__kind_idx").on(integrations.kind),
|
||||
(table) => ({
|
||||
kindIdx: index("integration__kind_idx").on(table.kind),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -485,6 +485,60 @@ export const onboarding = sqliteTable("onboarding", {
|
||||
previousStep: text().$type<OnboardingStep>(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Read-only v1 definitions retained during the Custom JSX v2 upgrade.
|
||||
* They remain separate so legacy code can never execute in the v2 runtime.
|
||||
*/
|
||||
export const legacyCustomWidgetDefinitions = sqliteTable(
|
||||
"legacy_custom_widget_definition",
|
||||
{
|
||||
id: text().notNull().primaryKey(),
|
||||
name: text().notNull(),
|
||||
description: text(),
|
||||
iconUrl: text(),
|
||||
url: text().notNull(),
|
||||
authType: text().notNull().default("none"),
|
||||
headerName: text(),
|
||||
method: text().notNull().default("GET"),
|
||||
requestBody: text(),
|
||||
displayType: text().notNull().default("singleValue"),
|
||||
displayConfig: text().default(emptySuperJSON).notNull(),
|
||||
enabled: int({ mode: "boolean" }).notNull().default(true),
|
||||
createdAt: int({ mode: "timestamp" })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch())`),
|
||||
updatedAt: int({ mode: "timestamp" })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch())`),
|
||||
creatorId: text(),
|
||||
},
|
||||
(table) => ({
|
||||
creatorFk: foreignKey({
|
||||
columns: [table.creatorId],
|
||||
foreignColumns: [users.id],
|
||||
name: "legacy_cw_definition_creator_id_user_id_fk",
|
||||
}).onDelete("set null"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const legacyCustomWidgetSecrets = sqliteTable(
|
||||
"legacy_custom_widget_secret",
|
||||
{
|
||||
kind: text().$type<CustomWidgetSecretKind>().notNull(),
|
||||
encryptedValue: text("value").$type<`${string}.${string}`>().notNull(),
|
||||
updatedAt: int({ mode: "timestamp" }).notNull(),
|
||||
definitionId: text().notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({ columns: [table.definitionId, table.kind] }),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [legacyCustomWidgetDefinitions.id],
|
||||
name: "legacy_cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
export const customWidgetDefinitions = sqliteTable("custom_widget_definition", {
|
||||
id: text().notNull().primaryKey(),
|
||||
name: text().notNull(),
|
||||
@@ -513,14 +567,17 @@ export const customWidgetSecrets = sqliteTable(
|
||||
updatedAt: int({ mode: "timestamp" })
|
||||
.$onUpdateFn(() => new Date())
|
||||
.notNull(),
|
||||
definitionId: text()
|
||||
.notNull()
|
||||
.references(() => customWidgetDefinitions.id, { onDelete: "cascade" }),
|
||||
definitionId: text().notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
compoundKey: primaryKey({
|
||||
columns: [table.definitionId, table.sourceId, table.kind],
|
||||
}),
|
||||
definitionFk: foreignKey({
|
||||
columns: [table.definitionId],
|
||||
foreignColumns: [customWidgetDefinitions.id],
|
||||
name: "cw_secret_definition_id_fk",
|
||||
}).onDelete("cascade"),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -836,3 +893,18 @@ export const customWidgetSecretRelations = relations(customWidgetSecrets, ({ one
|
||||
references: [customWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetDefinitionRelations = relations(legacyCustomWidgetDefinitions, ({ many, one }) => ({
|
||||
secrets: many(legacyCustomWidgetSecrets),
|
||||
creator: one(users, {
|
||||
fields: [legacyCustomWidgetDefinitions.creatorId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const legacyCustomWidgetSecretRelations = relations(legacyCustomWidgetSecrets, ({ one }) => ({
|
||||
definition: one(legacyCustomWidgetDefinitions, {
|
||||
fields: [legacyCustomWidgetSecrets.definitionId],
|
||||
references: [legacyCustomWidgetDefinitions.id],
|
||||
}),
|
||||
}));
|
||||
@@ -1,9 +1,10 @@
|
||||
import path from "path";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { MySqlContainer } from "@testcontainers/mysql";
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import { migrate } from "drizzle-orm/mysql2/migrator";
|
||||
import mysql from "mysql2";
|
||||
import { describe, test } from "vitest";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
|
||||
|
||||
@@ -43,4 +44,88 @@ describe("Mysql Migration", () => {
|
||||
connection.end();
|
||||
await mysqlContainer.stop();
|
||||
}, 40_000);
|
||||
|
||||
test("preserves populated v1 custom widgets and encrypted secrets", async () => {
|
||||
const mysqlContainer = await new MySqlContainer("mysql:latest").start();
|
||||
const connection = mysql.createConnection({
|
||||
host: mysqlContainer.getHost(),
|
||||
database: mysqlContainer.getDatabase(),
|
||||
port: mysqlContainer.getPort(),
|
||||
user: mysqlContainer.getUsername(),
|
||||
password: mysqlContainer.getUserPassword(),
|
||||
multipleStatements: true,
|
||||
});
|
||||
const sql = connection.promise();
|
||||
try {
|
||||
await sql.query(`
|
||||
CREATE TABLE \`user\` (\`id\` varchar(64) NOT NULL PRIMARY KEY);
|
||||
CREATE TABLE \`custom_widget_definition\` (
|
||||
\`id\` varchar(64) NOT NULL PRIMARY KEY,
|
||||
\`name\` varchar(256) NOT NULL,
|
||||
\`description\` text,
|
||||
\`icon_url\` text,
|
||||
\`url\` text NOT NULL,
|
||||
\`auth_type\` varchar(32) NOT NULL DEFAULT 'none',
|
||||
\`header_name\` varchar(256),
|
||||
\`method\` varchar(16) NOT NULL DEFAULT 'GET',
|
||||
\`request_body\` text,
|
||||
\`display_type\` varchar(32) NOT NULL DEFAULT 'singleValue',
|
||||
\`display_config\` text NOT NULL,
|
||||
\`enabled\` boolean NOT NULL DEFAULT true,
|
||||
\`created_at\` timestamp NOT NULL,
|
||||
\`updated_at\` timestamp NOT NULL,
|
||||
\`creator_id\` varchar(64),
|
||||
CONSTRAINT \`custom_widget_definition_creator_id_user_id_fk\`
|
||||
FOREIGN KEY (\`creator_id\`) REFERENCES \`user\`(\`id\`) ON DELETE SET NULL
|
||||
);
|
||||
CREATE TABLE \`custom_widget_secret\` (
|
||||
\`kind\` varchar(64) NOT NULL,
|
||||
\`value\` text NOT NULL,
|
||||
\`updated_at\` timestamp NOT NULL,
|
||||
\`definition_id\` varchar(64) NOT NULL,
|
||||
PRIMARY KEY (\`definition_id\`, \`kind\`),
|
||||
CONSTRAINT \`cw_secret_definition_id_cw_definition_id_fk\`
|
||||
FOREIGN KEY (\`definition_id\`) REFERENCES \`custom_widget_definition\`(\`id\`) ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO \`user\` (\`id\`) VALUES ('owner');
|
||||
INSERT INTO \`custom_widget_definition\` (
|
||||
\`id\`, \`name\`, \`url\`, \`auth_type\`, \`method\`, \`display_type\`, \`display_config\`,
|
||||
\`enabled\`, \`created_at\`, \`updated_at\`, \`creator_id\`
|
||||
) VALUES (
|
||||
'legacy-weather', 'Weather', 'https://example.test/weather', 'bearer', 'GET', 'singleValue',
|
||||
'{"type":"singleValue","jsonPath":"$.temperature"}', true,
|
||||
'2023-11-14 00:00:00', '2023-11-14 00:00:01', 'owner'
|
||||
);
|
||||
INSERT INTO \`custom_widget_secret\` (\`kind\`, \`value\`, \`updated_at\`, \`definition_id\`)
|
||||
VALUES ('apiKey', 'encrypted.value', '2023-11-14 00:00:01', '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",
|
||||
);
|
||||
const [secrets] = await sql.query<mysql.RowDataPacket[]>(
|
||||
"SELECT definition_id, kind, value FROM legacy_custom_widget_secret",
|
||||
);
|
||||
expect(definitions).toEqual([
|
||||
expect.objectContaining({ id: "legacy-weather", name: "Weather", enabled: 1, creator_id: "owner" }),
|
||||
]);
|
||||
expect(secrets).toEqual([
|
||||
expect.objectContaining({ definition_id: "legacy-weather", kind: "apiKey", value: "encrypted.value" }),
|
||||
]);
|
||||
} finally {
|
||||
await sql.end();
|
||||
await mysqlContainer.stop();
|
||||
}
|
||||
}, 40_000);
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
import path from "path";
|
||||
import { readFileSync } from "node:fs";
|
||||
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 { describe, test } from "vitest";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
|
||||
|
||||
@@ -50,4 +51,82 @@ describe("PostgreSql Migration", () => {
|
||||
// Stop the container
|
||||
await postgreSqlContainer.stop();
|
||||
}, 40_000);
|
||||
|
||||
test("preserves populated v1 custom widgets and encrypted secrets", async () => {
|
||||
const postgreSqlContainer = await new PostgreSqlContainer("postgres:latest").start();
|
||||
const pool = new Pool({
|
||||
user: postgreSqlContainer.getUsername(),
|
||||
database: postgreSqlContainer.getDatabase(),
|
||||
password: postgreSqlContainer.getPassword(),
|
||||
port: postgreSqlContainer.getPort(),
|
||||
host: postgreSqlContainer.getHost(),
|
||||
});
|
||||
try {
|
||||
await pool.query(`
|
||||
CREATE TABLE "user" ("id" varchar(64) PRIMARY KEY NOT NULL);
|
||||
CREATE TABLE "custom_widget_definition" (
|
||||
"id" varchar(64) PRIMARY KEY NOT NULL,
|
||||
"name" varchar(256) NOT NULL,
|
||||
"description" text,
|
||||
"icon_url" text,
|
||||
"url" text NOT NULL,
|
||||
"auth_type" varchar(32) DEFAULT 'none' NOT NULL,
|
||||
"header_name" varchar(256),
|
||||
"method" varchar(16) DEFAULT 'GET' NOT NULL,
|
||||
"request_body" text,
|
||||
"display_type" varchar(32) DEFAULT 'singleValue' NOT NULL,
|
||||
"display_config" text NOT NULL,
|
||||
"enabled" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp NOT NULL,
|
||||
"updated_at" timestamp NOT NULL,
|
||||
"creator_id" varchar(64),
|
||||
CONSTRAINT "custom_widget_definition_creator_id_user_id_fk"
|
||||
FOREIGN KEY ("creator_id") REFERENCES "user"("id") ON DELETE SET NULL
|
||||
);
|
||||
CREATE TABLE "custom_widget_secret" (
|
||||
"kind" varchar(64) NOT NULL,
|
||||
"value" text NOT NULL,
|
||||
"updated_at" timestamp NOT NULL,
|
||||
"definition_id" varchar(64) NOT NULL,
|
||||
CONSTRAINT "custom_widget_secret_definition_id_kind_pk" PRIMARY KEY("definition_id", "kind"),
|
||||
CONSTRAINT "custom_widget_secret_definition_id_custom_widget_definition_id_fk"
|
||||
FOREIGN KEY ("definition_id") REFERENCES "custom_widget_definition"("id") ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO "user" ("id") VALUES ('owner');
|
||||
INSERT INTO "custom_widget_definition" (
|
||||
"id", "name", "url", "auth_type", "method", "display_type", "display_config", "enabled",
|
||||
"created_at", "updated_at", "creator_id"
|
||||
) VALUES (
|
||||
'legacy-weather', 'Weather', 'https://example.test/weather', 'bearer', 'GET', 'singleValue',
|
||||
'{"type":"singleValue","jsonPath":"$.temperature"}', true,
|
||||
'2023-11-14 00:00:00', '2023-11-14 00:00:01', 'owner'
|
||||
);
|
||||
INSERT INTO "custom_widget_secret" ("kind", "value", "updated_at", "definition_id")
|
||||
VALUES ('apiKey', 'encrypted.value', '2023-11-14 00:00:01', '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,
|
||||
).toEqual([
|
||||
expect.objectContaining({ id: "legacy-weather", name: "Weather", enabled: true, creator_id: "owner" }),
|
||||
]);
|
||||
expect((await pool.query("SELECT definition_id, kind, value FROM legacy_custom_widget_secret")).rows).toEqual([
|
||||
expect.objectContaining({ definition_id: "legacy-weather", kind: "apiKey", value: "encrypted.value" }),
|
||||
]);
|
||||
} finally {
|
||||
await pool.end();
|
||||
await postgreSqlContainer.stop();
|
||||
}
|
||||
}, 40_000);
|
||||
});
|
||||
@@ -1,8 +1,9 @@
|
||||
import path from "path";
|
||||
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 { test } from "vitest";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
|
||||
|
||||
@@ -22,3 +23,68 @@ test("SQLite migrations seed the five disabled bundled custom widgets", async ()
|
||||
|
||||
connection.close();
|
||||
});
|
||||
|
||||
test("Custom JSX v2 migration preserves populated v1 definitions and secrets", () => {
|
||||
const connection = new BetterSqlite3(":memory:");
|
||||
connection.exec(`
|
||||
CREATE TABLE user (id text PRIMARY KEY NOT NULL);
|
||||
CREATE TABLE custom_widget_definition (
|
||||
id text PRIMARY KEY NOT NULL,
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
icon_url text,
|
||||
url text NOT NULL,
|
||||
auth_type text DEFAULT 'none' NOT NULL,
|
||||
header_name text,
|
||||
method text DEFAULT 'GET' NOT NULL,
|
||||
request_body text,
|
||||
display_type text DEFAULT 'singleValue' NOT NULL,
|
||||
display_config text DEFAULT '{}' NOT NULL,
|
||||
enabled integer DEFAULT true NOT NULL,
|
||||
created_at integer NOT NULL,
|
||||
updated_at integer NOT NULL,
|
||||
creator_id text REFERENCES user(id) ON DELETE SET NULL
|
||||
);
|
||||
CREATE TABLE custom_widget_secret (
|
||||
kind text NOT NULL,
|
||||
value text NOT NULL,
|
||||
updated_at integer NOT NULL,
|
||||
definition_id text NOT NULL REFERENCES custom_widget_definition(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY(definition_id, kind)
|
||||
);
|
||||
INSERT INTO user (id) VALUES ('owner');
|
||||
INSERT INTO custom_widget_definition (
|
||||
id, name, url, auth_type, method, display_type, display_config, enabled, created_at, updated_at, creator_id
|
||||
) VALUES ('legacy-weather', 'Weather', 'https://example.test/weather', 'bearer', 'GET', 'singleValue',
|
||||
'{"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');
|
||||
`);
|
||||
|
||||
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({
|
||||
id: "legacy-weather",
|
||||
name: "Weather",
|
||||
enabled: 1,
|
||||
creator_id: "owner",
|
||||
});
|
||||
expect(connection.prepare("SELECT * FROM legacy_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 });
|
||||
|
||||
connection.close();
|
||||
});
|
||||
Reference in new issue
Block a user