139 lines
4.4 KiB
TypeScript
139 lines
4.4 KiB
TypeScript
import { pgTable, foreignKey, text, numeric, boolean, timestamp, unique, primaryKey } from "drizzle-orm/pg-core"
|
|
import { sql } from "drizzle-orm"
|
|
|
|
|
|
|
|
export const items = pgTable("items", {
|
|
id: text().primaryKey().notNull(),
|
|
wishlistId: text("wishlist_id").notNull(),
|
|
title: text().notNull(),
|
|
description: text(),
|
|
link: text(),
|
|
imageUrl: text("image_url"),
|
|
price: numeric({ precision: 10, scale: 2 }),
|
|
currency: text().default('DKK'),
|
|
color: text(),
|
|
order: numeric().default('0').notNull(),
|
|
isReserved: boolean("is_reserved").default(false).notNull(),
|
|
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
|
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.wishlistId],
|
|
foreignColumns: [wishlists.id],
|
|
name: "items_wishlist_id_wishlists_id_fk"
|
|
}).onDelete("cascade"),
|
|
]);
|
|
|
|
export const wishlists = pgTable("wishlists", {
|
|
id: text().primaryKey().notNull(),
|
|
userId: text("user_id"),
|
|
title: text().notNull(),
|
|
description: text(),
|
|
ownerToken: text("owner_token").notNull(),
|
|
publicToken: text("public_token").notNull(),
|
|
isFavorite: boolean("is_favorite").default(false).notNull(),
|
|
color: text(),
|
|
endDate: timestamp("end_date", { mode: 'string' }),
|
|
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
|
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
|
|
theme: text().default('none'),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [user.id],
|
|
name: "wishlists_user_id_user_id_fk"
|
|
}).onDelete("set null"),
|
|
unique("wishlists_owner_token_unique").on(table.ownerToken),
|
|
unique("wishlists_public_token_unique").on(table.publicToken),
|
|
]);
|
|
|
|
export const savedWishlists = pgTable("saved_wishlists", {
|
|
id: text().primaryKey().notNull(),
|
|
userId: text("user_id").notNull(),
|
|
wishlistId: text("wishlist_id").notNull(),
|
|
isFavorite: boolean("is_favorite").default(false).notNull(),
|
|
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
|
ownerToken: text("owner_token"),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [user.id],
|
|
name: "saved_wishlists_user_id_user_id_fk"
|
|
}).onDelete("cascade"),
|
|
foreignKey({
|
|
columns: [table.wishlistId],
|
|
foreignColumns: [wishlists.id],
|
|
name: "saved_wishlists_wishlist_id_wishlists_id_fk"
|
|
}).onDelete("cascade"),
|
|
]);
|
|
|
|
export const user = pgTable("user", {
|
|
id: text().primaryKey().notNull(),
|
|
name: text(),
|
|
email: text(),
|
|
emailVerified: timestamp({ mode: 'string' }),
|
|
image: text(),
|
|
password: text(),
|
|
username: text(),
|
|
dashboardTheme: text("dashboard_theme").default('none'),
|
|
dashboardColor: text("dashboard_color"),
|
|
}, (table) => [
|
|
unique("user_email_unique").on(table.email),
|
|
unique("user_username_unique").on(table.username),
|
|
]);
|
|
|
|
export const reservations = pgTable("reservations", {
|
|
id: text().primaryKey().notNull(),
|
|
itemId: text("item_id").notNull(),
|
|
reserverName: text("reserver_name"),
|
|
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.itemId],
|
|
foreignColumns: [items.id],
|
|
name: "reservations_item_id_items_id_fk"
|
|
}).onDelete("cascade"),
|
|
]);
|
|
|
|
export const session = pgTable("session", {
|
|
sessionToken: text().primaryKey().notNull(),
|
|
userId: text().notNull(),
|
|
expires: timestamp({ mode: 'string' }).notNull(),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [user.id],
|
|
name: "session_userId_user_id_fk"
|
|
}).onDelete("cascade"),
|
|
]);
|
|
|
|
export const verificationToken = pgTable("verificationToken", {
|
|
identifier: text().notNull(),
|
|
token: text().notNull(),
|
|
expires: timestamp({ mode: 'string' }).notNull(),
|
|
}, (table) => [
|
|
primaryKey({ columns: [table.identifier, table.token], name: "verificationToken_identifier_token_pk"}),
|
|
]);
|
|
|
|
export const account = pgTable("account", {
|
|
userId: text().notNull(),
|
|
type: text().notNull(),
|
|
provider: text().notNull(),
|
|
providerAccountId: text().notNull(),
|
|
refreshToken: text("refresh_token"),
|
|
accessToken: text("access_token"),
|
|
expiresAt: numeric("expires_at"),
|
|
tokenType: text("token_type"),
|
|
scope: text(),
|
|
idToken: text("id_token"),
|
|
sessionState: text("session_state"),
|
|
}, (table) => [
|
|
foreignKey({
|
|
columns: [table.userId],
|
|
foreignColumns: [user.id],
|
|
name: "account_userId_user_id_fk"
|
|
}).onDelete("cascade"),
|
|
primaryKey({ columns: [table.provider, table.providerAccountId], name: "account_provider_providerAccountId_pk"}),
|
|
]);
|