Fix migration sorting to use numeric comparison
Mirror to GitHub / mirror (push) Successful in 24s
Test and Lint / backend-test (push) Successful in 1m27s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m4s
Version and Release / version-bump (push) Failing after 39s
Version and Release / trigger-drone (push) Has been skipped

- Changed from string sort to numeric sort for migration files
- String sort was causing '029' to run before '001'
- Now properly extracts and compares numeric prefixes
- Applied fix to both run-migrations.js and run-migrations-safe.js

This ensures 001_init.js runs first and creates all necessary tables
before other migrations try to use them.
This commit is contained in:
2025-07-25 12:51:54 +02:00
parent ba2c021c45
commit 4e052966d3
2 changed files with 14 additions and 2 deletions
+7 -1
View File
@@ -134,7 +134,13 @@ async function runMigrations() {
migrationFiles = coreFiles migrationFiles = coreFiles
.filter(f => f.match(/^\d{3}_.*\.js$/)) .filter(f => f.match(/^\d{3}_.*\.js$/))
.map(f => path.join('core', f)) .map(f => path.join('core', f))
.sort(); .sort((a, b) => {
const baseA = path.basename(a);
const baseB = path.basename(b);
const numA = parseInt(baseA.split('_')[0]);
const numB = parseInt(baseB.split('_')[0]);
return numA - numB;
});
} 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');
+7 -1
View File
@@ -68,7 +68,13 @@ async function runMigrations() {
migrationFiles = coreFiles migrationFiles = coreFiles
.filter(f => f.match(/^\d{3}_.*\.js$/)) .filter(f => f.match(/^\d{3}_.*\.js$/))
.map(f => path.join('core', f)) .map(f => path.join('core', f))
.sort(); .sort((a, b) => {
const baseA = path.basename(a);
const baseB = path.basename(b);
const numA = parseInt(baseA.split('_')[0]);
const numB = parseInt(baseB.split('_')[0]);
return numA - numB;
});
} 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');