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,32 +1,59 @@
import { pgTable, varchar, timestamp, uuid, pgEnum, index, primaryKey, integer } from 'drizzle-orm/pg-core';
import { users } from './users';
import { tags } from './tags';
import {
pgTable,
varchar,
timestamp,
uuid,
pgEnum,
index,
primaryKey,
integer,
} from "drizzle-orm/pg-core";
import { users } from "./users";
import { tags } from "./tags";
export const contentType = pgEnum('content_type', ['meme', 'gif']);
export const contentType = pgEnum("content_type", ["meme", "gif"]);
export const contents = pgTable('contents', {
id: uuid('id').primaryKey().defaultRandom(),
userId: uuid('user_id').notNull().references(() => users.uuid, { onDelete: 'cascade' }),
type: contentType('type').notNull(),
title: varchar('title', { length: 255 }).notNull(),
storageKey: varchar('storage_key', { length: 512 }).notNull().unique(), // Clé interne S3
mimeType: varchar('mime_type', { length: 128 }).notNull(), // Pour le Content-Type HTTP
fileSize: integer('file_size').notNull(), // Taille en octets
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
deletedAt: timestamp('deleted_at', { withTimezone: true }), // Soft delete
}, (table) => ({
userIdIdx: index('contents_user_id_idx').on(table.userId),
storageKeyIdx: index('contents_storage_key_idx').on(table.storageKey),
deletedAtIdx: index('contents_deleted_at_idx').on(table.deletedAt),
}));
export const contents = pgTable(
"contents",
{
id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id")
.notNull()
.references(() => users.uuid, { onDelete: "cascade" }),
type: contentType("type").notNull(),
title: varchar("title", { length: 255 }).notNull(),
storageKey: varchar("storage_key", { length: 512 }).notNull().unique(), // Clé interne S3
mimeType: varchar("mime_type", { length: 128 }).notNull(), // Pour le Content-Type HTTP
fileSize: integer("file_size").notNull(), // Taille en octets
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
deletedAt: timestamp("deleted_at", { withTimezone: true }), // Soft delete
},
(table) => ({
userIdIdx: index("contents_user_id_idx").on(table.userId),
storageKeyIdx: index("contents_storage_key_idx").on(table.storageKey),
deletedAtIdx: index("contents_deleted_at_idx").on(table.deletedAt),
}),
);
export const contentsToTags = pgTable('contents_to_tags', {
contentId: uuid('content_id').notNull().references(() => contents.id, { onDelete: 'cascade' }),
tagId: uuid('tag_id').notNull().references(() => tags.id, { onDelete: 'cascade' }),
}, (t) => ({
pk: primaryKey({ columns: [t.contentId, t.tagId] }),
}));
export const contentsToTags = pgTable(
"contents_to_tags",
{
contentId: uuid("content_id")
.notNull()
.references(() => contents.id, { onDelete: "cascade" }),
tagId: uuid("tag_id")
.notNull()
.references(() => tags.id, { onDelete: "cascade" }),
},
(t) => ({
pk: primaryKey({ columns: [t.contentId, t.tagId] }),
}),
);
export type ContentInDb = typeof contents.$inferSelect;
export type NewContentInDb = typeof contents.$inferInsert;