feat(25-01): add attribution columns and unique constraint to globalItems

- Add sourceUrl, imageCredit, imageSourceUrl nullable columns
- Add unique constraint on (brand, model) pair
- Generate migration 0003_loving_serpent_society.sql
This commit is contained in:
2026-04-10 10:55:55 +02:00
parent b6970c9a04
commit 39ef9cc433
3 changed files with 41 additions and 11 deletions

View File

@@ -0,0 +1,16 @@
CREATE TABLE "global_item_tags" (
"global_item_id" integer NOT NULL,
"tag_id" integer NOT NULL,
CONSTRAINT "global_item_tags_global_item_id_tag_id_pk" PRIMARY KEY("global_item_id","tag_id")
);
--> statement-breakpoint
ALTER TABLE "global_items" ADD COLUMN "source_url" text;--> statement-breakpoint
ALTER TABLE "global_items" ADD COLUMN "image_credit" text;--> statement-breakpoint
ALTER TABLE "global_items" ADD COLUMN "image_source_url" text;--> statement-breakpoint
ALTER TABLE "oauth_codes" ADD COLUMN "user_id" integer NOT NULL;--> statement-breakpoint
ALTER TABLE "global_item_tags" ADD CONSTRAINT "global_item_tags_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "global_item_tags" ADD CONSTRAINT "global_item_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "items" ADD CONSTRAINT "items_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "oauth_codes" ADD CONSTRAINT "oauth_codes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "thread_candidates" ADD CONSTRAINT "thread_candidates_global_item_id_global_items_id_fk" FOREIGN KEY ("global_item_id") REFERENCES "public"."global_items"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "global_items" ADD CONSTRAINT "global_items_brand_model_unique" UNIQUE("brand","model");

View File

@@ -22,6 +22,13 @@
"when": 1775413526643, "when": 1775413526643,
"tag": "0002_wakeful_vermin", "tag": "0002_wakeful_vermin",
"breakpoints": true "breakpoints": true
},
{
"idx": 3,
"version": "7",
"when": 1775811339957,
"tag": "0003_loving_serpent_society",
"breakpoints": true
} }
] ]
} }

View File

@@ -133,7 +133,9 @@ export const setupItems = pgTable("setup_items", {
// ── Global Items ──────────────────────────────────────────────────── // ── Global Items ────────────────────────────────────────────────────
export const globalItems = pgTable("global_items", { export const globalItems = pgTable(
"global_items",
{
id: serial("id").primaryKey(), id: serial("id").primaryKey(),
brand: text("brand").notNull(), brand: text("brand").notNull(),
model: text("model").notNull(), model: text("model").notNull(),
@@ -142,8 +144,13 @@ export const globalItems = pgTable("global_items", {
priceCents: integer("price_cents"), priceCents: integer("price_cents"),
imageUrl: text("image_url"), imageUrl: text("image_url"),
description: text("description"), description: text("description"),
sourceUrl: text("source_url"),
imageCredit: text("image_credit"),
imageSourceUrl: text("image_source_url"),
createdAt: timestamp("created_at").defaultNow().notNull(), createdAt: timestamp("created_at").defaultNow().notNull(),
}); },
(table) => [unique().on(table.brand, table.model)],
);
// ── Tags ─────────────────────────────────────────────────────────── // ── Tags ───────────────────────────────────────────────────────────