source: database/drizzle/schema/users.ts@ b615094

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

add constraints

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[b615094]1import {pgTable, serial, integer, text, numeric, boolean, date, primaryKey, check} from "drizzle-orm/pg-core";
2import {sql} from "drizzle-orm";
[fdd776b]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()
[b615094]29 .default("pending"),
[fdd776b]30 componentType: text("component_type").notNull()
[b615094]31 },
32 (t) => ({
33 checkStatus: check("check_status", sql`${t.status} in ('pending', 'approved', 'rejected')`),
34 }),
35);
[fdd776b]36
37export type userItem = typeof usersTable.$inferSelect;
38export type userInsert = typeof usersTable.$inferInsert;
39
40export type adminItem = typeof adminsTable.$inferSelect;
41export type adminInsert = typeof adminsTable.$inferInsert;
42
43export type suggestionItem = typeof suggestionsTable.$inferSelect;
44export type suggestionInsert = typeof suggestionsTable.$inferInsert;
Note: See TracBrowser for help on using the repository browser.