Updating schema for drizzle, adding migrate and push.

This commit is contained in:
Bradley Shellnut 2024-02-03 18:21:32 -08:00
parent 3494876abb
commit 30cd8ceb97
9 changed files with 1777 additions and 228 deletions

View file

@ -6,6 +6,6 @@ export default defineConfig({
out: './drizzle',
driver: 'mysql2',
dbCredentials: {
connectionString: process.env.DATABASE_URL
uri: `${process.env.DATABASE_URL}`
}
});

View file

@ -0,0 +1,169 @@
CREATE TABLE `artists` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`external_id` int,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `artists_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `categories` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`external_id` int,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `categories_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `collection_items` (
`id` varchar(255) NOT NULL,
`collection_id` varchar(255) NOT NULL,
`game_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `collection_items_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `collections` (
`id` varchar(255) NOT NULL,
`user_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `collections_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `designers` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`external_id` int,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `designers_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `expansions` (
`id` varchar(255) NOT NULL,
`base_game_id` varchar(255) NOT NULL,
`game_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `expansions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `games` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`description` text,
`year_published` year,
`min_players` int,
`max_players` int,
`playtime` int,
`min_playtime` int,
`max_playtime` int,
`min_age` int,
`image_url` varchar(255),
`thumb_url` varchar(255),
`url` varchar(255),
`external_id` int,
`last_sync_at` datetime,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `games_id` PRIMARY KEY(`id`),
CONSTRAINT `games_external_id_unique` UNIQUE(`external_id`)
);
--> statement-breakpoint
CREATE TABLE `mechanics` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`external_id` int,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `mechanics_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `publishers` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
`slug` varchar(255),
`external_id` int,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `publishers_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `roles` (
`id` varchar(255) NOT NULL,
`name` varchar(255),
CONSTRAINT `roles_id` PRIMARY KEY(`id`),
CONSTRAINT `roles_name_unique` UNIQUE(`name`)
);
--> statement-breakpoint
CREATE TABLE `sessions` (
`id` varchar(255) NOT NULL,
`user_id` varchar(255) NOT NULL,
`ip_country` varchar(255),
`ip_address` varchar(255),
`expires_at` datetime NOT NULL,
CONSTRAINT `sessions_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `user_roles` (
`id` varchar(255) NOT NULL,
`user_id` varchar(255) NOT NULL,
`role_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `user_roles_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` varchar(255) NOT NULL,
`username` varchar(255),
`hashed_password` varchar(255),
`email` varchar(255),
`first_name` varchar(255),
`last_name` varchar(255),
`verified` boolean DEFAULT false,
`receive_email` boolean DEFAULT false,
`theme` varchar(255) DEFAULT 'system',
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `users_id` PRIMARY KEY(`id`),
CONSTRAINT `users_username_unique` UNIQUE(`username`),
CONSTRAINT `users_email_unique` UNIQUE(`email`)
);
--> statement-breakpoint
CREATE TABLE `wishlist_items` (
`id` varchar(255) NOT NULL,
`wishlist_id` varchar(255) NOT NULL,
`game_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `wishlist_items_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
CREATE TABLE `wishlists` (
`id` varchar(255) NOT NULL,
`user_id` varchar(255) NOT NULL,
`created_at` datetime DEFAULT (now(6)),
`updated_at` datetime DEFAULT (now(6)),
CONSTRAINT `wishlists_id` PRIMARY KEY(`id`)
);
--> statement-breakpoint
ALTER TABLE `collection_items` ADD CONSTRAINT `collection_items_collection_id_collections_id_fk` FOREIGN KEY (`collection_id`) REFERENCES `collections`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `collection_items` ADD CONSTRAINT `collection_items_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `collections` ADD CONSTRAINT `collections_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `expansions` ADD CONSTRAINT `expansions_base_game_id_games_id_fk` FOREIGN KEY (`base_game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `expansions` ADD CONSTRAINT `expansions_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `sessions` ADD CONSTRAINT `sessions_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `user_roles` ADD CONSTRAINT `user_roles_role_id_roles_id_fk` FOREIGN KEY (`role_id`) REFERENCES `roles`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `wishlist_items` ADD CONSTRAINT `wishlist_items_wishlist_id_wishlists_id_fk` FOREIGN KEY (`wishlist_id`) REFERENCES `wishlists`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `wishlist_items` ADD CONSTRAINT `wishlist_items_game_id_games_id_fk` FOREIGN KEY (`game_id`) REFERENCES `games`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `wishlists` ADD CONSTRAINT `wishlists_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE cascade ON UPDATE no action;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1707012854588,
"tag": "0000_smooth_thunderbolt",
"breakpoints": true
}
]
}

View file

@ -16,11 +16,9 @@
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"site:update": "pnpm update -i -L",
"db:studio": "prisma studio",
"db:push": "prisma db push",
"db:generate": "prisma generate",
"db:seed": "prisma db seed",
"i-changed-the-schema": "pnpm run db:push && pnpm run db:generate"
"generate": "drizzle-kit generate:mysql",
"migrate": "tsx ./src/migrate.ts",
"db:push": "drizzle-kit push:mysql"
},
"prisma": {
"seed": "node --loader ts-node/esm prisma/seed.ts"
@ -39,6 +37,7 @@
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"autoprefixer": "^10.4.17",
"dotenv": "^16.4.1",
"drizzle-kit": "^0.20.13",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",

View file

@ -160,6 +160,9 @@ devDependencies:
autoprefixer:
specifier: ^10.4.17
version: 10.4.17(postcss@8.4.33)
dotenv:
specifier: ^16.4.1
version: 16.4.1
drizzle-kit:
specifier: ^0.20.13
version: 0.20.13
@ -3863,6 +3866,11 @@ packages:
esutils: 2.0.3
dev: true
/dotenv@16.4.1:
resolution: {integrity: sha512-CjA3y+Dr3FyFDOAMnxZEGtnW9KBR2M0JvvUtXNW+dYJL5ROWxP9DUHCwgFqpMk0OXCc0ljhaNTr2w/kutYIcHQ==}
engines: {node: '>=12'}
dev: true
/dreamopt@0.8.0:
resolution: {integrity: sha512-vyJTp8+mC+G+5dfgsY+r3ckxlz+QMX40VjPQsZc5gxVAxLmi64TBoVkP54A/pRAXMXsbu2GMMBrZPxNv23waMg==}
engines: {node: '>=0.4.0'}

View file

@ -3,9 +3,9 @@ import { Lucia, TimeSpan } from 'lucia';
import { DrizzleMySQLAdapter } from "@lucia-auth/adapter-drizzle";
import { dev } from '$app/environment';
import db from '$lib/drizzle';
import { sessionTable, userTable } from '../../schema';
import { sessions, users } from '../../schema';
const adapter = new DrizzleMySQLAdapter(db, sessionTable, userTable);
const adapter = new DrizzleMySQLAdapter(db, sessions, users);
export const lucia = new Lucia(adapter, {
getSessionAttributes: (attributes) => {

12
src/migrate.ts Normal file
View file

@ -0,0 +1,12 @@
import { drizzle } from "drizzle-orm/mysql2";
import { migrate } from "drizzle-orm/mysql2/migrator";
import { createConnection } from "mysql2";
const connection = createConnection({
uri: process.env.DATABASE_URL
})
const db = drizzle(connection);
await migrate(db, { migrationsFolder: "drizzle" });
await connection.end();

View file

@ -1,29 +1,29 @@
import { sql } from 'drizzle-orm';
import { mysqlTable, datetime, varchar, boolean, timestamp } from 'drizzle-orm/mysql-core';
import { mysqlTable, datetime, varchar, boolean, timestamp, year, int, text } from 'drizzle-orm/mysql-core';
import { nanoid } from 'nanoid';
model User {
id String @id @default(cuid())
username String @unique
hashed_password String?
email String? @unique
firstName String?
lastName String?
roles UserRole[]
verified Boolean @default(false)
receiveEmail Boolean @default(false)
collection Collection?
wishlist Wishlist?
list List[]
theme String @default("system")
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
sessions Session[]
// model User {
// id String @id @default(cuid())
// username String @unique
// hashed_password String?
// email String? @unique
// firstName String?
// lastName String?
// roles UserRole[]
// verified Boolean @default(false)
// receiveEmail Boolean @default(false)
// collection Collection?
// wishlist Wishlist?
// list List[]
// theme String @default("system")
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// sessions Session[]
@@map("users")
}
// @@map("users")
// }
export const userTable = mysqlTable("users", {
export const users = mysqlTable("users", {
id: varchar("id", {
length: 255
}).primaryKey()
@ -48,10 +48,12 @@ export const userTable = mysqlTable("users", {
theme: varchar("theme", {
length: 255
}).default("system"),
createdAt: timestamp("created_at").default(sql`(now(6))`),
updatedAt: timestamp("updated_at").default(sql`(now(6))`)
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
});
// model Session {
// id String @id @unique
// userId String
@ -64,7 +66,7 @@ export const userTable = mysqlTable("users", {
// @@map("sessions")
// }
export const sessionTable = mysqlTable("sessions", {
export const sessions = mysqlTable("sessions", {
id: varchar("id", {
length: 255
}).primaryKey()
@ -73,7 +75,7 @@ export const sessionTable = mysqlTable("sessions", {
length: 255
})
.notNull()
.references(() => userTable.id),
.references(() => users.id, { onDelete: 'cascade' }),
ipCountry: varchar("ip_country", {
length: 255
}),
@ -83,229 +85,457 @@ export const sessionTable = mysqlTable("sessions", {
expiresAt: datetime("expires_at").notNull()
});
model Role {
id String @id @default(cuid())
name String @unique
userRoles UserRole[]
// model Role {
// id String @id @default(cuid())
// name String @unique
// userRoles UserRole[]
@@map("roles")
}
// @@map("roles")
// }
model UserRole {
id String @id @default(cuid())
user User @relation(fields: [user_id], references: [id])
user_id String
role Role @relation(fields: [role_id], references: [id])
role_id String
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
export const roles = mysqlTable("roles", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}).unique()
});
@@unique([user_id, role_id])
@@index([user_id])
@@index([role_id])
@@map("user_roles")
}
// model UserRole {
// id String @id @default(cuid())
// user User @relation(fields: [user_id], references: [id])
// user_id String
// role Role @relation(fields: [role_id], references: [id])
// role_id String
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
model Collection {
id String @id @default(cuid())
user_id String @unique
user User @relation(references: [id], fields: [user_id])
items CollectionItem[]
// @@unique([user_id, role_id])
// @@index([user_id])
// @@index([role_id])
// @@map("user_roles")
// }
@@index([user_id])
@@map("collections")
}
export const userRoles = mysqlTable("user_roles", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
userId: varchar("user_id", {
length: 255
})
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
roleId: varchar("role_id", {
length: 255
})
.notNull()
.references(() => roles.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
});
model CollectionItem {
id String @id @default(cuid())
collection_id String
collection Collection @relation(references: [id], fields: [collection_id], onDelete: Cascade)
game_id String @unique
game Game @relation(references: [id], fields: [game_id])
times_played Int
// model Game {
// id String @id @default(cuid())
// name String
// slug String
// description String? @db.LongText
// year_published Int? @db.Year
// min_players Int?
// max_players Int?
// playtime Int?
// min_playtime Int?
// max_playtime Int?
// min_age Int?
// image_url String?
// thumb_url String?
// url String?
// rules_url String?
// categories Category[]
// mechanics Mechanic[]
// designers Designer[]
// publishers Publisher[]
// artists Artist[]
// names GameName[]
// expansions Expansion[] @relation("BaseToExpansion")
// expansion_of Expansion[] @relation("ExpansionToBase")
// collection_items CollectionItem[]
// wishlist_items WishlistItem[]
// list_items ListItem[]
// external_id Int @unique
// last_sync_at DateTime? @db.Timestamp(6)
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
@@index([game_id, collection_id])
@@index([game_id])
@@index([collection_id])
@@map("collection_items")
}
// @@fulltext([name])
// @@fulltext([slug])
// @@map("games")
// }
model Wishlist {
id String @id @default(cuid())
user_id String @unique
user User @relation(references: [id], fields: [user_id])
items WishlistItem[]
export const games = mysqlTable("games", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
description: text("description"),
yearPublished: year("year_published"),
minPlayers: int("min_players"),
maxPlayers: int("max_players"),
playtime: int("playtime"),
minPlaytime: int("min_playtime"),
maxPlaytime: int("max_playtime"),
minAge: int("min_age"),
imageUrl: varchar("image_url", {
length: 255
}),
thumbUrl: varchar("thumb_url", {
length: 255
}),
url: varchar("url", {
length: 255
}),
externalId: int("external_id").unique(),
lastSyncAt: datetime("last_sync_at"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
@@index([user_id])
@@map("wishlists")
}
// model Expansion {
// id String @id @default(cuid())
// base_game Game @relation(name: "BaseToExpansion", fields: [base_game_id], references: [id])
// base_game_id String
// game Game @relation(name: "ExpansionToBase", fields: [game_id], references: [id])
// game_id String
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
model WishlistItem {
id String @id @default(cuid())
wishlist_id String
wishlist Wishlist @relation(references: [id], fields: [wishlist_id], onDelete: Cascade)
game_id String @unique
game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([base_game_id])
// @@index([game_id])
// @@map("expansions")
// }
@@index([game_id, wishlist_id])
@@index([game_id])
@@index([wishlist_id])
@@map("wishlist_items")
}
export const expansions = mysqlTable("expansions", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
baseGameId: varchar("base_game_id", {
length: 255
})
.notNull()
.references(() => games.id, { onDelete: 'cascade' }),
gameId: varchar("game_id", {
length: 255
})
.notNull()
.references(() => games.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
model List {
id String @id @default(cuid())
name String
user_id String @unique
user User @relation(references: [id], fields: [user_id])
items ListItem[]
// model Collection {
// id String @id @default(cuid())
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items CollectionItem[]
@@index([user_id])
@@map("lists")
}
// @@index([user_id])
// @@map("collections")
// }
model ListItem {
id String @id @default(cuid())
list_id String
list List @relation(references: [id], fields: [list_id], onDelete: Cascade)
game_id String @unique
game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
export const collections = mysqlTable("collections", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
userId: varchar("user_id", {
length: 255
})
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
@@index([game_id, list_id])
@@index([game_id])
@@index([list_id])
@@map("list_items")
}
// model CollectionItem {
// id String @id @default(cuid())
// collection_id String
// collection Collection @relation(references: [id], fields: [collection_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// times_played Int
model Game {
id String @id @default(cuid())
name String
slug String
description String? @db.LongText
year_published Int? @db.Year
min_players Int?
max_players Int?
playtime Int?
min_playtime Int?
max_playtime Int?
min_age Int?
image_url String?
thumb_url String?
url String?
rules_url String?
categories Category[]
mechanics Mechanic[]
designers Designer[]
publishers Publisher[]
artists Artist[]
names GameName[]
expansions Expansion[] @relation("BaseToExpansion")
expansion_of Expansion[] @relation("ExpansionToBase")
collection_items CollectionItem[]
wishlist_items WishlistItem[]
list_items ListItem[]
external_id Int @unique
last_sync_at DateTime? @db.Timestamp(6)
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([game_id, collection_id])
// @@index([game_id])
// @@index([collection_id])
// @@map("collection_items")
// }
@@fulltext([name])
@@fulltext([slug])
@@map("games")
}
export const collectionItems = mysqlTable("collection_items", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
collectionId: varchar("collection_id", {
length: 255
})
.notNull()
.references(() => collections.id, { onDelete: 'cascade' }),
gameId: varchar("game_id", {
length: 255
})
.notNull()
.references(() => games.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
model GameName {
id String @id @default(cuid())
name String
slug String
game_id String
game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// model Wishlist {
// id String @id @default(cuid())
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items WishlistItem[]
@@index([game_id])
@@map("game_names")
}
// @@index([user_id])
// @@map("wishlists")
// }
model Publisher {
id String @id @default(cuid())
name String
slug String
external_id Int @unique
games Game[]
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
export const wishlists = mysqlTable("wishlists", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
userId: varchar("user_id", {
length: 255
})
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
});
@@fulltext([name])
@@map("publishers")
}
// model WishlistItem {
// id String @id @default(cuid())
// wishlist_id String
// wishlist Wishlist @relation(references: [id], fields: [wishlist_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
model Category {
id String @id @default(cuid())
name String
slug String
games Game[]
external_id Int @unique
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// @@index([game_id, wishlist_id])
// @@index([game_id])
// @@index([wishlist_id])
// @@map("wishlist_items")
// }
@@fulltext([name])
@@map("categories")
}
export const wishlistItems = mysqlTable("wishlist_items", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
wishlistId: varchar("wishlist_id", {
length: 255
})
.notNull()
.references(() => wishlists.id, { onDelete: 'cascade' }),
gameId: varchar("game_id", {
length: 255
})
.notNull()
.references(() => games.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
});
model Mechanic {
id String @id @default(cuid())
name String
slug String
games Game[]
external_id Int @unique
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// model List {
// id String @id @default(cuid())
// name String
// user_id String @unique
// user User @relation(references: [id], fields: [user_id])
// items ListItem[]
@@fulltext([name])
@@map("mechanics")
}
// @@index([user_id])
// @@map("lists")
// }
model Designer {
id String @id @default(cuid())
name String
slug String
external_id Int @unique
games Game[]
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// model ListItem {
// id String @id @default(cuid())
// list_id String
// list List @relation(references: [id], fields: [list_id], onDelete: Cascade)
// game_id String @unique
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name])
@@map("designers")
}
// @@index([game_id, list_id])
// @@index([game_id])
// @@index([list_id])
// @@map("list_items")
// }
model Artist {
id String @id @default(cuid())
name String
slug String @unique
external_id Int @unique
games Game[]
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// model GameName {
// id String @id @default(cuid())
// name String
// slug String
// game_id String
// game Game @relation(references: [id], fields: [game_id])
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name])
@@map("artists")
}
// @@index([game_id])
// @@map("game_names")
// }
model Expansion {
id String @id @default(cuid())
base_game Game @relation(name: "BaseToExpansion", fields: [base_game_id], references: [id])
base_game_id String
game Game @relation(name: "ExpansionToBase", fields: [game_id], references: [id])
game_id String
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
// model Publisher {
// id String @id @default(cuid())
// name String
// slug String
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
@@index([base_game_id])
@@index([game_id])
@@map("expansions")
}
// @@fulltext([name])
// @@map("publishers")
// }
export const publishers = mysqlTable("publishers", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
externalId: int("external_id"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
// model Category {
// id String @id @default(cuid())
// name String
// slug String
// games Game[]
// external_id Int @unique
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("categories")
// }
export const categories = mysqlTable("categories", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
externalId: int("external_id"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
// model Mechanic {
// id String @id @default(cuid())
// name String
// slug String
// games Game[]
// external_id Int @unique
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("mechanics")
// }
export const mechanics = mysqlTable("mechanics", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
externalId: int("external_id"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
// model Designer {
// id String @id @default(cuid())
// name String
// slug String
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("designers")
// }
export const designers = mysqlTable("designers", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
externalId: int("external_id"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})
// model Artist {
// id String @id @default(cuid())
// name String
// slug String @unique
// external_id Int @unique
// games Game[]
// created_at DateTime @default(now()) @db.Timestamp(6)
// updated_at DateTime @updatedAt @db.Timestamp(6)
// @@fulltext([name])
// @@map("artists")
// }
export const artists = mysqlTable("artists", {
id: varchar("id", {
length: 255
}).primaryKey()
.$defaultFn(() => nanoid()),
name: varchar("name", {
length: 255
}),
slug: varchar("slug", {
length: 255
}),
externalId: int("external_id"),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
})