chore: reformat database schema files for readability

Applied consistent formatting and indentation across all schema files using Drizzle ORM to enhance code clarity and maintainability.
This commit is contained in:
Mathis HERRIOT
2026-01-05 15:59:15 +01:00
parent cadc497dec
commit b22129c4dd
10 changed files with 388 additions and 207 deletions

View File

@@ -1,18 +1,35 @@
import { pgTable, varchar, timestamp, uuid, index, boolean } from 'drizzle-orm/pg-core';
import { users } from './users';
import {
pgTable,
varchar,
timestamp,
uuid,
index,
boolean,
} 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),
}));
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),
}),
);