Files
memegoat/backend/src/database/schemas/sessions.ts
Mathis HERRIOT 38e97741e0
Some checks failed
Lint / lint (push) Failing after 4m58s
chore: reformat schemas and documentation files for consistency
Standardized formatting across database schema files and updated documentation structure to improve clarity and organization.
2026-01-05 16:17:41 +01:00

36 lines
1.1 KiB
TypeScript

import {
boolean,
index,
pgTable,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core";
import { users } from "./users";
export const sessions = pgTable(
"sessions",
{
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id")
.notNull()
.references(() => users.uuid, { onDelete: "cascade" }),
refreshToken: varchar("refresh_token", { length: 512 }).notNull().unique(),
userAgent: varchar("user_agent", { length: 255 }),
ipHash: varchar("ip_hash", { length: 64 }), // IP hachée pour la protection de la vie privée (RGPD)
isValid: boolean("is_valid").notNull().default(true),
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => ({
userIdIdx: index("sessions_user_id_idx").on(table.userId),
refreshTokenIdx: index("sessions_refresh_token_idx").on(table.refreshToken),
expiresAtIdx: index("sessions_expires_at_idx").on(table.expiresAt),
}),
);