Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #6972, #6574 - run each database version as top level transaction - run migrations in correct order
- Loading branch information
Showing
42 changed files
with
954 additions
and
924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/004/01-add-tour-column-to-users.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
table = 'users', | ||
column = 'tour', | ||
message = 'Adding column: ' + table + '.' + column; | ||
|
||
table = 'users', | ||
column = 'tour', | ||
message = 'Adding column: ' + table + '.' + column; | ||
module.exports = function addTourColumnToUsers(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function addTourColumnToUsers(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transaction.schema.hasColumn(table, column); | ||
}) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/004/02-add-sortorder-column-to-poststags.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
table = 'posts_tags', | ||
column = 'sort_order', | ||
message = 'Adding column: ' + table + '.' + column; | ||
|
||
table = 'posts_tags', | ||
column = 'sort_order', | ||
message = 'Adding column: ' + table + '.' + column; | ||
module.exports = function addSortOrderColumnToPostsTags(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function addSortOrderColumnToPostsTags(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transaction.schema.hasColumn(table, column); | ||
}) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
42 changes: 22 additions & 20 deletions
42
core/server/data/migration/004/03-add-many-columns-to-clients.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
var Promise = require('bluebird'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
table = 'clients', | ||
columns = ['redirection_uri', 'logo', 'status', 'type', 'description']; | ||
|
||
table = 'clients', | ||
columns = ['redirection_uri', 'logo', 'status', 'type', 'description']; | ||
module.exports = function addManyColumnsToClients(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
module.exports = function addManyColumnsToClients(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return Promise.mapSeries(columns, function (column) { | ||
var message = 'Adding column: ' + table + '.' + column; | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
|
||
return transaction.schema.hasColumn(table, column) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn('Adding columns to table: ' + table); | ||
} | ||
}); | ||
}); | ||
}; |
25 changes: 13 additions & 12 deletions
25
core/server/data/migration/004/04-add-clienttrusteddomains-table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
table = 'client_trusted_domains', | ||
message = 'Creating table: ' + table; | ||
|
||
table = 'client_trusted_domains', | ||
message = 'Creating table: ' + table; | ||
module.exports = function addClientTrustedDomainsTable(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function addClientTrustedDomainsTable(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.createTable(table); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.createTable(table, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/004/05-drop-unique-on-clients-secret.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
table = 'clients', | ||
column = 'secret', | ||
message = 'Dropping unique on: ' + table + '.' + column; | ||
|
||
table = 'clients', | ||
column = 'secret', | ||
message = 'Dropping unique on: ' + table + '.' + column; | ||
module.exports = function dropUniqueOnClientsSecret(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function dropUniqueOnClientsSecret(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return commands.getIndexes(table).then(function (indexes) { | ||
if (indexes.indexOf(table + '_' + column + '_unique') > -1) { | ||
logger.info(message); | ||
return commands.dropUnique(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return commands.getIndexes(table, transaction); | ||
}) | ||
.then(function (indexes) { | ||
if (indexes.indexOf(table + '_' + column + '_unique') > -1) { | ||
logger.info(message); | ||
return commands.dropUnique(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/005/01-drop-hidden-column-from-tags.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
table = 'tags', | ||
column = 'hidden', | ||
message = 'Removing column: ' + table + '.' + column; | ||
|
||
table = 'tags', | ||
column = 'hidden', | ||
message = 'Removing column: ' + table + '.' + column; | ||
module.exports = function dropHiddenColumnFromTags(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function dropHiddenColumnFromTags(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (exists) { | ||
logger.info(message); | ||
return commands.dropColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transaction.schema.hasColumn(table, column); | ||
}) | ||
.then(function (exists) { | ||
if (exists) { | ||
logger.info(message); | ||
return commands.dropColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/005/02-add-visibility-column-to-key-tables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
var Promise = require('bluebird'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
tables = ['posts', 'tags', 'users'], | ||
column = 'visibility'; | ||
|
||
tables = ['posts', 'tags', 'users'], | ||
column = 'visibility'; | ||
module.exports = function addVisibilityColumnToKeyTables(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function addVisibilityColumnToKeyTables(logger) { | ||
return Promise.mapSeries(tables, function (table) { | ||
var message = 'Adding column: ' + table + '.' + column; | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
var message = 'Adding column: ' + table + '.' + column; | ||
|
||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transaction.schema.hasColumn(table, column); | ||
}) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}); | ||
}; |
44 changes: 23 additions & 21 deletions
44
core/server/data/migration/005/03-add-mobiledoc-column-to-posts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
var commands = require('../../schema').commands, | ||
db = require('../../db'), | ||
var Promise = require('bluebird'), | ||
commands = require('../../schema').commands, | ||
table = 'posts', | ||
column = 'mobiledoc', | ||
message = 'Adding column: ' + table + '.' + column; | ||
|
||
table = 'posts', | ||
column = 'mobiledoc', | ||
message = 'Adding column: ' + table + '.' + column; | ||
module.exports = function addMobiledocColumnToPosts(options, logger) { | ||
var transaction = options.transacting; | ||
|
||
module.exports = function addMobiledocColumnToPosts(logger) { | ||
return db.knex.schema.hasTable(table).then(function (exists) { | ||
if (exists) { | ||
return db.knex.schema.hasColumn(table, column).then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
} else { | ||
// @TODO: this should probably be an error | ||
logger.warn(message); | ||
} | ||
}); | ||
return transaction.schema.hasTable(table) | ||
.then(function (exists) { | ||
if (!exists) { | ||
return Promise.reject(new Error('Table does not exist!')); | ||
} | ||
|
||
return transaction.schema.hasColumn(table, column); | ||
}) | ||
.then(function (exists) { | ||
if (!exists) { | ||
logger.info(message); | ||
return commands.addColumn(table, column, transaction); | ||
} else { | ||
logger.warn(message); | ||
} | ||
}); | ||
}; |
Oops, something went wrong.