Add migration script for applying parent category support
Created scripts/apply-migration.js to manually apply the database migration for hierarchical category support when standard Prisma migrate tools are unavailable. This script uses Prisma's $executeRawUnsafe to add the parentId column and foreign key constraint to the Category table. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
da0a65cf26
commit
396dbb93f0
@@ -0,0 +1,34 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log('Applying migration...');
|
||||
|
||||
// Add parentId column if it doesn't exist
|
||||
await prisma.$executeRawUnsafe(`
|
||||
ALTER TABLE "Category" ADD COLUMN "parentId" TEXT;
|
||||
`).catch(() => {
|
||||
console.log('Column parentId already exists or has an issue');
|
||||
});
|
||||
|
||||
// Add foreign key constraint if it doesn't exist
|
||||
await prisma.$executeRawUnsafe(`
|
||||
ALTER TABLE "Category" ADD CONSTRAINT "Category_parentId_fkey"
|
||||
FOREIGN KEY ("parentId") REFERENCES "Category"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
`).catch(() => {
|
||||
console.log('Foreign key already exists or has an issue');
|
||||
});
|
||||
|
||||
console.log('Migration applied successfully!');
|
||||
} catch (error) {
|
||||
console.error('Error applying migration:', error);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user