feat: add user schema with PostgreSQL integration using Drizzle ORM

This commit is contained in:
Mathis HERRIOT
2026-01-05 12:10:49 +01:00
parent 6c4f1694ba
commit 7761e26d32
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1 @@
export * from './users';

View File

@@ -0,0 +1,22 @@
import {pgTable, varchar, timestamp, uuid, pgEnum, index} from 'drizzle-orm/pg-core';
export const userStatus = pgEnum("user_status", ["active", "verification", "suspended", "pending", "deleted"])
export const users = pgTable('users', {
status: userStatus('status').default('pending').notNull(),
uuid: uuid().primaryKey().defaultRandom(),
email: varchar('email', { length: 128 }).notNull().unique(),
username: varchar('username', { length: 32 }).notNull().unique(),
displayName: varchar('display_name', { length: 32 }),
passwordHash: varchar('password_hash', { length: 72 }).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
gdprAcceptation: timestamp('gdpr_acceptation', { withTimezone: true }),
}, (table) => ({
uuidIdx: index('users_uuid_idx').on(table.uuid),
emailIdx: index('users_email_idx').on(table.email),
usernameIdx: index('users_username_idx').on(table.username),
}));
export type UserInDb = typeof users.$inferSelect;
export type NewUserInDb = typeof users.$inferInsert;