mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Refactored column migrations to use helpers (#12360)
- these helpers remove a lot of the duplicated code that we had when doing up/down column migrations, and provides a much shorter way of doing this in the future
This commit is contained in:
parent
02d78a89aa
commit
33bc3c9011
27 changed files with 306 additions and 1051 deletions
|
@ -266,6 +266,89 @@ function combineTransactionalMigrations(...migrations) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Migration[]} migrations
|
||||
*
|
||||
* @returns {Migration}
|
||||
*/
|
||||
function combineNonTransactionalMigrations(...migrations) {
|
||||
return {
|
||||
config: {
|
||||
transaction: false
|
||||
},
|
||||
async up(config) {
|
||||
for (const migration of migrations) {
|
||||
await migration.up(config);
|
||||
}
|
||||
},
|
||||
async down(config) {
|
||||
// Down migrations must be run backwards!!
|
||||
const reverseMigrations = migrations.slice().reverse();
|
||||
for (const migration of reverseMigrations) {
|
||||
await migration.down(config);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} table
|
||||
* @param {string} column
|
||||
* @param {Object} columnDefinition
|
||||
*
|
||||
* @returns {Migration}
|
||||
*/
|
||||
function createAddColumnMigration(table, column, columnDefinition) {
|
||||
return createNonTransactionalMigration(
|
||||
// up
|
||||
commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState: hasColumn => hasColumn === true,
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition
|
||||
}),
|
||||
// down
|
||||
commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} table
|
||||
* @param {string} column
|
||||
* @param {Object} columnDefinition
|
||||
*
|
||||
* @returns {Migration}
|
||||
*/
|
||||
function createDropColumnMigration(table, column, columnDefinition) {
|
||||
return createNonTransactionalMigration(
|
||||
// up
|
||||
commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
}),
|
||||
// down
|
||||
commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState: hasColumn => hasColumn === true,
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
addTable,
|
||||
addPermission,
|
||||
|
@ -274,6 +357,9 @@ module.exports = {
|
|||
createTransactionalMigration,
|
||||
createNonTransactionalMigration,
|
||||
combineTransactionalMigrations,
|
||||
combineNonTransactionalMigrations,
|
||||
createAddColumnMigration,
|
||||
createDropColumnMigration,
|
||||
meta: {
|
||||
MIGRATION_USER
|
||||
}
|
||||
|
|
|
@ -1,56 +1,20 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createNonTransactionalMigration} = require('../../utils');
|
||||
const commands = require('../../../schema/commands');
|
||||
|
||||
const createLog = type => msg => 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) {
|
||||
// has to be passed directly in case of migration to 3.0
|
||||
// ref: https://github.com/TryGhost/Ghost/commit/9d7190d69255ac011848c6bf654886be81abeedc#diff-c20cac44dad77922cf53ffd7b094cd8cL22
|
||||
const columnSpec = {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
};
|
||||
|
||||
return operation(table, column, transacting, columnSpec);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
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();
|
||||
module.exports = createNonTransactionalMigration(
|
||||
commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'page',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}),
|
||||
() => Promise.resolve()
|
||||
);
|
||||
|
|
|
@ -1,48 +1,15 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createNonTransactionalMigration} = require('../../utils');
|
||||
const commands = require('../../../schema/commands');
|
||||
|
||||
const createLog = type => msg => 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
|
||||
};
|
||||
module.exports = createNonTransactionalMigration(
|
||||
commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'type',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
}),
|
||||
() => Promise.resolve()
|
||||
);
|
||||
|
|
|
@ -1,55 +1,15 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {combineNonTransactionalMigrations, createDropColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'password',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
}, {
|
||||
table: 'members',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createDropColumnMigration('members', 'password', {
|
||||
type: 'string',
|
||||
maxlength: 60,
|
||||
nullable: true
|
||||
}),
|
||||
|
||||
down: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'password',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
maxlength: 60,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
table: 'members',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: false,
|
||||
defaultTo: ''
|
||||
}
|
||||
}),
|
||||
|
||||
config: {
|
||||
transaction: true
|
||||
}
|
||||
};
|
||||
createDropColumnMigration('members', 'name', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: false,
|
||||
defaultTo: ''
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
}),
|
||||
|
||||
down: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
}),
|
||||
|
||||
config: {
|
||||
transaction: true
|
||||
}
|
||||
};
|
||||
module.exports = createAddColumnMigration('members', 'name', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: true
|
||||
});
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: commands.createColumnMigration({
|
||||
table: 'members_stripe_customers',
|
||||
column: 'email',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
}),
|
||||
|
||||
down: commands.createColumnMigration({
|
||||
table: 'members_stripe_customers',
|
||||
column: 'email',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
}),
|
||||
|
||||
config: {
|
||||
transaction: true
|
||||
}
|
||||
};
|
||||
module.exports = createAddColumnMigration('members_stripe_customers', 'email', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: true
|
||||
});
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: commands.createColumnMigration({
|
||||
table: 'members_stripe_customers',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
}),
|
||||
|
||||
down: commands.createColumnMigration({
|
||||
table: 'members_stripe_customers',
|
||||
column: 'name',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
}),
|
||||
|
||||
config: {
|
||||
transaction: true
|
||||
}
|
||||
};
|
||||
module.exports = createAddColumnMigration('members_stripe_customers', 'name', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: true
|
||||
});
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
|
||||
up: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'note',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
}),
|
||||
|
||||
down: commands.createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'note',
|
||||
dbIsInCorrectState(hasColumn) {
|
||||
return hasColumn === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
}),
|
||||
|
||||
config: {
|
||||
transaction: true
|
||||
}
|
||||
};
|
||||
module.exports = createAddColumnMigration('members', 'note', {
|
||||
type: 'string',
|
||||
maxlength: 2000,
|
||||
nullable: true
|
||||
});
|
||||
|
|
|
@ -1,79 +1,14 @@
|
|||
const Promise = require('bluebird');
|
||||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {combineNonTransactionalMigrations, createDropColumnMigration} = require('../../utils');
|
||||
|
||||
const createLog = type => msg => logging[type](msg);
|
||||
|
||||
function createColumnMigrations(migrations) {
|
||||
return function columnMigrations({transacting}) {
|
||||
return Promise.each(migrations, function ({table, column, dbIsInCorrectState, operation, operationVerb, columnDefinition}) {
|
||||
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 = createColumnMigrations([
|
||||
{
|
||||
table: 'users',
|
||||
column: 'ghost_auth_access_token',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
},
|
||||
{
|
||||
table: 'users',
|
||||
column: 'ghost_auth_id',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
}
|
||||
]);
|
||||
|
||||
module.exports.down = createColumnMigrations([
|
||||
{
|
||||
table: 'users',
|
||||
column: 'ghost_auth_access_token',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 32
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'users',
|
||||
column: 'ghost_auth_id',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 24
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createDropColumnMigration('users', 'ghost_auth_access_token', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 32
|
||||
}),
|
||||
createDropColumnMigration('users', 'ghost_auth_id', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 24
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,191 +1,44 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {combineNonTransactionalMigrations, createDropColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'meta_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'meta_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_image',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_image',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Dropping'
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'meta_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createDropColumnMigration('posts', 'meta_title', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 2000
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'meta_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'meta_description', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 2000
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_image',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'og_image', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 2000
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'og_title', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 300
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'og_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'og_description', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 500
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_image',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'twitter_image', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 2000
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_title',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'twitter_title', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 300
|
||||
}
|
||||
},
|
||||
{
|
||||
table: 'posts',
|
||||
column: 'twitter_description',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createDropColumnMigration('posts', 'twitter_description', {
|
||||
type: 'string',
|
||||
nullable: true,
|
||||
maxlength: 500
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,44 +1,8 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
const createLog = type => msg => 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 = createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'type',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('posts', 'type', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'post'
|
||||
});
|
||||
|
||||
module.exports.down = createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'type',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,49 +1,7 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createDropColumnMigration} = require('../../utils');
|
||||
|
||||
const createLog = type => msg => 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 = createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'page',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
module.exports = createDropColumnMigration('posts', 'page', {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
});
|
||||
|
||||
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
|
||||
};
|
||||
|
|
|
@ -1,30 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'send_email_when_published',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'bool',
|
||||
nullable: true,
|
||||
defaultTo: false
|
||||
}
|
||||
module.exports = createAddColumnMigration('posts', 'send_email_when_published', {
|
||||
type: 'bool',
|
||||
nullable: true,
|
||||
defaultTo: false
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'send_email_when_published',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table: 'posts_meta',
|
||||
column: 'email_subject',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('posts_meta', 'email_subject', {
|
||||
type: 'string',
|
||||
maxlength: 300,
|
||||
nullable: true
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table: 'posts_meta',
|
||||
column: 'email_subject',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,44 +1,7 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
const createLog = type => msg => 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 = createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'subscribed',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('members', 'subscribed', {
|
||||
type: 'bool',
|
||||
nullable: true,
|
||||
defaultTo: true
|
||||
});
|
||||
|
||||
module.exports.down = createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'subscribed',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,44 +1,8 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
const createLog = type => msg => 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 = createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'uuid',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('members', 'uuid', {
|
||||
type: 'string',
|
||||
maxlength: 36,
|
||||
nullable: true,
|
||||
unique: true
|
||||
});
|
||||
|
||||
module.exports.down = createColumnMigration({
|
||||
table: 'members',
|
||||
column: 'uuid',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,25 +1,8 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'error_data',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('emails', 'error_data', {
|
||||
type: 'text',
|
||||
maxlength: 1000000000,
|
||||
fieldtype: 'long',
|
||||
nullable: true
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'error_data',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,25 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table: 'members_stripe_customers_subscriptions',
|
||||
column: 'cancel_at_period_end',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('members_stripe_customers_subscriptions', 'cancel_at_period_end', {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table: 'members_stripe_customers_subscriptions',
|
||||
column: 'cancel_at_period_end',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -1,49 +1,15 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
transaction: true
|
||||
},
|
||||
|
||||
async up(options) {
|
||||
function addSettingsColumn(column) {
|
||||
return {
|
||||
table: 'settings',
|
||||
column,
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
};
|
||||
}
|
||||
|
||||
const columnMigration = commands.createColumnMigration(
|
||||
addSettingsColumn('group'),
|
||||
addSettingsColumn('flags')
|
||||
);
|
||||
|
||||
return columnMigration(options);
|
||||
},
|
||||
|
||||
async down(options) {
|
||||
function removeSettingsColumn(column) {
|
||||
return {
|
||||
table: 'settings',
|
||||
column,
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
};
|
||||
}
|
||||
|
||||
const columnMigration = commands.createColumnMigration(
|
||||
removeSettingsColumn('group'),
|
||||
removeSettingsColumn('flags')
|
||||
);
|
||||
|
||||
return columnMigration(options);
|
||||
}
|
||||
};
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createAddColumnMigration('settings', 'group', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'core'
|
||||
}),
|
||||
createAddColumnMigration('settings', 'flags', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: true
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,97 +1,54 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils');
|
||||
|
||||
const newColumns = [{
|
||||
column: 'og_image',
|
||||
columnDefinition: {
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createAddColumnMigration('tags', 'og_image', {
|
||||
type: 'string',
|
||||
maxlength: 2000,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'og_title',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'og_title', {
|
||||
type: 'string',
|
||||
maxlength: 300,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'og_description',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'og_description', {
|
||||
type: 'string',
|
||||
maxlength: 500,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'twitter_image',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'twitter_image', {
|
||||
type: 'string',
|
||||
maxlength: 2000,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'twitter_title',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'twitter_title', {
|
||||
type: 'string',
|
||||
maxlength: 300,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'twitter_description',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'twitter_description', {
|
||||
type: 'string',
|
||||
maxlength: 500,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'codeinjection_head',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'codeinjection_head', {
|
||||
type: 'text',
|
||||
maxlength: 65535,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'codeinjection_foot',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'codeinjection_foot', {
|
||||
type: 'text',
|
||||
maxlength: 65535,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'canonical_url',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'canonical_url', {
|
||||
type: 'string',
|
||||
maxlength: 2000,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'accent_color',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('tags', 'accent_color', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: true
|
||||
}
|
||||
}];
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
transaction: true
|
||||
},
|
||||
|
||||
up: commands.createColumnMigration(...newColumns.map((column) => {
|
||||
return Object.assign({}, column, {
|
||||
table: 'tags',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === true,
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
});
|
||||
})),
|
||||
|
||||
down: commands.createColumnMigration(...newColumns.map((column) => {
|
||||
return Object.assign({}, column, {
|
||||
table: 'tags',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
}))
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,41 +1,14 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils');
|
||||
|
||||
const newColumns = [{
|
||||
column: 'from',
|
||||
columnDefinition: {
|
||||
module.exports = combineNonTransactionalMigrations(
|
||||
createAddColumnMigration('emails', 'from', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: true
|
||||
}
|
||||
}, {
|
||||
column: 'reply_to',
|
||||
columnDefinition: {
|
||||
}),
|
||||
createAddColumnMigration('emails', 'reply_to', {
|
||||
type: 'string',
|
||||
maxlength: 191,
|
||||
nullable: true
|
||||
}
|
||||
}];
|
||||
|
||||
module.exports = {
|
||||
config: {
|
||||
transaction: true
|
||||
},
|
||||
|
||||
up: commands.createColumnMigration(...newColumns.map((column) => {
|
||||
return Object.assign({}, column, {
|
||||
table: 'emails',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === true,
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
});
|
||||
})),
|
||||
|
||||
down: commands.createColumnMigration(...newColumns.map((column) => {
|
||||
return Object.assign({}, column, {
|
||||
table: 'emails',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
}))
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
|
@ -1,25 +1,8 @@
|
|||
const {createColumnMigration, addColumn, dropColumn} = require('../../../schema/commands');
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
up: createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'email_recipient_filter',
|
||||
dbIsInCorrectState: hasColumn => !!hasColumn,
|
||||
operation: addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'none',
|
||||
validations: {isIn: [['none', 'all', 'free', 'paid']]}
|
||||
}
|
||||
}),
|
||||
down: createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'email_recipient_filter',
|
||||
dbIsInCorrectState: hasColumn => !hasColumn,
|
||||
operation: dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
})
|
||||
};
|
||||
module.exports = createAddColumnMigration('posts', 'email_recipient_filter', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'none'
|
||||
});
|
||||
|
|
|
@ -1,25 +1,8 @@
|
|||
const {createColumnMigration, addColumn, dropColumn} = require('../../../schema/commands');
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
up: createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'recipient_filter',
|
||||
dbIsInCorrectState: hasColumn => !!hasColumn,
|
||||
operation: addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'paid',
|
||||
validations: {isIn: [['all', 'free', 'paid']]}
|
||||
}
|
||||
}),
|
||||
down: createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'recipient_filter',
|
||||
dbIsInCorrectState: hasColumn => !hasColumn,
|
||||
operation: dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
})
|
||||
};
|
||||
module.exports = createAddColumnMigration('emails', 'recipient_filter', {
|
||||
type: 'string',
|
||||
maxlength: 50,
|
||||
nullable: false,
|
||||
defaultTo: 'paid'
|
||||
});
|
||||
|
|
|
@ -1,24 +1,7 @@
|
|||
const {createColumnMigration, addColumn, dropColumn} = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
up: createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'track_opens',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === true,
|
||||
operation: addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
}
|
||||
}),
|
||||
|
||||
down: createColumnMigration({
|
||||
table: 'emails',
|
||||
column: 'track_opens',
|
||||
dbIsInCorrectState: hasColumn => hasColumn === false,
|
||||
operation: dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
})
|
||||
};
|
||||
module.exports = createAddColumnMigration('emails', 'track_opens', {
|
||||
type: 'bool',
|
||||
nullable: false,
|
||||
defaultTo: false
|
||||
});
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const {createColumnMigration, addColumn, dropColumn} = require('../../../schema/commands');
|
||||
const {createDropColumnMigration} = require('../../utils');
|
||||
|
||||
module.exports = {
|
||||
up: createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'send_email_when_published',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
}),
|
||||
|
||||
down: createColumnMigration({
|
||||
table: 'posts',
|
||||
column: 'send_email_when_published',
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: addColumn,
|
||||
operationVerb: 'Adding',
|
||||
columnDefinition: {
|
||||
type: 'bool',
|
||||
nullable: true,
|
||||
defaultTo: false
|
||||
}
|
||||
})
|
||||
};
|
||||
module.exports = createDropColumnMigration('posts', 'send_email_when_published', {
|
||||
type: 'bool',
|
||||
nullable: true,
|
||||
defaultTo: false
|
||||
});
|
||||
|
|
|
@ -1,28 +1,7 @@
|
|||
const commands = require('../../../schema').commands;
|
||||
const {createAddColumnMigration} = require('../../utils');
|
||||
|
||||
const table = 'members';
|
||||
const column = 'geolocation';
|
||||
|
||||
module.exports.up = commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === true;
|
||||
},
|
||||
operation: commands.addColumn,
|
||||
operationVerb: 'Adding'
|
||||
module.exports = createAddColumnMigration('members', 'geolocation', {
|
||||
type: 'string',
|
||||
maxlength: 2000,
|
||||
nullable: true
|
||||
});
|
||||
|
||||
module.exports.down = commands.createColumnMigration({
|
||||
table,
|
||||
column,
|
||||
dbIsInCorrectState(columnExists) {
|
||||
return columnExists === false;
|
||||
},
|
||||
operation: commands.dropColumn,
|
||||
operationVerb: 'Removing'
|
||||
});
|
||||
|
||||
module.exports.config = {
|
||||
transaction: true
|
||||
};
|
||||
|
|
|
@ -162,9 +162,7 @@ function createColumnMigration(...migrations) {
|
|||
}
|
||||
}
|
||||
|
||||
return async function columnMigration(options) {
|
||||
const conn = options.transacting || options.connection;
|
||||
|
||||
return async function columnMigration(conn) {
|
||||
for (const migration of migrations) {
|
||||
await runColumnMigration(conn, migration);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue