46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import {
|
|
text,
|
|
pgTable,
|
|
numeric,
|
|
index,
|
|
timestamp,
|
|
boolean,
|
|
uuid,
|
|
uniqueIndex,
|
|
} from "drizzle-orm/pg-core";
|
|
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
|
|
export const users = pgTable(
|
|
"users",
|
|
{
|
|
user_id: uuid("user_id").defaultRandom().primaryKey(),
|
|
username: text("username").notNull(),
|
|
email: text("email").notNull(),
|
|
password: text("password").notNull(),
|
|
passwordToken: text("passwordToken"),
|
|
passwordTokenExpires: timestamp("passwordTokenExpires"),
|
|
acitve: boolean("active").default(true).notNull(),
|
|
pinCode: numeric("pingcode"),
|
|
role: text("role").default("user").notNull(), // temp column while we migrate the front end
|
|
lastLogin: timestamp("lastLogin").defaultNow(),
|
|
add_User: text("add_User").default("LST_System").notNull(),
|
|
add_Date: timestamp("add_Date").defaultNow(),
|
|
upd_user: text("upd_User").default("LST_System").notNull(),
|
|
upd_date: timestamp("upd_date").defaultNow(),
|
|
},
|
|
(table) => [
|
|
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
|
|
uniqueIndex("username").on(table.username),
|
|
]
|
|
);
|
|
|
|
// Schema for inserting a user - can be used to validate API requests
|
|
// export const insertUsersSchema = createInsertSchema(users, {
|
|
// username: z.string().min(3, {message: "Username must be at least 3 characters"}),
|
|
// email: z.string().email({message: "Invalid email"}),
|
|
// password: z.string().min(8, {message: "Password must be at least 8 characters"}),
|
|
// });
|
|
// Schema for selecting a Expenses - can be used to validate API responses
|
|
export const selectUsersSchema = createSelectSchema(users);
|