Files
filezzy-staging/backend/scripts/remove-tool-tier-from-db.ts
2026-02-04 14:16:04 +01:00

45 lines
1.5 KiB
TypeScript

/**
* Remove Tool.tier (and ToolTier enum) from the database without re-seeding.
* Use this when the migration 20260201200000_remove_tool_tier has not been applied
* and you want to drop the column/enum only (e.g. DB content differs from seed).
*
* Run from backend: npm run db:remove-tool-tier
* Or: npx ts-node scripts/remove-tool-tier-from-db.ts
*
* After running, mark the migration as applied so Prisma stays in sync:
* npx prisma migrate resolve --applied 20260201200000_remove_tool_tier
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const STATEMENTS = [
{ name: 'Drop index Tool_category_tier_idx', sql: 'DROP INDEX IF EXISTS "app"."Tool_category_tier_idx";' },
{ name: 'Drop index Tool_tier_idx', sql: 'DROP INDEX IF EXISTS "app"."Tool_tier_idx";' },
{ name: 'Drop column Tool.tier', sql: 'ALTER TABLE "app"."Tool" DROP COLUMN IF EXISTS "tier";' },
{ name: 'Drop enum ToolTier', sql: 'DROP TYPE IF EXISTS "app"."ToolTier";' },
];
async function main() {
console.log('Removing Tool.tier from database (no seed)...\n');
for (const { name, sql } of STATEMENTS) {
try {
await prisma.$executeRawUnsafe(sql);
console.log(' OK:', name);
} catch (e) {
console.error(' FAIL:', name, e);
throw e;
}
}
console.log('\nDone. Tool.tier and ToolTier have been removed. Run prisma generate if needed.');
}
main()
.then(() => process.exit(0))
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());