2026-03-04 18:07:18 +01:00
|
|
|
import {
|
|
|
|
|
pgTable,
|
|
|
|
|
text,
|
|
|
|
|
timestamp,
|
|
|
|
|
pgEnum,
|
|
|
|
|
boolean,
|
|
|
|
|
index,
|
|
|
|
|
uniqueIndex,
|
|
|
|
|
integer,
|
|
|
|
|
} from "drizzle-orm/pg-core";
|
2026-03-04 18:42:58 +01:00
|
|
|
import { files } from "./files";
|
2026-03-04 18:07:18 +01:00
|
|
|
|
|
|
|
|
export const roleEnum = pgEnum("user_role", ["model", "viewer", "admin"]);
|
|
|
|
|
|
|
|
|
|
export const users = pgTable(
|
|
|
|
|
"users",
|
|
|
|
|
{
|
2026-03-04 22:27:54 +01:00
|
|
|
id: text("id")
|
|
|
|
|
.primaryKey()
|
|
|
|
|
.$defaultFn(() => crypto.randomUUID()),
|
2026-03-04 18:07:18 +01:00
|
|
|
email: text("email").notNull(),
|
|
|
|
|
password_hash: text("password_hash").notNull(),
|
|
|
|
|
first_name: text("first_name"),
|
|
|
|
|
last_name: text("last_name"),
|
|
|
|
|
artist_name: text("artist_name"),
|
|
|
|
|
slug: text("slug"),
|
|
|
|
|
description: text("description"),
|
|
|
|
|
tags: text("tags").array().default([]),
|
|
|
|
|
role: roleEnum("role").notNull().default("viewer"),
|
|
|
|
|
avatar: text("avatar").references(() => files.id, { onDelete: "set null" }),
|
|
|
|
|
banner: text("banner").references(() => files.id, { onDelete: "set null" }),
|
2026-03-08 10:54:27 +01:00
|
|
|
photo: text("photo").references(() => files.id, { onDelete: "set null" }),
|
2026-03-06 16:14:00 +01:00
|
|
|
is_admin: boolean("is_admin").notNull().default(false),
|
2026-03-04 18:07:18 +01:00
|
|
|
email_verified: boolean("email_verified").notNull().default(false),
|
|
|
|
|
email_verify_token: text("email_verify_token"),
|
|
|
|
|
password_reset_token: text("password_reset_token"),
|
|
|
|
|
password_reset_expiry: timestamp("password_reset_expiry"),
|
|
|
|
|
date_created: timestamp("date_created").notNull().defaultNow(),
|
|
|
|
|
date_updated: timestamp("date_updated"),
|
|
|
|
|
},
|
|
|
|
|
(t) => [
|
|
|
|
|
uniqueIndex("users_email_idx").on(t.email),
|
|
|
|
|
uniqueIndex("users_slug_idx").on(t.slug),
|
|
|
|
|
index("users_role_idx").on(t.role),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const user_photos = pgTable(
|
|
|
|
|
"user_photos",
|
|
|
|
|
{
|
|
|
|
|
id: integer("id").primaryKey().generatedAlwaysAsIdentity(),
|
|
|
|
|
user_id: text("user_id")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => users.id, { onDelete: "cascade" }),
|
|
|
|
|
file_id: text("file_id")
|
|
|
|
|
.notNull()
|
|
|
|
|
.references(() => files.id, { onDelete: "cascade" }),
|
|
|
|
|
sort: integer("sort").default(0),
|
|
|
|
|
},
|
|
|
|
|
(t) => [index("user_photos_user_idx").on(t.user_id)],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export type User = typeof users.$inferSelect;
|
|
|
|
|
export type NewUser = typeof users.$inferInsert;
|