From 7761e26d324fe02dfa7e3fd89e0abf5bcade3e29 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Mon, 5 Jan 2026 12:10:49 +0100 Subject: [PATCH] feat: add user schema with PostgreSQL integration using Drizzle ORM --- backend/src/database/schemas/index.ts | 1 + backend/src/database/schemas/users.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 backend/src/database/schemas/index.ts create mode 100644 backend/src/database/schemas/users.ts diff --git a/backend/src/database/schemas/index.ts b/backend/src/database/schemas/index.ts new file mode 100644 index 0000000..83131ec --- /dev/null +++ b/backend/src/database/schemas/index.ts @@ -0,0 +1 @@ +export * from './users'; \ No newline at end of file diff --git a/backend/src/database/schemas/users.ts b/backend/src/database/schemas/users.ts new file mode 100644 index 0000000..2b7d9b5 --- /dev/null +++ b/backend/src/database/schemas/users.ts @@ -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;