Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove i18n from migration output #6543

Merged
merged 1 commit into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions core/server/data/migration/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
errors = require('../../errors'),
commands = require('../schema').commands,
schema = require('../schema').tables,
i18n = require('../../i18n'),

// private
logInfo,
Expand All @@ -15,14 +14,14 @@ var _ = require('lodash'),
modifyUniqueCommands;

logInfo = function logInfo(message) {
errors.logInfo(i18n.t('notices.data.migration.commands.migrations'), message);
errors.logInfo('Migrations', message);
};

getDeleteCommands = function getDeleteCommands(oldTables, newTables) {
var deleteTables = _.difference(oldTables, newTables);
return _.map(deleteTables, function (table) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.deletingTable', {table: table}));
logInfo('Deleting table: ' + table);
return commands.deleteTable(table);
};
});
Expand All @@ -32,7 +31,7 @@ getAddCommands = function getAddCommands(oldTables, newTables) {
var addTables = _.difference(newTables, oldTables);
return _.map(addTables, function (table) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.creatingTable', {table: table}));
logInfo('Creating table: ' + table);
return commands.createTable(table);
};
});
Expand All @@ -44,7 +43,7 @@ addColumnCommands = function addColumnCommands(table, columns) {

return _.map(addColumns, function (column) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.addingColumn', {table: table, column: column}));
logInfo('Adding column: ' + table + '.' + column);
return commands.addColumn(table, column);
};
});
Expand All @@ -56,7 +55,7 @@ dropColumnCommands = function dropColumnCommands(table, columns) {

return _.map(dropColumns, function (column) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.droppingColumn', {table: table, column: column}));
logInfo('Dropping column: ' + table + '.' + column);
return commands.dropColumn(table, column);
};
});
Expand All @@ -68,14 +67,14 @@ modifyUniqueCommands = function modifyUniqueCommands(table, indexes) {
if (schema[table][column].unique === true) {
if (!_.contains(indexes, table + '_' + column + '_unique')) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.addingUnique', {table: table, column: column}));
logInfo('Adding unique on: ' + table + '.' + column);
return commands.addUnique(table, column);
};
}
} else if (!schema[table][column].unique) {
if (_.contains(indexes, table + '_' + column + '_unique')) {
return function () {
logInfo(i18n.t('notices.data.migration.commands.droppingUnique', {table: table, column: column}));
logInfo('Dropping unique on: ' + table + '.' + column);
return commands.dropUnique(table, column);
};
}
Expand Down
39 changes: 20 additions & 19 deletions core/server/data/migration/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var Promise = require('bluebird'),
update;

logInfo = function logInfo(message) {
errors.logInfo(i18n.t('notices.data.fixtures.migrations'), message);
errors.logInfo('Migrations', message);
};

/**
Expand All @@ -47,7 +47,7 @@ convertAdminToOwner = function convertAdminToOwner() {
return models.Role.findOne({name: 'Owner'});
}).then(function (ownerRole) {
if (adminUser) {
logInfo(i18n.t('notices.data.fixtures.convertingAdmToOwner'));
logInfo('Converting admin to owner');
return adminUser.roles().updatePivot({role_id: ownerRole.id});
}
});
Expand All @@ -65,7 +65,7 @@ createOwner = function createOwner() {
user.roles = [ownerRole.id];
user.password = utils.uid(50);

logInfo(i18n.t('notices.data.fixtures.creatingOwner'));
logInfo('Creating owner');
return models.User.add(user, options);
});
};
Expand All @@ -78,7 +78,7 @@ populate = function populate() {
Role = models.Role,
Client = models.Client;

logInfo(i18n.t('notices.data.fixtures.populatingFixtures'));
logInfo('Populating fixtures');

_.each(fixtures.posts, function (post) {
ops.push(Post.add(post, options));
Expand Down Expand Up @@ -134,12 +134,12 @@ to003 = function to003() {
Role = models.Role,
Client = models.Client;

logInfo(i18n.t('notices.data.fixtures.upgradingFixturesTo', {version: '003'}));
logInfo('Upgrading fixtures to 003');

// Add the client fixture if missing
upgradeOp = Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
if (!client) {
logInfo(i18n.t('notices.data.fixtures.addingClientFixture'));
logInfo('Adding ghost-admin client fixture');
return Client.add(fixtures.clients[0], options);
}
});
Expand All @@ -148,7 +148,7 @@ to003 = function to003() {
// Add the owner role if missing
upgradeOp = Role.findOne({name: fixtures.roles[3].name}).then(function (owner) {
if (!owner) {
logInfo(i18n.t('notices.data.fixtures.addingOwnerRoleFixture'));
logInfo('Adding owner role fixture');
_.each(fixtures.roles.slice(3), function (role) {
return Role.add(role, options);
});
Expand All @@ -171,6 +171,7 @@ to004 = function to004() {
var value,
ops = [],
upgradeOp,
// These messages are shown in the admin UI, not the console, and should therefore be translated
jquery = [
i18n.t('notices.data.fixtures.canSafelyDelete'),
'<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>\n\n'
Expand All @@ -180,7 +181,7 @@ to004 = function to004() {
i18n.t('notices.data.fixtures.canBeChanged')
];

logInfo(i18n.t('notices.data.fixtures.upgradingFixturesTo', {version: '004'}));
logInfo('Upgrading fixtures to 004');

// add jquery setting and privacy info
upgradeOp = function () {
Expand All @@ -189,7 +190,7 @@ to004 = function to004() {
value = setting.attributes.value;
// Only add jQuery if it's not already in there
if (value.indexOf(jquery.join('')) === -1) {
logInfo(i18n.t('notices.data.fixtures.addingJquery'));
logInfo('Adding jQuery link to ghost_foot');
value = jquery.join('') + value;
return models.Settings.edit({key: 'ghost_foot', value: value}, options).then(function () {
if (_.isEmpty(config.privacy)) {
Expand All @@ -211,7 +212,7 @@ to004 = function to004() {
upgradeOp = function () {
return models.Settings.findOne('isPrivate').then(function (setting) {
if (setting) {
logInfo(i18n.t('notices.data.fixtures.updateIsPrivate'));
logInfo('Update isPrivate setting');
return models.Settings.edit({key: 'isPrivate', type: 'private'}, options);
}
return Promise.resolve();
Expand All @@ -223,7 +224,7 @@ to004 = function to004() {
upgradeOp = function () {
return models.Settings.findOne('password').then(function (setting) {
if (setting) {
logInfo(i18n.t('notices.data.fixtures.updatePassword'));
logInfo('Update password setting');
return models.Settings.edit({key: 'password', type: 'private'}, options);
}
return Promise.resolve();
Expand All @@ -236,7 +237,7 @@ to004 = function to004() {
upgradeOp = function () {
return models.Client.findOne({slug: fixtures.clients[0].slug}).then(function (client) {
if (client) {
logInfo(i18n.t('notices.data.fixtures.updateAdminClientFixture'));
logInfo('Update ghost-admin client fixture');
var adminClient = fixtures.clients[0];
adminClient.secret = crypto.randomBytes(6).toString('hex');
return models.Client.edit(adminClient, _.extend({}, options, {id: client.id}));
Expand All @@ -250,7 +251,7 @@ to004 = function to004() {
upgradeOp = function () {
return models.Client.findOne({slug: fixtures.clients[1].slug}).then(function (client) {
if (!client) {
logInfo(i18n.t('notices.data.fixtures.addFrontendClientFixture'));
logInfo('Add ghost-frontend client fixture');
var frontendClient = fixtures.clients[1];
frontendClient.secret = crypto.randomBytes(6).toString('hex');
return models.Client.add(frontendClient, options);
Expand All @@ -277,7 +278,7 @@ to004 = function to004() {
}
});
if (tagOps.length > 0) {
logInfo(i18n.t('notices.data.fixtures.cleaningTags', {length: tagOps.length}));
logInfo('Cleaning ' + tagOps.length + ' malformed tags');
return Promise.all(tagOps);
}
}
Expand All @@ -289,7 +290,7 @@ to004 = function to004() {
// Add post_tag order
upgradeOp = function () {
var tagOps = [];
logInfo(i18n.t('notices.data.fixtures.collectingDataOnTagOrder'));
logInfo('Collecting data on tag order for posts...');
return models.Post.findAll(_.extend({}, options)).then(function (posts) {
if (posts) {
return posts.mapThen(function (post) {
Expand All @@ -314,9 +315,9 @@ to004 = function to004() {
});

if (tagOps.length > 0) {
logInfo(i18n.t('notices.data.fixtures.updatingOrder', {length: tagOps.length}));
logInfo('Updating order on ' + tagOps.length + ' tag relationships (could take a while)...');
return sequence(tagOps).then(function () {
logInfo(i18n.t('notices.data.fixtures.updatedOrder'));
logInfo('Tag order successfully updated');
});
}
});
Expand All @@ -327,7 +328,7 @@ to004 = function to004() {
upgradeOp = function () {
return models.Post.findOne({slug: fixtures.posts_0_7[0].slug, status: 'all'}, options).then(function (post) {
if (!post) {
logInfo(i18n.t('notices.data.fixtures.addingUpgrade', {version: '0.7'}));
logInfo('Adding 0.7 upgrade post fixture');
// Set the published_at timestamp, but keep the post as a draft so doesn't appear on the frontend
// This is a hack to ensure that this post appears at the very top of the drafts list, because
// unpublished posts always appear first
Expand All @@ -344,7 +345,7 @@ to004 = function to004() {
update = function update(fromVersion, toVersion) {
var ops = [];

logInfo(i18n.t('notices.data.fixtures.updatingFixtures'));
logInfo('Updating fixtures');
// Are we migrating to, or past 003?
if ((fromVersion < '003' && toVersion >= '003') ||
fromVersion === '003' && toVersion === '003' && process.env.FORCE_MIGRATION) {
Expand Down
7 changes: 3 additions & 4 deletions core/server/data/migration/fixtures/permissions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var Promise = require('bluebird'),
_ = require('lodash'),
errors = require('../../../../errors'),
i18n = require('../../../../i18n'),
models = require('../../../../models'),
sequence = require('../../../../utils/sequence'),
fixtures = require('./permissions'),
Expand Down Expand Up @@ -72,7 +71,7 @@ addAllPermissions = function (options) {

// ## Populate
populate = function (options) {
logInfo(i18n.t('errors.data.fixtures.populatingPermissions'));
logInfo('Populating permissions');
// ### Ensure all permissions are added
return addAllPermissions(options).then(function () {
// ### Ensure all roles_permissions are added
Expand All @@ -86,12 +85,12 @@ populate = function (options) {
to003 = function (options) {
var ops = [];

logInfo(i18n.t('errors.data.fixtures.upgradingPermissions'));
logInfo('Upgrading permissions');

// To safely upgrade, we need to clear up the existing permissions and permissions_roles before recreating the new
// full set of permissions defined as of version 003
return models.Permissions.forge().fetch().then(function (permissions) {
logInfo(i18n.t('errors.data.fixtures.removingOldPermissions'));
logInfo('Removing old permissions');
permissions.each(function (permission) {
ops.push(permission.related('roles').detach().then(function () {
return permission.destroy();
Expand Down
30 changes: 14 additions & 16 deletions core/server/data/migration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var _ = require('lodash'),
dataExport = require('../export'),
config = require('../../config'),
errors = require('../../errors'),
i18n = require('../../i18n'),
models = require('../../models'),
sequence = require('../../utils/sequence'),

Expand All @@ -30,26 +29,26 @@ var _ = require('lodash'),
backupDatabase;

logInfo = function logInfo(message) {
errors.logInfo(i18n.t('notices.data.migration.index.migrations'), message);
errors.logInfo('Migrations', message);
};

populateDefaultSettings = function populateDefaultSettings() {
// Initialise the default settings
logInfo(i18n.t('notices.data.migration.index.populatingDefaultSettings'));
logInfo('Populating default settings');
return models.Settings.populateDefaults().then(function () {
logInfo(i18n.t('notices.data.migration.index.complete'));
logInfo('Complete');
});
};

backupDatabase = function backupDatabase() {
logInfo(i18n.t('notices.data.migration.index.creatingDatabaseBackup'));
logInfo('Creating database backup');
return dataExport().then(function (exportedData) {
// Save the exported data to the file system for download
return dataExport.fileName().then(function (fileName) {
fileName = path.resolve(config.paths.contentPath + '/data/' + fileName);

return Promise.promisify(fs.writeFile)(fileName, JSON.stringify(exportedData)).then(function () {
logInfo(i18n.t('notices.data.migration.index.databaseBackupDestination', {filename: fileName}));
logInfo('Database backup written to: ' + fileName);
});
});
});
Expand Down Expand Up @@ -84,8 +83,7 @@ init = function (tablesOnly) {
if (databaseVersion < defaultVersion || process.env.FORCE_MIGRATION) {
// 2. The database exists but is out of date
// Migrate to latest version
logInfo(i18n.t('notices.data.migration.index.databaseUpgradeRequired',
{dbVersion: databaseVersion, defaultVersion: defaultVersion}));
logInfo('Database upgrade required from version ' + databaseVersion + ' to ' + defaultVersion);
return self.migrateUp(databaseVersion, defaultVersion).then(function () {
// Finally update the databases current version
return versioning.setDatabaseVersion();
Expand All @@ -94,7 +92,7 @@ init = function (tablesOnly) {

if (databaseVersion === defaultVersion) {
// 1. The database exists and is up-to-date
logInfo(i18n.t('notices.data.migration.index.upToDateAtVersion', {dbVersion: databaseVersion}));
logInfo('Up to date at version ' + databaseVersion);
// TODO: temporary fix for missing client.secret
return fixClientSecret();
}
Expand All @@ -103,20 +101,20 @@ init = function (tablesOnly) {
// 3. The database exists but the currentVersion setting does not or cannot be understood
// In this case we don't understand the version because it is too high
errors.logErrorAndExit(
i18n.t('notices.data.migration.index.databaseNotCompatible.error'),
i18n.t('notices.data.migration.index.databaseNotCompatible.help')
'Your database is not compatible with this version of Ghost',
'You will need to create a new database'
);
}
}, function (err) {
if (err.message || err === 'Settings table does not exist') {
// 4. The database has not yet been created
// Bring everything up from initial version.
logInfo(i18n.t('notices.data.migration.index.dbInitialisationRequired', {version: versioning.getDefaultDatabaseVersion()}));
logInfo('Database initialisation required for version ' + versioning.getDefaultDatabaseVersion());
return self.migrateUpFreshDb(tablesOnly);
}
// 3. The database exists but the currentVersion setting does not or cannot be understood
// In this case the setting was missing or there was some other problem
errors.logErrorAndExit(i18n.t('notices.data.migration.index.problemWithDatabase'), err.message || err);
errors.logErrorAndExit('There is a problem with the database', err.message || err);
});
};

Expand All @@ -137,11 +135,11 @@ migrateUpFreshDb = function (tablesOnly) {
var tableSequence,
tables = _.map(schemaTables, function (table) {
return function () {
logInfo(i18n.t('notices.data.migration.index.creatingTable', {table: table}));
logInfo('Creating table: ' + table);
return commands.createTable(table);
};
});
logInfo(i18n.t('notices.data.migration.index.creatingTables'));
logInfo('Creating tables...');
tableSequence = sequence(tables);

if (tablesOnly) {
Expand Down Expand Up @@ -192,7 +190,7 @@ migrateUp = function (fromVersion, toVersion) {

// execute the commands in sequence
if (!_.isEmpty(migrateOps)) {
logInfo(i18n.t('notices.data.migration.index.runningMigrations'));
logInfo('Running migrations');

return sequence(migrateOps);
}
Expand Down
Loading