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

View file

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

View file

@ -3,9 +3,9 @@ import { Lucia, TimeSpan } from 'lucia';
import { DrizzleMySQLAdapter } from "@lucia-auth/adapter-drizzle"; import { DrizzleMySQLAdapter } from "@lucia-auth/adapter-drizzle";
import { dev } from '$app/environment'; import { dev } from '$app/environment';
import db from '$lib/drizzle'; 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, { export const lucia = new Lucia(adapter, {
getSessionAttributes: (attributes) => { 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 { 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'; import { nanoid } from 'nanoid';
model User { // model User {
id String @id @default(cuid()) // id String @id @default(cuid())
username String @unique // username String @unique
hashed_password String? // hashed_password String?
email String? @unique // email String? @unique
firstName String? // firstName String?
lastName String? // lastName String?
roles UserRole[] // roles UserRole[]
verified Boolean @default(false) // verified Boolean @default(false)
receiveEmail Boolean @default(false) // receiveEmail Boolean @default(false)
collection Collection? // collection Collection?
wishlist Wishlist? // wishlist Wishlist?
list List[] // list List[]
theme String @default("system") // theme String @default("system")
created_at DateTime @default(now()) @db.Timestamp(6) // created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6) // updated_at DateTime @updatedAt @db.Timestamp(6)
sessions Session[] // sessions Session[]
@@map("users") // @@map("users")
} // }
export const userTable = mysqlTable("users", { export const users = mysqlTable("users", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
}).primaryKey() }).primaryKey()
@ -48,10 +48,12 @@ export const userTable = mysqlTable("users", {
theme: varchar("theme", { theme: varchar("theme", {
length: 255 length: 255
}).default("system"), }).default("system"),
createdAt: timestamp("created_at").default(sql`(now(6))`), createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: timestamp("updated_at").default(sql`(now(6))`) updatedAt: datetime("updated_at").default(sql`(now(6))`)
}); });
// model Session { // model Session {
// id String @id @unique // id String @id @unique
// userId String // userId String
@ -64,7 +66,7 @@ export const userTable = mysqlTable("users", {
// @@map("sessions") // @@map("sessions")
// } // }
export const sessionTable = mysqlTable("sessions", { export const sessions = mysqlTable("sessions", {
id: varchar("id", { id: varchar("id", {
length: 255 length: 255
}).primaryKey() }).primaryKey()
@ -73,7 +75,7 @@ export const sessionTable = mysqlTable("sessions", {
length: 255 length: 255
}) })
.notNull() .notNull()
.references(() => userTable.id), .references(() => users.id, { onDelete: 'cascade' }),
ipCountry: varchar("ip_country", { ipCountry: varchar("ip_country", {
length: 255 length: 255
}), }),
@ -83,229 +85,457 @@ export const sessionTable = mysqlTable("sessions", {
expiresAt: datetime("expires_at").notNull() expiresAt: datetime("expires_at").notNull()
}); });
model Role { // model Role {
id String @id @default(cuid()) // id String @id @default(cuid())
name String @unique // name String @unique
userRoles UserRole[] // userRoles UserRole[]
@@map("roles") // @@map("roles")
} // }
model UserRole { export const roles = mysqlTable("roles", {
id String @id @default(cuid()) id: varchar("id", {
user User @relation(fields: [user_id], references: [id]) length: 255
user_id String }).primaryKey()
role Role @relation(fields: [role_id], references: [id]) .$defaultFn(() => nanoid()),
role_id String name: varchar("name", {
created_at DateTime @default(now()) @db.Timestamp(6) length: 255
updated_at DateTime @updatedAt @db.Timestamp(6) }).unique()
});
@@unique([user_id, role_id]) // model UserRole {
@@index([user_id]) // id String @id @default(cuid())
@@index([role_id]) // user User @relation(fields: [user_id], references: [id])
@@map("user_roles") // 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 { // @@unique([user_id, role_id])
id String @id @default(cuid()) // @@index([user_id])
user_id String @unique // @@index([role_id])
user User @relation(references: [id], fields: [user_id]) // @@map("user_roles")
items CollectionItem[] // }
@@index([user_id]) export const userRoles = mysqlTable("user_roles", {
@@map("collections") 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 { // model Game {
id String @id @default(cuid()) // id String @id @default(cuid())
collection_id String // name String
collection Collection @relation(references: [id], fields: [collection_id], onDelete: Cascade) // slug String
game_id String @unique // description String? @db.LongText
game Game @relation(references: [id], fields: [game_id]) // year_published Int? @db.Year
times_played Int // 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]) // @@fulltext([name])
@@index([game_id]) // @@fulltext([slug])
@@index([collection_id]) // @@map("games")
@@map("collection_items") // }
}
model Wishlist { export const games = mysqlTable("games", {
id String @id @default(cuid()) id: varchar("id", {
user_id String @unique length: 255
user User @relation(references: [id], fields: [user_id]) }).primaryKey()
items WishlistItem[] .$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]) // model Expansion {
@@map("wishlists") // 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 { // @@index([base_game_id])
id String @id @default(cuid()) // @@index([game_id])
wishlist_id String // @@map("expansions")
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([game_id, wishlist_id]) export const expansions = mysqlTable("expansions", {
@@index([game_id]) id: varchar("id", {
@@index([wishlist_id]) length: 255
@@map("wishlist_items") }).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 { // model Collection {
id String @id @default(cuid()) // id String @id @default(cuid())
name String // user_id String @unique
user_id String @unique // user User @relation(references: [id], fields: [user_id])
user User @relation(references: [id], fields: [user_id]) // items CollectionItem[]
items ListItem[]
@@index([user_id]) // @@index([user_id])
@@map("lists") // @@map("collections")
} // }
model ListItem { export const collections = mysqlTable("collections", {
id String @id @default(cuid()) id: varchar("id", {
list_id String length: 255
list List @relation(references: [id], fields: [list_id], onDelete: Cascade) }).primaryKey()
game_id String @unique .$defaultFn(() => nanoid()),
game Game @relation(references: [id], fields: [game_id]) userId: varchar("user_id", {
created_at DateTime @default(now()) @db.Timestamp(6) length: 255
updated_at DateTime @updatedAt @db.Timestamp(6) })
.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]) // model CollectionItem {
@@index([game_id]) // id String @id @default(cuid())
@@index([list_id]) // collection_id String
@@map("list_items") // 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 { // @@index([game_id, collection_id])
id String @id @default(cuid()) // @@index([game_id])
name String // @@index([collection_id])
slug String // @@map("collection_items")
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)
@@fulltext([name]) export const collectionItems = mysqlTable("collection_items", {
@@fulltext([slug]) id: varchar("id", {
@@map("games") 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 { // model Wishlist {
id String @id @default(cuid()) // id String @id @default(cuid())
name String // user_id String @unique
slug String // user User @relation(references: [id], fields: [user_id])
game_id String // items WishlistItem[]
game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
@@index([game_id]) // @@index([user_id])
@@map("game_names") // @@map("wishlists")
} // }
model Publisher { export const wishlists = mysqlTable("wishlists", {
id String @id @default(cuid()) id: varchar("id", {
name String length: 255
slug String }).primaryKey()
external_id Int @unique .$defaultFn(() => nanoid()),
games Game[] userId: varchar("user_id", {
created_at DateTime @default(now()) @db.Timestamp(6) length: 255
updated_at DateTime @updatedAt @db.Timestamp(6) })
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
createdAt: datetime("created_at").default(sql`(now(6))`),
updatedAt: datetime("updated_at").default(sql`(now(6))`)
});
@@fulltext([name]) // model WishlistItem {
@@map("publishers") // 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 { // @@index([game_id, wishlist_id])
id String @id @default(cuid()) // @@index([game_id])
name String // @@index([wishlist_id])
slug String // @@map("wishlist_items")
games Game[] // }
external_id Int @unique
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name]) export const wishlistItems = mysqlTable("wishlist_items", {
@@map("categories") 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 { // model List {
id String @id @default(cuid()) // id String @id @default(cuid())
name String // name String
slug String // user_id String @unique
games Game[] // user User @relation(references: [id], fields: [user_id])
external_id Int @unique // items ListItem[]
created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name]) // @@index([user_id])
@@map("mechanics") // @@map("lists")
} // }
model Designer { // model ListItem {
id String @id @default(cuid()) // id String @id @default(cuid())
name String // list_id String
slug String // list List @relation(references: [id], fields: [list_id], onDelete: Cascade)
external_id Int @unique // game_id String @unique
games Game[] // game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6) // created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6) // updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name]) // @@index([game_id, list_id])
@@map("designers") // @@index([game_id])
} // @@index([list_id])
// @@map("list_items")
// }
model Artist { // model GameName {
id String @id @default(cuid()) // id String @id @default(cuid())
name String // name String
slug String @unique // slug String
external_id Int @unique // game_id String
games Game[] // game Game @relation(references: [id], fields: [game_id])
created_at DateTime @default(now()) @db.Timestamp(6) // created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6) // updated_at DateTime @updatedAt @db.Timestamp(6)
@@fulltext([name]) // @@index([game_id])
@@map("artists") // @@map("game_names")
} // }
model Expansion { // model Publisher {
id String @id @default(cuid()) // id String @id @default(cuid())
base_game Game @relation(name: "BaseToExpansion", fields: [base_game_id], references: [id]) // name String
base_game_id String // slug String
game Game @relation(name: "ExpansionToBase", fields: [game_id], references: [id]) // external_id Int @unique
game_id String // games Game[]
created_at DateTime @default(now()) @db.Timestamp(6) // created_at DateTime @default(now()) @db.Timestamp(6)
updated_at DateTime @updatedAt @db.Timestamp(6) // updated_at DateTime @updatedAt @db.Timestamp(6)
@@index([base_game_id]) // @@fulltext([name])
@@index([game_id]) // @@map("publishers")
@@map("expansions") // }
}
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))`)
})