|
| 1 | +// src/lib/db/schema.ts |
| 2 | +import { |
| 3 | + pgTable, |
| 4 | + serial, |
| 5 | + text, |
| 6 | + boolean, |
| 7 | + integer, |
| 8 | + timestamp, |
| 9 | + uniqueIndex, |
| 10 | + varchar, |
| 11 | + real, |
| 12 | + primaryKey, |
| 13 | +} from "drizzle-orm/pg-core"; |
| 14 | + |
| 15 | +// --- User --- |
| 16 | +export const users = pgTable("User", { |
| 17 | + id: serial("id").primaryKey(), |
| 18 | + Firstname: text("Firstname").notNull(), |
| 19 | + Lastname: text("Lastname").notNull(), |
| 20 | + username: text("username").notNull(), |
| 21 | + email: text("email").notNull(), |
| 22 | + hashedpass: text("hashedpass").notNull(), |
| 23 | + description: text("description"), |
| 24 | + isbanned: boolean("isbanned").notNull().default(false), |
| 25 | +}, |
| 26 | +(table) => ({ |
| 27 | + usernameIndex: uniqueIndex("username_idx").on(table.username), |
| 28 | + emailIndex: uniqueIndex("email_idx").on(table.email), |
| 29 | +})); |
| 30 | + |
| 31 | +// --- Category --- |
| 32 | +export const categories = pgTable("Category", { |
| 33 | + id: serial("id").primaryKey(), |
| 34 | + name: text("name").notNull(), |
| 35 | + description: text("description"), |
| 36 | + app_read: boolean("app_read").notNull().default(false), |
| 37 | + app_write: boolean("app_write").notNull().default(false), |
| 38 | + creationdate: timestamp("creationdate").defaultNow().notNull(), |
| 39 | + isdisable: boolean("isdisable").notNull().default(false), |
| 40 | + ishidden: boolean("ishidden").notNull().default(false), |
| 41 | + totaltopics: integer("totaltopics").notNull().default(0), |
| 42 | + createby: integer("createby").notNull(), |
| 43 | +}, (table) => ({ |
| 44 | + nameIndex: uniqueIndex("name_idx").on(table.name), |
| 45 | +})); |
| 46 | + |
| 47 | +// --- Post --- |
| 48 | +export const posts = pgTable("Post", { |
| 49 | + id: serial("id").primaryKey(), |
| 50 | + name: text("name").notNull(), |
| 51 | + description: text("description"), |
| 52 | + createby: integer("createby").notNull(), |
| 53 | + creation_date: timestamp("creation_date").defaultNow().notNull(), |
| 54 | + last_edited: timestamp("last_edited").notNull(), |
| 55 | + app_read: boolean("app_read").notNull().default(false), |
| 56 | + app_write: boolean("app_write").notNull().default(false), |
| 57 | + isdisable: boolean("isdisable").notNull().default(false), |
| 58 | + ishidden: boolean("ishidden").notNull().default(false), |
| 59 | + maplocation: text("maplocation"), |
| 60 | + categoryId: integer("categoryId").notNull(), |
| 61 | +}); |
| 62 | + |
| 63 | +// --- Review --- |
| 64 | +export const reviews = pgTable("Review", { |
| 65 | + id: serial("id").primaryKey(), |
| 66 | + userid: integer("userid").notNull(), |
| 67 | + topicid: integer("topicid").notNull(), |
| 68 | + title: text("title").notNull(), |
| 69 | + description: text("description").notNull(), |
| 70 | +}); |
| 71 | + |
| 72 | +// --- Log --- |
| 73 | +export const logs = pgTable("Log", { |
| 74 | + id: serial("id").primaryKey(), |
| 75 | + action: text("action").notNull(), |
| 76 | + who: integer("who").notNull(), |
| 77 | + ondate: timestamp("ondate").defaultNow().notNull(), |
| 78 | +}); |
| 79 | + |
| 80 | +// --- Session --- |
| 81 | +export const sessions = pgTable("Session", { |
| 82 | + id: varchar("id", { length: 255 }).primaryKey(), |
| 83 | + userId: integer("userId").notNull(), |
| 84 | + expiresAt: timestamp("expiresAt").notNull(), |
| 85 | +}); |
| 86 | + |
| 87 | +// --- Key --- |
| 88 | +export const keys = pgTable("Key", { |
| 89 | + id: varchar("id", { length: 255 }).primaryKey(), |
| 90 | + userId: integer("userId").notNull(), |
| 91 | + hashedPassword: text("hashedPassword"), |
| 92 | +}); |
| 93 | + |
| 94 | +// --- Stargazing --- |
| 95 | +export const stargazing = pgTable("Stargazing", { |
| 96 | + id: serial("id").primaryKey(), |
| 97 | + title: text("title").notNull(), |
| 98 | + description: text("description"), |
| 99 | + lat: real("lat").notNull(), |
| 100 | + long: real("long").notNull(), |
| 101 | +}); |
0 commit comments