// src/db/schema.ts
import {
mysqlTable, varchar, timestamp, mysqlEnum,
char, int, primaryKey,
} from 'drizzle-orm/mysql-core'
import { relations } from 'drizzle-orm'
// --- Authors ---
export const authors = mysqlTable('authors', {
id: char('id', { length: 36 }).notNull().primaryKey(),
name: varchar('name', { length: 255 }).notNull(),
email: varchar('email', { length: 255 }).notNull(),
avatarUrl: varchar('avatarUrl', { length: 1000 }),
createdAt: timestamp('createdAt').notNull(),
})
// --- Tags ---
export const tags = mysqlTable('tags', {
id: char('id', { length: 36 }).notNull().primaryKey(),
name: varchar('name', { length: 100 }).notNull(),
slug: varchar('slug', { length: 100 }).notNull(),
})
// --- Posts ---
export const posts = mysqlTable('posts', {
id: char('id', { length: 36 }).notNull().primaryKey(),
title: varchar('title', { length: 255 }),
body: varchar('body', { length: 5000 }),
status: mysqlEnum('status', ['draft', 'published']).notNull().default('draft'),
authorId: char('authorId', { length: 36 }).notNull(),
createdAt: timestamp('createdAt').notNull(),
})
// --- Post Tags (junction table) ---
export const postTags = mysqlTable('post_tags', {
postId: char('postId', { length: 36 }).notNull(),
tagId: char('tagId', { length: 36 }).notNull(),
}, (t) => ({
pk: primaryKey({ columns: [t.postId, t.tagId] }),
}))
// --- Post Media ---
export const postMedia = mysqlTable('post_media', {
id: char('id', { length: 36 }).notNull().primaryKey(),
postId: char('postId', { length: 36 }).notNull(),
url: varchar('url', { length: 1000 }).notNull(),
type: mysqlEnum('type', ['image', 'video']).notNull(),
order: int('order').notNull().default(0),
createdAt: timestamp('createdAt').notNull(),
})