28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { pgTable, text, serial, timestamp, jsonb } from "drizzle-orm/pg-core";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { z } from "zod/v4";
|
|
|
|
export type UserPreferences = {
|
|
view?: "grid" | "table" | "rows";
|
|
density?: "cozy" | "compact";
|
|
watchlist?: number[];
|
|
};
|
|
|
|
export const usersTable = pgTable("users", {
|
|
id: serial("id").primaryKey(),
|
|
username: text("username").notNull().unique(),
|
|
email: text("email"),
|
|
role: text("role").notNull().default("user"),
|
|
passwordHash: text("password_hash"),
|
|
tier: text("tier").notNull().default("free"),
|
|
authProvider: text("auth_provider").notNull().default("local"),
|
|
authProviderId: text("auth_provider_id"),
|
|
displayName: text("display_name"),
|
|
preferences: jsonb("preferences").$type<UserPreferences>().notNull().default({}),
|
|
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
});
|
|
|
|
export const insertUserSchema = createInsertSchema(usersTable).omit({ id: true, createdAt: true });
|
|
export type InsertUser = z.infer<typeof insertUserSchema>;
|
|
export type LocalUser = typeof usersTable.$inferSelect;
|