64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
|
|
/**
|
|||
|
|
* 删除 AI 相关数据库表
|
|||
|
|
* 直接执行 SQL,不通过 Prisma 迁移
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import { PrismaClient } from '@prisma/client';
|
|||
|
|
import dotenv from 'dotenv';
|
|||
|
|
|
|||
|
|
dotenv.config();
|
|||
|
|
|
|||
|
|
const prisma = new PrismaClient();
|
|||
|
|
|
|||
|
|
async function deleteAITables() {
|
|||
|
|
try {
|
|||
|
|
console.log('🗑️ 开始删除 AI 相关表...');
|
|||
|
|
|
|||
|
|
// 删除表(按依赖顺序)
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
DROP TABLE IF EXISTS "document_chunks" CASCADE;
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 document_chunks 表');
|
|||
|
|
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
DROP TABLE IF EXISTS "ai_prompt_logs" CASCADE;
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 ai_prompt_logs 表');
|
|||
|
|
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
DROP TABLE IF EXISTS "ai_prompt_configs" CASCADE;
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 ai_prompt_configs 表');
|
|||
|
|
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
DROP TABLE IF EXISTS "ai_content_tasks" CASCADE;
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 ai_content_tasks 表');
|
|||
|
|
|
|||
|
|
// 删除 Course 表中的 AI 相关字段
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
ALTER TABLE "courses" DROP COLUMN IF EXISTS "generation_status";
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 courses.generation_status 字段');
|
|||
|
|
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
ALTER TABLE "courses" DROP COLUMN IF EXISTS "generation_progress";
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 courses.generation_progress 字段');
|
|||
|
|
|
|||
|
|
await prisma.$executeRawUnsafe(`
|
|||
|
|
ALTER TABLE "courses" DROP COLUMN IF EXISTS "ai_content_task_id";
|
|||
|
|
`);
|
|||
|
|
console.log('✅ 已删除 courses.ai_content_task_id 字段');
|
|||
|
|
|
|||
|
|
console.log('✅ 所有 AI 相关表已删除!');
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('❌ 删除失败:', error);
|
|||
|
|
throw error;
|
|||
|
|
} finally {
|
|||
|
|
await prisma.$disconnect();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
deleteAITables();
|