| [b615094] | 1 | import {pgTable, serial, integer, text, numeric, boolean, date, primaryKey, check} from "drizzle-orm/pg-core";
|
|---|
| 2 | import {sql} from "drizzle-orm";
|
|---|
| [fdd776b] | 3 |
|
|---|
| 4 | export 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 |
|
|---|
| 11 | export const adminsTable = pgTable("admins", {
|
|---|
| 12 | userId: integer("user_id")
|
|---|
| 13 | .primaryKey()
|
|---|
| 14 | .references(() => usersTable.id, { onDelete: 'cascade', onUpdate: 'cascade' })
|
|---|
| 15 | })
|
|---|
| 16 |
|
|---|
| 17 | export 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 |
|
|---|
| 37 | export type userItem = typeof usersTable.$inferSelect;
|
|---|
| 38 | export type userInsert = typeof usersTable.$inferInsert;
|
|---|
| 39 |
|
|---|
| 40 | export type adminItem = typeof adminsTable.$inferSelect;
|
|---|
| 41 | export type adminInsert = typeof adminsTable.$inferInsert;
|
|---|
| 42 |
|
|---|
| 43 | export type suggestionItem = typeof suggestionsTable.$inferSelect;
|
|---|
| 44 | export type suggestionInsert = typeof suggestionsTable.$inferInsert; |
|---|