Files
dahoam/drizzle/0007_dashboard_wallpaper.sql
niklas dacd374946
images / check (push) Successful in 32s
images / image (push) Successful in 15s
feat: every dashboard has its own wallpaper
The wallpaper and how much it is darkened move from the user to the dashboard.
Migration 0007 copies what each user had to all their dashboards.

Settings open for the dashboard you came from (/settings?d=<id>): its wallpaper
is shown, a switch reaches the others, and "Back to dashboard" returns to it.
2026-11-18 18:03:10 +01:00

27 lines
2.0 KiB
SQL

-- Hand-written: the wallpaper moves from the user to the dashboard. Every dashboard of a
-- user starts with the wallpaper that the user had, so nothing looks different.
ALTER TABLE "dashboard" ADD COLUMN "wallpaper_url" text;--> statement-breakpoint
ALTER TABLE "dashboard" ADD COLUMN "wallpaper_dim" integer DEFAULT 40 NOT NULL;--> statement-breakpoint
-- a user who chose a wallpaper but has no dashboard yet keeps it too
INSERT INTO "dashboard" ("user_id", "name")
SELECT "user_id", 'Home' FROM "settings"
WHERE NOT EXISTS (SELECT 1 FROM "dashboard" WHERE "dashboard"."user_id" = "settings"."user_id");--> statement-breakpoint
-- the address of an upload now names its dashboard: /api/wallpaper?d=<id>&v=<upload time>
UPDATE "dashboard" SET
"wallpaper_dim" = "settings"."wallpaper_dim",
"wallpaper_url" = CASE WHEN "settings"."wallpaper_url" LIKE '/api/wallpaper?v=%'
THEN replace("settings"."wallpaper_url", '?v=', '?d=' || "dashboard"."id" || '&v=')
ELSE "settings"."wallpaper_url" END
FROM "settings" WHERE "settings"."user_id" = "dashboard"."user_id";--> statement-breakpoint
ALTER TABLE "wallpaper" DROP CONSTRAINT "wallpaper_pkey";--> statement-breakpoint
ALTER TABLE "wallpaper" ADD COLUMN "dashboard_id" uuid;--> statement-breakpoint
-- one upload per user becomes one copy per dashboard of that user
INSERT INTO "wallpaper" ("dashboard_id", "user_id", "mime", "data")
SELECT "dashboard"."id", "wallpaper"."user_id", "wallpaper"."mime", "wallpaper"."data"
FROM "wallpaper" JOIN "dashboard" ON "dashboard"."user_id" = "wallpaper"."user_id";--> statement-breakpoint
DELETE FROM "wallpaper" WHERE "dashboard_id" IS NULL;--> statement-breakpoint
ALTER TABLE "wallpaper" ADD PRIMARY KEY ("dashboard_id");--> statement-breakpoint
ALTER TABLE "wallpaper" ADD CONSTRAINT "wallpaper_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" DROP COLUMN "wallpaper_url";--> statement-breakpoint
ALTER TABLE "settings" DROP COLUMN "wallpaper_dim";