Files
dahoam/drizzle/0006_dashboards_icons.sql
T
niklas e85244e820
images / check (push) Successful in 33s
images / image (push) Successful in 16s
feat: several dashboards with a default, icon search and icon upload
Dashboards are separate sets of cards (Home, Work). Settings manages them and
sets the one that opens at sign-in, the header and the search bar switch.
Migration 0006 puts the existing cards on a dashboard "Home".

The link dialog searches dashboard-icons and uploads custom icons (/api/icon,
up to 1 MB, SVG served sandboxed). Wallpaper and icons share the upload checks.
2026-11-18 17:53:27 +01:00

30 lines
2.0 KiB
SQL

CREATE TABLE "dashboard" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" text NOT NULL,
"name" text NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "icon" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"user_id" text NOT NULL,
"mime" text NOT NULL,
"data" "bytea" NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "card" ADD COLUMN "dashboard_id" uuid;--> statement-breakpoint
-- Hand-written: the cards a user already has become that user's first dashboard, "Home".
INSERT INTO "dashboard" ("user_id", "name")
SELECT DISTINCT "user_id", 'Home' FROM "card";--> statement-breakpoint
UPDATE "card" SET "dashboard_id" = "dashboard"."id" FROM "dashboard"
WHERE "dashboard"."user_id" = "card"."user_id";--> statement-breakpoint
ALTER TABLE "card" ALTER COLUMN "dashboard_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "settings" ADD COLUMN "default_dashboard_id" uuid;--> statement-breakpoint
ALTER TABLE "dashboard" ADD CONSTRAINT "dashboard_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "icon" ADD CONSTRAINT "icon_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "dashboard_user_id_idx" ON "dashboard" USING btree ("user_id");--> statement-breakpoint
CREATE INDEX "icon_user_id_idx" ON "icon" USING btree ("user_id");--> statement-breakpoint
ALTER TABLE "card" ADD CONSTRAINT "card_dashboard_id_dashboard_id_fk" FOREIGN KEY ("dashboard_id") REFERENCES "public"."dashboard"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "settings" ADD CONSTRAINT "settings_default_dashboard_id_dashboard_id_fk" FOREIGN KEY ("default_dashboard_id") REFERENCES "public"."dashboard"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "card_dashboard_id_idx" ON "card" USING btree ("dashboard_id");