task-p.6 migrate

This commit is contained in:
phaichayon
2026-06-30 11:50:50 +07:00
parent b0081c7031
commit 9ab254ef0d
27 changed files with 3170 additions and 32 deletions

View File

@@ -931,6 +931,67 @@ export const crmDocumentTemplateVersions = pgTable(
})
);
export const crmDocumentLibraries = pgTable(
'crm_document_libraries',
{
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
code: text('code').notNull(),
name: text('name').notNull(),
documentType: text('document_type').notNull(),
description: text('description'),
brand: text('brand').notNull(),
language: text('language').notNull(),
productType: text('product_type').notNull(),
status: text('status').default('active').notNull(),
isActive: boolean('is_active').default(true).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
deletedAt: timestamp('deleted_at', { withTimezone: true }),
createdBy: text('created_by').notNull(),
updatedBy: text('updated_by').notNull()
},
(table) => ({
organizationCodeIdx: uniqueIndex('crm_document_libraries_org_code_idx').on(
table.organizationId,
table.code
)
})
);
export const crmDocumentLibraryVersions = pgTable(
'crm_document_library_versions',
{
id: text('id').primaryKey(),
organizationId: text('organization_id').notNull(),
libraryId: text('library_id').notNull(),
version: text('version').notNull(),
fileName: text('file_name').notNull(),
storageProvider: text('storage_provider').notNull(),
storageKey: text('storage_key').notNull(),
mimeType: text('mime_type').notNull(),
fileSize: integer('file_size').notNull(),
checksum: text('checksum').notNull(),
pageCount: integer('page_count').notNull(),
status: text('status').default('draft').notNull(),
isActive: boolean('is_active').default(false).notNull(),
publishedAt: timestamp('published_at', { withTimezone: true }),
publishedBy: text('published_by'),
archivedAt: timestamp('archived_at', { withTimezone: true }),
archivedBy: text('archived_by'),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(),
deletedAt: timestamp('deleted_at', { withTimezone: true }),
createdBy: text('created_by').notNull()
},
(table) => ({
libraryVersionIdx: uniqueIndex('crm_document_library_versions_library_version_idx').on(
table.libraryId,
table.version
)
})
);
export const crmDocumentTemplateMappings = pgTable(
'crm_document_template_mappings',
{