feat(19-01): update schema with reference item model and tags tables

- Add globalItemId and purchasePriceCents columns to items table
- Add globalItemId column to threadCandidates table
- Add tags and globalItemTags tables for tag system
- Remove itemGlobalLinks table (replaced by direct FK)
- Generate migration with data migration step before table drop
This commit is contained in:
2026-04-05 20:25:59 +02:00
parent e59e724d84
commit 5df513c138
4 changed files with 1227 additions and 9 deletions

View File

@@ -55,6 +55,8 @@ export const items = pgTable("items", {
imageFilename: text("image_filename"),
imageSourceUrl: text("image_source_url"),
quantity: integer("quantity").notNull().default(1),
globalItemId: integer("global_item_id").references(() => globalItems.id),
purchasePriceCents: integer("purchase_price_cents"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
@@ -97,6 +99,7 @@ export const threadCandidates = pgTable("thread_candidates", {
pros: text("pros"),
cons: text("cons"),
sortOrder: doublePrecision("sort_order").notNull().default(0),
globalItemId: integer("global_item_id").references(() => globalItems.id),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});
@@ -141,19 +144,29 @@ export const globalItems = pgTable("global_items", {
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// ── Item Global Links ───────────────────────────────────────────────
// ── Tags ───────────────────────────────────────────────────────────
export const itemGlobalLinks = pgTable("item_global_links", {
export const tags = pgTable("tags", {
id: serial("id").primaryKey(),
itemId: integer("item_id")
.notNull()
.references(() => items.id, { onDelete: "cascade" })
.unique(),
globalItemId: integer("global_item_id")
.notNull()
.references(() => globalItems.id, { onDelete: "cascade" }),
name: text("name").notNull().unique(),
createdAt: timestamp("created_at").defaultNow().notNull(),
});
// ── Global Item Tags ───────────────────────────────────────────────
export const globalItemTags = pgTable(
"global_item_tags",
{
globalItemId: integer("global_item_id")
.notNull()
.references(() => globalItems.id, { onDelete: "cascade" }),
tagId: integer("tag_id")
.notNull()
.references(() => tags.id, { onDelete: "cascade" }),
},
(table) => [primaryKey({ columns: [table.globalItemId, table.tagId] })],
);
// ── Settings ────────────────────────────────────────────────────────
export const settings = pgTable(