Some checks failed
Lint / lint (push) Failing after 4m58s
Standardized formatting across database schema files and updated documentation structure to improve clarity and organization.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import {
|
|
boolean,
|
|
index,
|
|
pgTable,
|
|
timestamp,
|
|
uuid,
|
|
varchar,
|
|
} from "drizzle-orm/pg-core";
|
|
import { users } from "./users";
|
|
|
|
export const apiKeys = pgTable(
|
|
"api_keys",
|
|
{
|
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
userId: uuid("user_id")
|
|
.notNull()
|
|
.references(() => users.uuid, { onDelete: "cascade" }),
|
|
keyHash: varchar("key_hash", { length: 128 }).notNull().unique(), // Haché pour la sécurité (SHA-256)
|
|
name: varchar("name", { length: 128 }).notNull(), // Nom donné par l'utilisateur (ex: "My App")
|
|
prefix: varchar("prefix", { length: 8 }).notNull(), // Pour identification visuelle (ex: "mg_...")
|
|
isActive: boolean("is_active").notNull().default(true),
|
|
lastUsedAt: timestamp("last_used_at", { withTimezone: true }),
|
|
expiresAt: timestamp("expires_at", { withTimezone: true }),
|
|
createdAt: timestamp("created_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
updatedAt: timestamp("updated_at", { withTimezone: true })
|
|
.notNull()
|
|
.defaultNow(),
|
|
},
|
|
(table) => ({
|
|
userIdIdx: index("api_keys_user_id_idx").on(table.userId),
|
|
keyHashIdx: index("api_keys_key_hash_idx").on(table.keyHash),
|
|
}),
|
|
);
|