Fix 001_init.js to follow proper migration pattern
Mirror to GitHub / mirror (push) Successful in 24s
Test and Lint / backend-test (push) Successful in 1m39s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m0s
Version and Release / version-bump (push) Successful in 33s
Version and Release / trigger-drone (push) Has been skipped

- Changed from standalone script to proper migration with exports.up/down
- Removed process.exit() calls that were terminating the migration runner
- Removed immediate execution of runMigrations()
- Now properly exports migration functions like other migrations

This was the root cause - 001_init.js was executing immediately when
required and calling process.exit(), preventing it from being run as
a migration and causing 029 to run first on an empty database.
This commit is contained in:
2025-07-25 13:00:03 +02:00
parent 4e052966d3
commit ccf59d1d4d
2 changed files with 10 additions and 7 deletions
+9 -7
View File
@@ -4,8 +4,8 @@ const { generateReadablePassword } = require('../../src/utils/passwordGenerator'
const fs = require('fs').promises;
const path = require('path');
async function runMigrations() {
console.log('Running database migrations...');
exports.up = async function(knex) {
console.log('Initializing database schema...');
try {
// Initialize tables
@@ -116,11 +116,13 @@ Generated on: ${new Date().toISOString()}
}
console.log('Migrations completed successfully');
process.exit(0);
} catch (error) {
console.error('Migration failed:', error);
process.exit(1);
}
console.error('Initial setup failed:', error);
throw error;
}
};
runMigrations();
exports.down = async function(knex) {
// This migration cannot be rolled back as it creates the initial schema
console.log('Initial setup cannot be rolled back');
};
@@ -141,6 +141,7 @@ async function runMigrations() {
const numB = parseInt(baseB.split('_')[0]);
return numA - numB;
});
console.log('Migration files in order:', migrationFiles.map(f => path.basename(f)));
} else {
// For existing deployments, run all migrations (legacy + core)
console.log('Existing deployment detected - checking all migrations');