49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const prisma = new PrismaClient();
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
async function createNotesTable() {
|
|
try {
|
|
// Read migration SQL
|
|
const migrationPath = path.join(__dirname, 'prisma/migrations/20260113_simplify_notes/migration.sql');
|
|
const sql = fs.readFileSync(migrationPath, 'utf8');
|
|
|
|
// Execute SQL (split by semicolons for multiple statements)
|
|
const statements = sql.split(';').filter(s => s.trim().length > 0);
|
|
|
|
for (const statement of statements) {
|
|
if (statement.trim()) {
|
|
try {
|
|
await prisma.$executeRawUnsafe(statement.trim() + ';');
|
|
console.log('✓ Executed statement');
|
|
} catch (error) {
|
|
// Ignore errors for IF EXISTS / IF NOT EXISTS statements
|
|
if (!error.message.includes('already exists') && !error.message.includes('does not exist')) {
|
|
console.error('Error executing statement:', error.message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log('\n✅ Migration completed');
|
|
|
|
// Verify table exists
|
|
const result = await prisma.$queryRaw`
|
|
SELECT column_name, data_type, is_nullable
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'notes'
|
|
ORDER BY ordinal_position
|
|
`;
|
|
console.log('\nNotes table columns:');
|
|
console.log(JSON.stringify(result, null, 2));
|
|
} catch (error) {
|
|
console.error('Error:', error.message);
|
|
console.error(error);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
createNotesTable();
|