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
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:
@@ -4,8 +4,8 @@ const { generateReadablePassword } = require('../../src/utils/passwordGenerator'
|
|||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
async function runMigrations() {
|
exports.up = async function(knex) {
|
||||||
console.log('Running database migrations...');
|
console.log('Initializing database schema...');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Initialize tables
|
// Initialize tables
|
||||||
@@ -116,11 +116,13 @@ Generated on: ${new Date().toISOString()}
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Migrations completed successfully');
|
console.log('Migrations completed successfully');
|
||||||
process.exit(0);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Migration failed:', error);
|
console.error('Initial setup failed:', error);
|
||||||
process.exit(1);
|
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]);
|
const numB = parseInt(baseB.split('_')[0]);
|
||||||
return numA - numB;
|
return numA - numB;
|
||||||
});
|
});
|
||||||
|
console.log('Migration files in order:', migrationFiles.map(f => path.basename(f)));
|
||||||
} else {
|
} else {
|
||||||
// For existing deployments, run all migrations (legacy + core)
|
// For existing deployments, run all migrations (legacy + core)
|
||||||
console.log('Existing deployment detected - checking all migrations');
|
console.log('Existing deployment detected - checking all migrations');
|
||||||
|
|||||||
Reference in New Issue
Block a user