source: database/drizzle/schema/users.ts@ 82aa6ae

main
Last change on this file since 82aa6ae was 37bcb87, checked in by Tome <gjorgievtome@…>, 7 months ago

update schema

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import {pgTable, serial, integer, text, numeric, boolean, date, primaryKey, check} from "drizzle-orm/pg-core";
2import {sql} from "drizzle-orm";
3
4export const usersTable = pgTable("users", {
5 id: serial("id").primaryKey(),
6 username: text("username").notNull().unique(),
7 passwordHash: text("password").notNull(),
8 email: text("email").notNull().unique()
9})
10
11export const adminsTable = pgTable("admins", {
12 userId: integer("user_id")
13 .primaryKey()
14 .references(() => usersTable.id, { onDelete: 'cascade', onUpdate: 'cascade' })
15})
16
17export const suggestionsTable = pgTable("suggestions", {
18 id: serial("id").primaryKey(),
19 userId: integer("user_id")
20 .notNull()
21 .references(() => usersTable.id, { onDelete: 'cascade', onUpdate: 'cascade' }),
22 adminId: integer("admin_id")
23 .references(() => adminsTable.userId, { onDelete: 'set null', onUpdate: 'cascade' }),
24 link: text("link").notNull(),
25 adminComment: text("admin_comment"),
26 description: text("description"),
27 status: text("status")
28 .notNull()
29 .default("pending"),
30 componentType: text("component_type").notNull()
31 },
32 (t) => ({
33 checkStatus: check("check_status", sql`${t.status} in ('pending', 'approved', 'rejected')`),
34 checkType: check("check_type", sql`${t.componentType} in
35 ('cpu', 'gpu', 'memory', 'storage', 'power_supply', 'motherboard', 'case', 'cooler', 'memory_card', 'optical_drive', 'sound_card', 'cables', 'network_adapter', 'network_card')`),
36 }),
37);
38
39export type userItem = typeof usersTable.$inferSelect;
40export type userInsert = typeof usersTable.$inferInsert;
41
42export type adminItem = typeof adminsTable.$inferSelect;
43export type adminInsert = typeof adminsTable.$inferInsert;
44
45export type suggestionItem = typeof suggestionsTable.$inferSelect;
46export type suggestionInsert = typeof suggestionsTable.$inferInsert;
Note: See TracBrowser for help on using the repository browser.