feat(db): introduce item_claims for quantity-aware claims; supersede inline claim columns
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { sqliteTable, text, integer, real } from 'drizzle-orm/sqlite-core';
|
||||
import { sqliteTable, text, integer, real, unique } from 'drizzle-orm/sqlite-core';
|
||||
import { createId } from '@paralleldrive/cuid2';
|
||||
import { sql } from 'drizzle-orm';
|
||||
|
||||
@@ -36,17 +36,29 @@ export const wishlistItems = sqliteTable('wishlist_items', {
|
||||
url: string;
|
||||
}>>(),
|
||||
isArchived: integer('is_archived', { mode: 'boolean' }).notNull().default(false),
|
||||
|
||||
claimedByGuestId: text('claimed_by_guest_id').references(() => guests.id, { onDelete: 'set null' }),
|
||||
claimedByNote: text('claimed_by_note'),
|
||||
claimedAt: integer('claimed_at', { mode: 'timestamp' }),
|
||||
isPurchased: integer('is_purchased', { mode: 'boolean' }).notNull().default(false),
|
||||
|
||||
// claim ownership lives in item_claims (1 item -> many claims; unique per (item, guest))
|
||||
sortOrder: integer('sort_order').notNull().default(0),
|
||||
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),
|
||||
});
|
||||
|
||||
export const itemClaims = sqliteTable(
|
||||
'item_claims',
|
||||
{
|
||||
id: text('id').primaryKey().$defaultFn(() => createId()),
|
||||
itemId: text('item_id').notNull().references(() => wishlistItems.id, { onDelete: 'cascade' }),
|
||||
guestId: text('guest_id').notNull().references(() => guests.id, { onDelete: 'cascade' }),
|
||||
quantity: integer('quantity').notNull().default(1),
|
||||
note: text('note'),
|
||||
isPurchased: integer('is_purchased', { mode: 'boolean' }).notNull().default(false),
|
||||
claimedAt: integer('claimed_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),
|
||||
updatedAt: integer('updated_at', { mode: 'timestamp' }).notNull().default(sql`(unixepoch())`),
|
||||
},
|
||||
(t) => ({
|
||||
uniqueItemGuest: unique('item_claims_item_guest_unique').on(t.itemId, t.guestId),
|
||||
})
|
||||
);
|
||||
|
||||
export const settings = sqliteTable('settings', {
|
||||
id: text('id').primaryKey().$defaultFn(() => createId()),
|
||||
key: text('key').notNull().unique(),
|
||||
@@ -57,4 +69,5 @@ export const settings = sqliteTable('settings', {
|
||||
export type Wishlist = typeof wishlists.$inferSelect;
|
||||
export type WishlistItem = typeof wishlistItems.$inferSelect;
|
||||
export type Guest = typeof guests.$inferSelect;
|
||||
export type ItemClaim = typeof itemClaims.$inferSelect;
|
||||
export type Setting = typeof settings.$inferSelect;
|
||||
|
||||
Reference in New Issue
Block a user