import { boolean, integer, pgTable, primaryKey, timestamp, varchar } from "drizzle-orm/pg-core"; export const users = pgTable("users", { id: integer().primaryKey().generatedAlwaysAsIdentity(), email: varchar().unique().notNull(), name: varchar({ length: 26 }).unique().notNull(), pass: varchar({ length: 255 }).notNull(), registered: timestamp().notNull(), status: integer().default(0).notNull() // 000 |> verified / banned / moderator }); export const updates = pgTable("updates", { id: integer().primaryKey().generatedAlwaysAsIdentity(), user: integer() .references(() => users.id, { onDelete: "cascade" }) .notNull(), mood: integer().default(0).notNull(), description: varchar({ length: 512 }).default("").notNull(), date: timestamp().notNull() }); export const journalEntries = pgTable("journal_entries", { id: integer().primaryKey().generatedAlwaysAsIdentity(), user: integer() .references(() => users.id, { onDelete: "cascade" }) .notNull(), moodChange: integer("mood-change").default(0).notNull(), title: varchar({ length: 64 }).default("").notNull(), entry: varchar({ length: 4096 }).default("").notNull(), visibility: integer().default(1).notNull(), date: timestamp().notNull() }); export const journalComments = pgTable("journal_comments", { id: integer().primaryKey().generatedAlwaysAsIdentity(), user: integer() .references(() => users.id, { onDelete: "cascade" }) .notNull(), entry: integer() .references(() => journalEntries.id, { onDelete: "cascade" }) .notNull(), content: varchar({ length: 512 }).notNull(), date: timestamp().notNull() }); export const profiles = pgTable("profiles", { user: integer() .references(() => users.id, { onDelete: "cascade" }) .primaryKey() .notNull(), bio: varchar({ length: 1024 }).default("").notNull(), website: varchar().default("").notNull() }); export const follows = pgTable( "follows", { userId: integer("user_id").references(() => users.id, { onDelete: "cascade" }), followerId: integer("follower_id").references(() => users.id, { onDelete: "cascade" }) }, (table) => { return { pk: primaryKey({ columns: [table.userId, table.followerId] }) }; } ); export const inviteCodes = pgTable("invite_codes", { token: varchar({ length: 22 }).primaryKey(), user: integer("user_id").references(() => users.id, { onDelete: "cascade" }), granted: timestamp().notNull(), expires: timestamp().default(new Date(0)), confers: integer().default(0) });