feat: add user schema with PostgreSQL integration using Drizzle ORM
This commit is contained in:
1
backend/src/database/schemas/index.ts
Normal file
1
backend/src/database/schemas/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './users';
|
||||||
22
backend/src/database/schemas/users.ts
Normal file
22
backend/src/database/schemas/users.ts
Normal 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;
|
||||||
Reference in New Issue
Block a user