Skip to content
Snippets Groups Projects
Unverified Commit 6e6d7656 authored by Jed Fox's avatar Jed Fox Committed by GitHub
Browse files

Fix migration ID for “remove account type” migration (#1109)

Good catch @Jackenmen in
https://github.com/actualbudget/actual/pull/948#issuecomment-1580501909
— I’ve also added a CI check to ensure bad migrations aren’t introduced
in the future.

I think if you have a budget that has managed to have this migration
applied successfully, you’ll need to manually patch
`getAppliedMigrations` in
`packages/loot-core/src/server/migrate/migrations.ts` and inject a query
to remove the old migration ID and insert the new one.
parent a25327d3
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env node
// overview:
// 1. List all migrations in packages/loot-core/migrations/*
// 2. Check the commit that created the migration file
// 3. Make sure that newer migrations were committed after older migrations (by date in the migration name)
const fs = require('fs');
const path = require('path');
const { spawnSync } = require('child_process');
// Please don’t add to this list, we just can’t change this migration ID since it already happened
const exceptions = ['1679728867040_rules_conditions.sql'];
const migrationsDir = path.join(
__dirname,
'..',
'..',
'packages',
'loot-core',
'migrations',
);
const migrations = fs
.readdirSync(migrationsDir)
.filter(file => !file.startsWith('.'))
.map(file => {
const [_, date] = file.match(/^(\d+)_/) || [];
const { stdout } = spawnSync('git', [
'log',
'--format=%ct',
'-n',
'1',
path.join(migrationsDir, file),
]);
return {
migrationDate: parseInt(date),
commitDate: parseInt(stdout) * 1000,
file,
};
});
const sortedMigrations = migrations.sort(
(a, b) => a.migrationDate - b.migrationDate,
);
let ok = true;
for (let i = sortedMigrations.length - 1; i > 0; i--) {
const migration = sortedMigrations[i];
const prevMigration = sortedMigrations[i - 1];
if (migration.commitDate < prevMigration.commitDate) {
if (exceptions.includes(migration.file)) {
continue;
}
console.error(
`error: migration ${migration.file} was committed before ${prevMigration.file}, but it has a later date in the filename`,
);
ok = false;
}
}
if (ok) {
console.log('All migration IDs are in order');
} else {
console.error(
'\nMigrations must be ordered by date or they will fail to apply properly',
);
process.exit(1);
}
...@@ -32,3 +32,13 @@ jobs: ...@@ -32,3 +32,13 @@ jobs:
uses: ./.github/actions/setup uses: ./.github/actions/setup
- name: Test - name: Test
run: yarn test run: yarn test
migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '19'
- name: Check migrations
run: node ./.github/actions/check-migrations.js
---
category: Bugfix
authors: [j-f1]
---
Fix ID for newly added migration
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment