feat: add content schema with Drizzle ORM integration

This commit is contained in:
Mathis HERRIOT
2026-01-05 14:15:28 +01:00
parent 9439c004e2
commit 9fb890699a

View File

@@ -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;