|
| 1 | +import { pgTable, text, integer, boolean } from 'drizzle-orm/pg-core' |
| 2 | +import { users } from './auth' |
| 3 | +import { timestamps, randomId } from './common-fileds' |
| 4 | + |
| 5 | +// Main documents table |
| 6 | +export const documents = pgTable('documents', { |
| 7 | + ...randomId, |
| 8 | + title: text('title').notNull(), |
| 9 | + description: text('description'), |
| 10 | + author_id: text('author_id').references(() => users.id, { |
| 11 | + onDelete: 'set null', |
| 12 | + }), |
| 13 | + is_published: boolean('is_published').notNull().default(false), |
| 14 | + ...timestamps, |
| 15 | +}) |
| 16 | + |
| 17 | +// Text blocks |
| 18 | +export const documentTextBlocks = pgTable('document_text_blocks', { |
| 19 | + ...randomId, |
| 20 | + document_id: text('document_id') |
| 21 | + .notNull() |
| 22 | + .references(() => documents.id, { onDelete: 'cascade' }), |
| 23 | + position: integer('position').notNull(), |
| 24 | + // 'paragraph', 'heading1', 'heading2', 'heading3', 'quote', 'list-item' |
| 25 | + text_type: text('text_type').notNull(), |
| 26 | + content: text('content').notNull(), |
| 27 | + ...timestamps, |
| 28 | +}) |
| 29 | + |
| 30 | +// Media blocks |
| 31 | +export const documentMediaBlocks = pgTable('document_media_blocks', { |
| 32 | + ...randomId, |
| 33 | + document_id: text('document_id') |
| 34 | + .notNull() |
| 35 | + .references(() => documents.id, { onDelete: 'cascade' }), |
| 36 | + position: integer('position').notNull(), |
| 37 | + provider: text('provider').notNull(), // 'youtube', 'vimeo', 'dailymotion', 'image', 'audio', 'video' |
| 38 | + url: text('url').notNull(), |
| 39 | + id: text('id').notNull(), |
| 40 | + title: text('title'), |
| 41 | + ...timestamps, |
| 42 | +}) |
0 commit comments