feat: add users and auth tables schema

Made-with: Cursor
This commit is contained in:
Anton
2026-03-04 13:38:07 +03:00
parent a7394c4d9d
commit 8b3a4c475f
4 changed files with 63 additions and 0 deletions

18
src/db/schema/sessions.ts Normal file
View File

@@ -0,0 +1,18 @@
import { pgTable, uuid, varchar, timestamp } from 'drizzle-orm/pg-core';
import { users } from './users.js';
export const sessions = pgTable('sessions', {
id: uuid('id').primaryKey().defaultRandom(),
userId: uuid('user_id')
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
refreshTokenHash: varchar('refresh_token_hash', { length: 255 }).notNull(),
userAgent: varchar('user_agent', { length: 500 }),
ipAddress: varchar('ip_address', { length: 45 }),
lastActiveAt: timestamp('last_active_at', { withTimezone: true }).notNull().defaultNow(),
expiresAt: timestamp('expires_at', { withTimezone: true }).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});
export type Session = typeof sessions.$inferSelect;
export type NewSession = typeof sessions.$inferInsert;