42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
/**
|
|
* Dev-only: truncate treatment and lab case data (preserves catalog tables).
|
|
* Usage: npx ts-node prisma/reset-treatment-data.ts
|
|
*/
|
|
import { PrismaClient } from '@prisma/client';
|
|
import { config } from 'dotenv';
|
|
import path from 'path';
|
|
|
|
const envPath = path.join(__dirname, '..', '.env');
|
|
config({ path: envPath });
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
console.error('reset-treatment-data is not allowed in production');
|
|
process.exit(1);
|
|
}
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Truncating treatment and lab case data...');
|
|
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_tasks" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_sends" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_tooth_prosthesis" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_case_details" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "lab_cases" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatment_detail_attachments" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatment_details" CASCADE');
|
|
await prisma.$executeRawUnsafe('TRUNCATE TABLE "treatments" CASCADE');
|
|
|
|
console.log('Done.');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|