2024-12-15 23:39:56 -05:00
|
|
|
import { sql } from "drizzle-orm";
|
2024-12-16 14:31:44 -05:00
|
|
|
import { bigserial, boolean, check, date, pgTable, text, timestamp, unique, uuid, varchar } from "drizzle-orm/pg-core";
|
2024-12-15 23:39:56 -05:00
|
|
|
|
2024-12-16 14:31:44 -05:00
|
|
|
export const User = pgTable("users", {
|
2024-12-15 23:39:56 -05:00
|
|
|
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
|
|
|
|
username: varchar({ length: 50 }).notNull(),
|
|
|
|
|
email: varchar({ length: 255 }).notNull(),
|
|
|
|
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
|
|
|
|
firstName: varchar("first_name", { length: 50 }),
|
|
|
|
|
lastName: varchar("last_name", { length: 50 }),
|
|
|
|
|
profilePicture: varchar("profile_picture", { length: 255 }),
|
|
|
|
|
dateOfBirth: date("date_of_birth"),
|
|
|
|
|
phoneNumber: varchar("phone_number", { length: 20 }),
|
|
|
|
|
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
|
|
|
|
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
|
|
|
|
isAdmin: boolean("is_admin").default(false),
|
|
|
|
|
lastLogin: timestamp("last_login", { mode: 'string' }),
|
|
|
|
|
emailVerified: boolean("email_verified").default(false),
|
|
|
|
|
buildPrivacySetting: text("build_privacy_setting").default('public'),
|
2024-12-16 14:31:44 -05:00
|
|
|
uuid: uuid().defaultRandom(),
|
2024-12-15 23:39:56 -05:00
|
|
|
}, (table) => {
|
|
|
|
|
return {
|
|
|
|
|
usersUsernameKey: unique("users_username_key").on(table.username),
|
|
|
|
|
usersEmailKey: unique("users_email_key").on(table.email),
|
|
|
|
|
usersBuildPrivacySettingCheck: check("users_build_privacy_setting_check", sql`build_privacy_setting = ANY (ARRAY['private'::text, 'public'::text])`),
|
|
|
|
|
}
|
2024-12-16 17:28:57 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const users = pgTable("user", {
|
|
|
|
|
id: text("id")
|
|
|
|
|
.primaryKey()
|
|
|
|
|
.$defaultFn(() => crypto.randomUUID()),
|
|
|
|
|
name: text("name"),
|
|
|
|
|
email: text("email").unique(),
|
|
|
|
|
emailVerified: timestamp("emailVerified", { mode: "date" }),
|
|
|
|
|
image: text("image"),
|
|
|
|
|
})
|