27 lines
965 B
TypeScript
27 lines
965 B
TypeScript
/**
|
||
* 工具方法:确保 system_settings 表的可选列已创建
|
||
* 兼容旧版本数据库缺少 enabledBuiltinTemplates / categoryManagedFields 的情况
|
||
*/
|
||
|
||
import { prisma } from '@/lib/prisma'
|
||
|
||
async function addColumnIfMissing(column: string, type = 'TEXT', defaultValue?: string) {
|
||
try {
|
||
const defaultClause = defaultValue ? ` DEFAULT ${defaultValue}` : ''
|
||
await prisma.$executeRawUnsafe(
|
||
`ALTER TABLE "system_settings" ADD COLUMN IF NOT EXISTS "${column}" ${type}${defaultClause}`
|
||
)
|
||
} catch (error) {
|
||
console.error(`[SystemSettings] Failed to ensure column ${column}:`, error)
|
||
}
|
||
}
|
||
|
||
export async function ensureSystemSettingsOptionalColumns() {
|
||
await addColumnIfMissing('enabledBuiltinTemplates')
|
||
await addColumnIfMissing('categoryManagedFields')
|
||
// 首页删除按钮模式:ADMIN_ONLY / ALL
|
||
await addColumnIfMissing('homeDeleteButtonMode')
|
||
await addColumnIfMissing('premiumRatio', 'DOUBLE PRECISION', '10')
|
||
}
|
||
|