initial commit
This commit is contained in:
58
scripts/migrate-new-modules.js
Normal file
58
scripts/migrate-new-modules.js
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Migration runner for new module tables.
|
||||
* Run from project root: node scripts/migrate-new-modules.js
|
||||
*
|
||||
* Alternative: npx prisma db push (which reads from schema.prisma)
|
||||
*/
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
try {
|
||||
console.log('Connecting to database...');
|
||||
await prisma.$connect();
|
||||
console.log('Connected.');
|
||||
|
||||
const sqlPath = path.join(__dirname, '..', 'prisma', 'migrations', 'add_new_modules', 'migration.sql');
|
||||
const sql = fs.readFileSync(sqlPath, 'utf-8');
|
||||
|
||||
// Split by semicolons and execute each statement
|
||||
const statements = sql
|
||||
.split(';')
|
||||
.map(s => s.trim())
|
||||
.filter(s => s.length > 0 && !s.startsWith('--'));
|
||||
|
||||
console.log(`Executing ${statements.length} SQL statements...`);
|
||||
|
||||
for (let i = 0; i < statements.length; i++) {
|
||||
const stmt = statements[i];
|
||||
try {
|
||||
await prisma.$executeRawUnsafe(stmt);
|
||||
console.log(` [${i + 1}/${statements.length}] OK`);
|
||||
} catch (err) {
|
||||
// Ignore "already exists" errors
|
||||
if (err.message.includes('already exists')) {
|
||||
console.log(` [${i + 1}/${statements.length}] Already exists (skipped)`);
|
||||
} else {
|
||||
console.error(` [${i + 1}/${statements.length}] ERROR: ${err.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\nMigration complete!');
|
||||
console.log('Next step: run "npx prisma generate" to update the Prisma client types.');
|
||||
|
||||
} catch (err) {
|
||||
console.error('Migration failed:', err.message);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user