2024-02-06 07:18:13 +00:00
|
|
|
import { relations, sql, type InferSelectModel } from 'drizzle-orm';
|
2024-02-09 02:56:09 +00:00
|
|
|
import { pgTable, timestamp, varchar, boolean, integer, text } from 'drizzle-orm/pg-core';
|
2024-02-03 01:56:31 +00:00
|
|
|
import { nanoid } from 'nanoid';
|
2024-01-31 02:19:51 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const users = pgTable("users", {
|
2024-01-31 02:19:51 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
2024-02-03 01:56:31 +00:00
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
username: varchar("username", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).unique(),
|
2024-02-07 01:08:03 +00:00
|
|
|
hashed_password: varchar("hashed_password", {
|
2024-02-03 01:56:31 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
email: varchar("email", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).unique(),
|
2024-02-07 01:08:03 +00:00
|
|
|
first_name: varchar("first_name", {
|
2024-02-03 01:56:31 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-07 01:08:03 +00:00
|
|
|
last_name: varchar("last_name", {
|
2024-02-03 01:56:31 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
verified: boolean("verified").default(false),
|
2024-02-07 01:08:03 +00:00
|
|
|
receive_email: boolean("receive_email").default(false),
|
2024-02-03 01:56:31 +00:00
|
|
|
theme: varchar("theme", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).default("system"),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at").default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at").default(sql`(now())`)
|
2024-01-31 02:19:51 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const user_relations = relations(users, ({ many }) => ({
|
|
|
|
|
user_roles: many(user_roles)
|
|
|
|
|
}));
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-06 07:18:13 +00:00
|
|
|
export type Users = InferSelectModel<typeof users>;
|
2024-02-03 01:56:31 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const sessions = pgTable('sessions', {
|
2024-02-06 07:18:13 +00:00
|
|
|
id: varchar('id', {
|
2024-01-31 02:19:51 +00:00
|
|
|
length: 255
|
2024-02-06 07:18:13 +00:00
|
|
|
}).primaryKey(),
|
|
|
|
|
userId: varchar('user_id', {
|
2024-01-31 02:19:51 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
2024-02-06 07:18:13 +00:00
|
|
|
.references(() => users.id),
|
2024-02-09 02:56:09 +00:00
|
|
|
expiresAt: timestamp('expires_at', {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date"
|
|
|
|
|
}).notNull(),
|
2024-02-06 07:18:13 +00:00
|
|
|
ipCountry: varchar('ip_country', {
|
2024-02-03 01:56:31 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-06 07:18:13 +00:00
|
|
|
ipAddress: varchar('ip_address', {
|
2024-02-03 01:56:31 +00:00
|
|
|
length: 255
|
2024-02-06 07:18:13 +00:00
|
|
|
})
|
2024-01-31 02:19:51 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const roles = pgTable("roles", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).unique()
|
|
|
|
|
});
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const user_roles = pgTable("user_roles", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
user_id: varchar("user_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
2024-02-08 01:16:17 +00:00
|
|
|
role_id: varchar("role_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => roles.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-04 02:21:32 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const user_role_relations = relations(user_roles, ({ one }) => ({
|
|
|
|
|
role: one(roles, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [user_roles.role_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [roles.id]
|
|
|
|
|
}),
|
|
|
|
|
user: one(users, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [user_roles.user_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [users.id]
|
|
|
|
|
})
|
|
|
|
|
}));
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const games = pgTable("games", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
description: text("description"),
|
2024-02-09 02:56:09 +00:00
|
|
|
year_published: integer("year_published"),
|
|
|
|
|
min_players: integer("min_players"),
|
|
|
|
|
max_players: integer("max_players"),
|
|
|
|
|
playtime: integer("playtime"),
|
|
|
|
|
min_playtime: integer("min_playtime"),
|
|
|
|
|
max_playtime: integer("max_playtime"),
|
|
|
|
|
min_age: integer("min_age"),
|
2024-02-08 01:16:17 +00:00
|
|
|
image_url: varchar("image_url", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
thumb_url: varchar("thumb_url", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
url: varchar("url", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id").unique(),
|
|
|
|
|
last_sync_at: timestamp("last_sync_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-06 07:18:13 +00:00
|
|
|
export type Games = InferSelectModel<typeof games>;
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const gameRelations = relations(games, ({ many }) => ({
|
|
|
|
|
categories_to_games: many(categories_to_games),
|
|
|
|
|
mechanics_to_games: many(mechanics_to_games),
|
|
|
|
|
designers_to_games: many(designers_to_games),
|
|
|
|
|
publishers_to_games: many(publishers_to_games),
|
|
|
|
|
artists_to_games: many(artists_to_games),
|
|
|
|
|
}))
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const expansions = pgTable("expansions", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
base_game_id: varchar("base_game_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => games.id, { onDelete: 'cascade' }),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => games.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-04 02:21:32 +00:00
|
|
|
})
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const expansion_relations = relations(expansions, ({ one }) => ({
|
|
|
|
|
baseGame: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [expansions.base_game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [expansions.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
})
|
|
|
|
|
}));
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const collections = pgTable("collections", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
user_id: varchar("user_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const collection_relations = relations(collections, ({ one }) => ({
|
|
|
|
|
user: one(users, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [collections.user_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [users.id]
|
|
|
|
|
}),
|
|
|
|
|
}))
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const collection_items = pgTable("collection_items", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
collection_id: varchar("collection_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => collections.id, { onDelete: 'cascade' }),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => games.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const collection_item_relations = relations(collection_items, ({ one }) =>({
|
|
|
|
|
collection: one(collections, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [collection_items.collection_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [collections.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [collection_items.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
})
|
|
|
|
|
}));
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const wishlists = pgTable("wishlists", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
user_id: varchar("user_id", {
|
2024-02-04 02:21:32 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => users.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-04 02:21:32 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const wishlists_relations = relations(wishlists, ({ one }) => ({
|
|
|
|
|
user: one(users, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [wishlists.user_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [users.id]
|
|
|
|
|
}),
|
|
|
|
|
}))
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const wishlist_items = pgTable('wishlist_items', {
|
2024-02-05 01:53:23 +00:00
|
|
|
id: varchar('id', {
|
|
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
2024-02-08 01:16:17 +00:00
|
|
|
wishlist_id: varchar('wishlist_id', {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => wishlists.id, { onDelete: 'cascade' }),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar('game_id', {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
})
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => games.id, { onDelete: 'cascade' }),
|
2024-02-09 02:56:09 +00:00
|
|
|
created_at: timestamp('created_at', {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp('updated_at', {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-04 02:21:32 +00:00
|
|
|
});
|
|
|
|
|
|
2024-02-05 01:53:23 +00:00
|
|
|
export const wishlist_item_relations = relations(wishlist_items, ({ one }) => ({
|
|
|
|
|
wishlist: one(wishlists, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [wishlist_items.wishlist_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [wishlists.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [wishlist_items.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const publishers = pgTable("publishers", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id"),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const publishers_relations = relations(publishers, ({ many }) => ({
|
|
|
|
|
publishers_to_games: many(publishers_to_games)
|
|
|
|
|
}));
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const categories = pgTable("categories", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id"),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const categories_relations = relations(categories, ({ many }) => ({
|
|
|
|
|
categories_to_games: many(categories_to_games)
|
|
|
|
|
}));
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const mechanics = pgTable("mechanics", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id"),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const mechanic_relations = relations(mechanics, ({ many }) => ({
|
|
|
|
|
mechanics_to_games: many(mechanics_to_games)
|
|
|
|
|
}))
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const designers = pgTable("designers", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id"),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const designers_relations = relations(designers, ({ many }) => ({
|
|
|
|
|
designers_to_games: many(designers_to_games)
|
|
|
|
|
}));
|
2024-02-04 02:21:32 +00:00
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const artists = pgTable("artists", {
|
2024-02-04 02:21:32 +00:00
|
|
|
id: varchar("id", {
|
|
|
|
|
length: 255
|
|
|
|
|
}).primaryKey()
|
|
|
|
|
.$defaultFn(() => nanoid()),
|
|
|
|
|
name: varchar("name", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
slug: varchar("slug", {
|
|
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-09 02:56:09 +00:00
|
|
|
external_id: integer("external_id"),
|
|
|
|
|
created_at: timestamp("created_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`),
|
|
|
|
|
updated_at: timestamp("updated_at", {
|
|
|
|
|
withTimezone: true,
|
|
|
|
|
mode: "date",
|
|
|
|
|
precision: 6
|
|
|
|
|
}).default(sql`(now())`)
|
2024-02-05 01:53:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const artists_relations = relations(artists, ({ many }) => ({
|
|
|
|
|
artists_to_games: many(artists_to_games)
|
|
|
|
|
}));
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const artists_to_games = pgTable('artists_to_games', {
|
2024-02-08 01:16:17 +00:00
|
|
|
artist_id: varchar('artist_id', {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar('game_id', {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const artists_to_games_relations = relations(artists_to_games, ({ one }) => ({
|
|
|
|
|
artist: one(artists, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [artists_to_games.artist_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [artists.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [artists_to_games.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const categories_to_games = pgTable("categories_to_games", {
|
2024-02-08 01:16:17 +00:00
|
|
|
category_id: varchar("category_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const categories_to_games_relations = relations(categories_to_games, ({ one }) => ({
|
|
|
|
|
category: one(categories, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [categories_to_games.category_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [categories.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [categories_to_games.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
}))
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const designers_to_games = pgTable("designers_to_games", {
|
2024-02-08 01:16:17 +00:00
|
|
|
designer_id: varchar("designer_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const designers_to_games_relations = relations(designers_to_games, ({ one }) => ({
|
|
|
|
|
designer: one(designers, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [designers_to_games.designer_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [designers.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [designers_to_games.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
}))
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const mechanics_to_games = pgTable("mechanics_to_games", {
|
2024-02-08 01:16:17 +00:00
|
|
|
mechanic_id: varchar("mechanic_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const mechanics_to_games_relations = relations(mechanics_to_games, ({ one }) => ({
|
|
|
|
|
mechanic: one(mechanics, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [mechanics_to_games.mechanic_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [mechanics.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [mechanics_to_games.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
}));
|
|
|
|
|
|
2024-02-09 02:56:09 +00:00
|
|
|
export const publishers_to_games = pgTable("publishers_to_games", {
|
2024-02-08 01:16:17 +00:00
|
|
|
publisher_id: varchar("publisher_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
2024-02-08 01:16:17 +00:00
|
|
|
game_id: varchar("game_id", {
|
2024-02-05 01:53:23 +00:00
|
|
|
length: 255
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const publishers_to_games_relations = relations(publishers_to_games, ({ one }) => ({
|
|
|
|
|
publisher: one(publishers, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [publishers_to_games.publisher_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [publishers.id]
|
|
|
|
|
}),
|
|
|
|
|
game: one(games, {
|
2024-02-08 01:16:17 +00:00
|
|
|
fields: [publishers_to_games.game_id],
|
2024-02-05 01:53:23 +00:00
|
|
|
references: [games.id]
|
|
|
|
|
}),
|
|
|
|
|
}));
|