mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added erroring migrations to the final minor of deleted majors
refs https://github.com/TryGhost/Toolbox/issues/300 - the previous commit deleted all v1/v2/v3 migrations - Ghost-CLI forces you to update to the latest minor in your major before you upgrade but people who aren't on the latest minor, who don't use Ghost-CLI and try to update to v5 might have missed migrations that I've just deleted - the way to protect against this is to add some migrations for the last minor in each major, that will throw an error if they get run - this uses a feature of knex-migrator where it will always try to backfill missing migrations when you run Ghost, so these new migrations should _only_ be run if the Ghost DB hasn't already run the same number of migrations in that minor - by throwing an error, it'll cause knex-migrator to fail and the user shouldn't be able to update, which is good - v2 and v3 only have 1 migration so I can just replace that, but v1 has 2 migrations. I think it makes more sense that the first one errors and the second one is a no-op otherwise it'll run the first migration, succeed, run the second, error, and then rollback the second and first one - the new migration names are different from the original ones but that shouldn't matter because we're not comparing nor storing them
This commit is contained in:
parent
145dc4651a
commit
b788604e15
5 changed files with 30 additions and 0 deletions
|
@ -528,6 +528,23 @@ function addSetting({key, value, type, group}) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} major
|
||||||
|
*/
|
||||||
|
function createFinalMigration(major) {
|
||||||
|
return createTransactionalMigration(
|
||||||
|
async function up() {
|
||||||
|
throw new errors.InternalServerError({
|
||||||
|
message: `Unable to run migrations`,
|
||||||
|
context: `You must be on the latest v${major}.x to update across major versions - https://ghost.org/docs/update/`,
|
||||||
|
help: `Run 'ghost update v${major}' to get the latest v${major}.x version, then run 'ghost update' to get to the latest.`
|
||||||
|
});
|
||||||
|
},
|
||||||
|
async function down() {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addTable,
|
addTable,
|
||||||
dropTables,
|
dropTables,
|
||||||
|
@ -536,6 +553,7 @@ module.exports = {
|
||||||
addPermissionToRole,
|
addPermissionToRole,
|
||||||
addPermissionWithRoles,
|
addPermissionWithRoles,
|
||||||
addSetting,
|
addSetting,
|
||||||
|
createFinalMigration,
|
||||||
createTransactionalMigration,
|
createTransactionalMigration,
|
||||||
createNonTransactionalMigration,
|
createNonTransactionalMigration,
|
||||||
createIrreversibleMigration,
|
createIrreversibleMigration,
|
||||||
|
|
2
core/server/data/migrations/versions/1.25/01-final-v1.js
Normal file
2
core/server/data/migrations/versions/1.25/01-final-v1.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const {createFinalMigration} = require('../../utils');
|
||||||
|
module.exports = createFinalMigration(1);
|
6
core/server/data/migrations/versions/1.25/02-noop.js
Normal file
6
core/server/data/migrations/versions/1.25/02-noop.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
const {createTransactionalMigration} = require('../../utils');
|
||||||
|
|
||||||
|
module.exports = createTransactionalMigration(
|
||||||
|
async function up() {},
|
||||||
|
async function down() {}
|
||||||
|
);
|
2
core/server/data/migrations/versions/2.37/01-final-v2.js
Normal file
2
core/server/data/migrations/versions/2.37/01-final-v2.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const {createFinalMigration} = require('../../utils');
|
||||||
|
module.exports = createFinalMigration(2);
|
2
core/server/data/migrations/versions/3.41/01-final-v3.js
Normal file
2
core/server/data/migrations/versions/3.41/01-final-v3.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
const {createFinalMigration} = require('../../utils');
|
||||||
|
module.exports = createFinalMigration(3);
|
Loading…
Add table
Reference in a new issue