From 9fb890699a7aabfdf308a46d10d6884fbdd3af04 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Mon, 5 Jan 2026 14:15:28 +0100 Subject: [PATCH] feat: add content schema with Drizzle ORM integration --- backend/src/database/schemas/content.ts | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 backend/src/database/schemas/content.ts diff --git a/backend/src/database/schemas/content.ts b/backend/src/database/schemas/content.ts new file mode 100644 index 0000000..311b43e --- /dev/null +++ b/backend/src/database/schemas/content.ts @@ -0,0 +1,32 @@ +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 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 type ContentInDb = typeof contents.$inferSelect; +export type NewContentInDb = typeof contents.$inferInsert;