mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
No-op'd post.page->post.type migrations, added cleanup post.type->post.page migrations
This commit is contained in:
parent
9c46ff154d
commit
3764e023fb
7 changed files with 209 additions and 184 deletions
|
@ -1,44 +1,6 @@
|
||||||
const common = require('../../../../lib/common');
|
const Promise = require('bluebird');
|
||||||
const commands = require('../../../schema').commands;
|
|
||||||
|
|
||||||
const createLog = type => msg => common.logging[type](msg);
|
// adding/removing columns is too slow for a minor release
|
||||||
|
// noop'd, will be re-introduced in Ghost 3.0
|
||||||
function createColumnMigration({table, column, dbIsInCorrectState, operation, operationVerb}) {
|
module.exports.up = () => Promise.resolve();
|
||||||
return function columnMigrations({transacting}) {
|
module.exports.down = () => Promise.resolve();
|
||||||
return transacting.schema.hasColumn(table, column)
|
|
||||||
.then(dbIsInCorrectState)
|
|
||||||
.then((isInCorrectState) => {
|
|
||||||
const log = createLog(isInCorrectState ? 'warn' : 'info');
|
|
||||||
|
|
||||||
log(`${operationVerb} ${table}.${column}`);
|
|
||||||
|
|
||||||
if (!isInCorrectState) {
|
|
||||||
return operation(table, column, transacting);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.up = createColumnMigration({
|
|
||||||
table: 'posts',
|
|
||||||
column: 'type',
|
|
||||||
dbIsInCorrectState(columnExists) {
|
|
||||||
return columnExists === true;
|
|
||||||
},
|
|
||||||
operation: commands.addColumn,
|
|
||||||
operationVerb: 'Adding'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports.down = createColumnMigration({
|
|
||||||
table: 'posts',
|
|
||||||
column: 'type',
|
|
||||||
dbIsInCorrectState(columnExists) {
|
|
||||||
return columnExists === false;
|
|
||||||
},
|
|
||||||
operation: commands.dropColumn,
|
|
||||||
operationVerb: 'Removing'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports.config = {
|
|
||||||
transaction: true
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,94 +1,6 @@
|
||||||
const Promise = require('bluebird');
|
const Promise = require('bluebird');
|
||||||
const toPairs = require('lodash/toPairs');
|
|
||||||
const common = require('../../../../lib/common');
|
|
||||||
|
|
||||||
/*
|
// adding/removing columns is too slow for a minor release
|
||||||
* @param from: object with a SINGLE entry { 'fromColumn': 'fromValue' }
|
// noop'd, will be re-introduced in Ghost 3.0
|
||||||
* @param to: object with a SINGLE entry { 'toColumn': 'toValue' }
|
module.exports.up = () => Promise.resolve();
|
||||||
*/
|
module.exports.down = () => Promise.resolve();
|
||||||
const createColumnToColumnMap = ({from, to, tableName}) => (connection) => {
|
|
||||||
return connection.schema.hasTable(tableName)
|
|
||||||
.then((tableExists) => {
|
|
||||||
if (!tableExists) {
|
|
||||||
common.logging.warn(
|
|
||||||
`Table ${tableName} does not exist`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [fromColumn, fromValue] = toPairs(from)[0];
|
|
||||||
const [toColumn, toValue] = toPairs(to)[0];
|
|
||||||
|
|
||||||
return Promise.all([
|
|
||||||
connection.schema.hasColumn(tableName, fromColumn),
|
|
||||||
connection.schema.hasColumn(tableName, toColumn)
|
|
||||||
]).then(([fromColumnExists, toColumnExists]) => {
|
|
||||||
if (!fromColumnExists) {
|
|
||||||
common.logging.warn(
|
|
||||||
`Table '${tableName}' does not have column '${fromColumn}'`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!toColumnExists) {
|
|
||||||
common.logging.warn(
|
|
||||||
`Table '${tableName}' does not have column '${toColumn}'`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!fromColumnExists || !toColumnExists) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
common.logging.info(
|
|
||||||
`Updating ${tableName}, setting "${toColumn}" column to "${toValue}" where "${fromColumn}" column is "${fromValue}"`
|
|
||||||
);
|
|
||||||
|
|
||||||
return connection(tableName)
|
|
||||||
.where(fromColumn, fromValue)
|
|
||||||
.update(toColumn, toValue);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const createColumnToColumnMigration = ({tableName, from, to}) => {
|
|
||||||
return {
|
|
||||||
up: createColumnToColumnMap({from, to, tableName}),
|
|
||||||
down: createColumnToColumnMap({from: to, to: from, tableName})
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const pageColumnToPageType = createColumnToColumnMigration({
|
|
||||||
tableName: 'posts',
|
|
||||||
from: {
|
|
||||||
page: true
|
|
||||||
},
|
|
||||||
to: {
|
|
||||||
type: 'page'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const pageColumnToPostType = createColumnToColumnMigration({
|
|
||||||
tableName: 'posts',
|
|
||||||
from: {
|
|
||||||
page: false
|
|
||||||
},
|
|
||||||
to: {
|
|
||||||
type: 'post'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports.up = ({transacting}) => {
|
|
||||||
return Promise.all([
|
|
||||||
pageColumnToPageType.up(transacting),
|
|
||||||
pageColumnToPostType.up(transacting)
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.down = ({transacting}) => {
|
|
||||||
return Promise.all([
|
|
||||||
pageColumnToPageType.down(transacting),
|
|
||||||
pageColumnToPostType.down(transacting)
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports.config = {
|
|
||||||
transaction: true
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,49 +1,6 @@
|
||||||
const common = require('../../../../lib/common');
|
const Promise = require('bluebird');
|
||||||
const commands = require('../../../schema').commands;
|
|
||||||
|
|
||||||
const createLog = type => msg => common.logging[type](msg);
|
// adding/removing columns is too slow for a minor release
|
||||||
|
// noop'd, will be re-introduced in Ghost 3.0
|
||||||
function createColumnMigration({table, column, dbIsInCorrectState, operation, operationVerb, columnDefinition}) {
|
module.exports.up = () => Promise.resolve();
|
||||||
return function columnMigrations({transacting}) {
|
module.exports.down = () => Promise.resolve();
|
||||||
return transacting.schema.hasColumn(table, column)
|
|
||||||
.then(dbIsInCorrectState)
|
|
||||||
.then((isInCorrectState) => {
|
|
||||||
const log = createLog(isInCorrectState ? 'warn' : 'info');
|
|
||||||
|
|
||||||
log(`${operationVerb} ${table}.${column}`);
|
|
||||||
|
|
||||||
if (!isInCorrectState) {
|
|
||||||
return operation(table, column, transacting, columnDefinition);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.up = createColumnMigration({
|
|
||||||
table: 'posts',
|
|
||||||
column: 'page',
|
|
||||||
dbIsInCorrectState(columnExists) {
|
|
||||||
return columnExists === false;
|
|
||||||
},
|
|
||||||
operation: commands.dropColumn,
|
|
||||||
operationVerb: 'Removing'
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports.down = createColumnMigration({
|
|
||||||
table: 'posts',
|
|
||||||
column: 'page',
|
|
||||||
dbIsInCorrectState(columnExists) {
|
|
||||||
return columnExists === true;
|
|
||||||
},
|
|
||||||
operation: commands.addColumn,
|
|
||||||
operationVerb: 'Adding',
|
|
||||||
columnDefinition: {
|
|
||||||
type: 'bool',
|
|
||||||
nullable: false,
|
|
||||||
defaultTo: false
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports.config = {
|
|
||||||
transaction: true
|
|
||||||
};
|
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
const common = require('../../../../lib/common');
|
||||||
|
const commands = require('../../../schema').commands;
|
||||||
|
|
||||||
|
const createLog = type => msg => common.logging[type](msg);
|
||||||
|
|
||||||
|
function createColumnMigration({table, column, dbIsInCorrectState, operation, operationVerb}) {
|
||||||
|
return function columnMigrations({transacting}) {
|
||||||
|
return transacting.schema.hasColumn(table, column)
|
||||||
|
.then(dbIsInCorrectState)
|
||||||
|
.then((isInCorrectState) => {
|
||||||
|
const log = createLog(isInCorrectState ? 'warn' : 'info');
|
||||||
|
|
||||||
|
log(`${operationVerb} ${table}.${column}`);
|
||||||
|
|
||||||
|
if (!isInCorrectState) {
|
||||||
|
return operation(table, column, transacting);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.up = function (options) {
|
||||||
|
return options.transacting.schema.hasColumn('posts', 'type').then((hasTypeColumn) => {
|
||||||
|
if (!hasTypeColumn) {
|
||||||
|
// no-op'd post.page->post.type migrations were never run
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createColumnMigration({
|
||||||
|
table: 'posts',
|
||||||
|
column: 'page',
|
||||||
|
dbIsInCorrectState(columnExists) {
|
||||||
|
return columnExists === true;
|
||||||
|
},
|
||||||
|
operation: commands.addColumn,
|
||||||
|
operationVerb: 'Adding'
|
||||||
|
})(options);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// `up` only runs in order to fix a previous migration so we don't want to do
|
||||||
|
// anything in `down` because it would put previously-fine sites into the wrong
|
||||||
|
// state
|
||||||
|
module.exports.down = () => Promise.resolve();
|
||||||
|
|
||||||
|
module.exports.config = {
|
||||||
|
transaction: true
|
||||||
|
};
|
|
@ -0,0 +1,98 @@
|
||||||
|
const toPairs = require('lodash/toPairs');
|
||||||
|
const common = require('../../../../lib/common');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @param from: object with a SINGLE entry { 'fromColumn': 'fromValue' }
|
||||||
|
* @param to: object with a SINGLE entry { 'toColumn': 'toValue' }
|
||||||
|
*/
|
||||||
|
const createColumnToColumnMap = ({from, to, tableName}) => (connection) => {
|
||||||
|
return connection.schema.hasTable(tableName)
|
||||||
|
.then((tableExists) => {
|
||||||
|
if (!tableExists) {
|
||||||
|
common.logging.warn(
|
||||||
|
`Table ${tableName} does not exist`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [fromColumn, fromValue] = toPairs(from)[0];
|
||||||
|
const [toColumn, toValue] = toPairs(to)[0];
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
connection.schema.hasColumn(tableName, fromColumn),
|
||||||
|
connection.schema.hasColumn(tableName, toColumn)
|
||||||
|
]).then(([fromColumnExists, toColumnExists]) => {
|
||||||
|
if (!fromColumnExists) {
|
||||||
|
common.logging.warn(
|
||||||
|
`Table '${tableName}' does not have column '${fromColumn}'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!toColumnExists) {
|
||||||
|
common.logging.warn(
|
||||||
|
`Table '${tableName}' does not have column '${toColumn}'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!fromColumnExists || !toColumnExists) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
common.logging.info(
|
||||||
|
`Updating ${tableName}, setting "${toColumn}" column to "${toValue}" where "${fromColumn}" column is "${fromValue}"`
|
||||||
|
);
|
||||||
|
|
||||||
|
return connection(tableName)
|
||||||
|
.where(fromColumn, fromValue)
|
||||||
|
.update(toColumn, toValue);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const createColumnToColumnMigration = ({tableName, from, to}) => {
|
||||||
|
return {
|
||||||
|
up: createColumnToColumnMap({from, to, tableName}),
|
||||||
|
down: createColumnToColumnMap({from: to, to: from, tableName})
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const typeColumnToPageTrue = createColumnToColumnMigration({
|
||||||
|
tableName: 'posts',
|
||||||
|
from: {
|
||||||
|
type: 'page'
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
page: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const typeColumnToPageFalse = createColumnToColumnMigration({
|
||||||
|
tableName: 'posts',
|
||||||
|
from: {
|
||||||
|
type: 'post'
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
page: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports.up = ({transacting}) => {
|
||||||
|
return transacting.schema.hasColumn('posts', 'type').then((hasTypeColumn) => {
|
||||||
|
if (!hasTypeColumn) {
|
||||||
|
// no-op'd post.page->post.type migrations were never run
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all([
|
||||||
|
typeColumnToPageTrue.up(transacting),
|
||||||
|
typeColumnToPageFalse.up(transacting)
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// `up` only runs in order to fix a previous migration so we don't want to do
|
||||||
|
// anything in `down` because it would put previously-fine sites into the wrong
|
||||||
|
// state
|
||||||
|
module.exports.down = () => Promise.resolve();
|
||||||
|
|
||||||
|
module.exports.config = {
|
||||||
|
transaction: true
|
||||||
|
};
|
|
@ -0,0 +1,48 @@
|
||||||
|
const common = require('../../../../lib/common');
|
||||||
|
const commands = require('../../../schema').commands;
|
||||||
|
|
||||||
|
const createLog = type => msg => common.logging[type](msg);
|
||||||
|
|
||||||
|
function createColumnMigration({table, column, dbIsInCorrectState, operation, operationVerb, columnDefinition}) {
|
||||||
|
return function columnMigrations({transacting}) {
|
||||||
|
return transacting.schema.hasColumn(table, column)
|
||||||
|
.then(dbIsInCorrectState)
|
||||||
|
.then((isInCorrectState) => {
|
||||||
|
const log = createLog(isInCorrectState ? 'warn' : 'info');
|
||||||
|
|
||||||
|
log(`${operationVerb} ${table}.${column}`);
|
||||||
|
|
||||||
|
if (!isInCorrectState) {
|
||||||
|
return operation(table, column, transacting, columnDefinition);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.up = function (options) {
|
||||||
|
return options.transacting.schema.hasColumn('posts', 'type').then((hasTypeColumn) => {
|
||||||
|
if (!hasTypeColumn) {
|
||||||
|
// no-op'd post.page->post.type migrations were never run
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return createColumnMigration({
|
||||||
|
table: 'posts',
|
||||||
|
column: 'type',
|
||||||
|
dbIsInCorrectState(columnExists) {
|
||||||
|
return columnExists === false;
|
||||||
|
},
|
||||||
|
operation: commands.dropColumn,
|
||||||
|
operationVerb: 'Removing'
|
||||||
|
})(options);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// `up` only runs in order to fix a previous migration so we don't want to do
|
||||||
|
// anything in `down` because it would put previously-fine sites into the wrong
|
||||||
|
// state
|
||||||
|
module.exports.down = () => Promise.resolve();
|
||||||
|
|
||||||
|
module.exports.config = {
|
||||||
|
transaction: true
|
||||||
|
};
|
|
@ -19,7 +19,7 @@ module.exports = {
|
||||||
plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
|
plaintext: {type: 'text', maxlength: 1000000000, fieldtype: 'long', nullable: true},
|
||||||
feature_image: {type: 'string', maxlength: 2000, nullable: true},
|
feature_image: {type: 'string', maxlength: 2000, nullable: true},
|
||||||
featured: {type: 'bool', nullable: false, defaultTo: false},
|
featured: {type: 'bool', nullable: false, defaultTo: false},
|
||||||
type: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'post', validations: {isIn: [['post', 'page']]}},
|
page: {type: 'bool', nullable: false, defaultTo: false},
|
||||||
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'draft'},
|
status: {type: 'string', maxlength: 50, nullable: false, defaultTo: 'draft'},
|
||||||
locale: {type: 'string', maxlength: 6, nullable: true},
|
locale: {type: 'string', maxlength: 6, nullable: true},
|
||||||
visibility: {
|
visibility: {
|
||||||
|
|
Loading…
Reference in a new issue