mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Merge pull request #3313 from ErisDS/improve-fixtures
FORCE_MIGRATION ensures fixtures are added
This commit is contained in:
commit
48cbf371a2
3 changed files with 18 additions and 7 deletions
|
@ -51,7 +51,7 @@
|
|||
}
|
||||
],
|
||||
|
||||
"client": [
|
||||
"clients": [
|
||||
{
|
||||
"name": "Ghost Admin",
|
||||
"slug": "ghost-admin",
|
||||
|
|
|
@ -27,7 +27,7 @@ var when = require('when'),
|
|||
|
||||
|
||||
logInfo = function logInfo(message) {
|
||||
errors.logInfo('Fixtures', message);
|
||||
errors.logInfo('Migrations', message);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -58,6 +58,7 @@ convertAdminToOwner = function () {
|
|||
return models.Role.findOne({name: 'Owner'});
|
||||
}).then(function (ownerRole) {
|
||||
if (adminUser) {
|
||||
logInfo('Converting admin to owner');
|
||||
return adminUser.roles().updatePivot({role_id: ownerRole.id});
|
||||
}
|
||||
});
|
||||
|
@ -75,6 +76,7 @@ createOwner = function () {
|
|||
user.role = ownerRole.id;
|
||||
user.password = utils.uid(50);
|
||||
|
||||
logInfo('Creating owner');
|
||||
return models.User.add(user);
|
||||
});
|
||||
};
|
||||
|
@ -101,7 +103,7 @@ populate = function () {
|
|||
ops.push(function () { return Role.add(role); });
|
||||
});
|
||||
|
||||
_.each(fixtures.client, function (client) {
|
||||
_.each(fixtures.clients, function (client) {
|
||||
ops.push(function () { return Client.add(client); });
|
||||
});
|
||||
|
||||
|
@ -138,9 +140,10 @@ to003 = function () {
|
|||
Client = models.Client;
|
||||
|
||||
// Add the client fixture if missing
|
||||
upgradeOp = Client.findOne({secret: fixtures.client[0].secret}).then(function (client) {
|
||||
upgradeOp = Client.findOne({secret: fixtures.clients[0].secret}).then(function (client) {
|
||||
if (!client) {
|
||||
_.each(fixtures.client, function (client) {
|
||||
logInfo('Adding client fixture');
|
||||
_.each(fixtures.clients, function (client) {
|
||||
return Client.add(client);
|
||||
});
|
||||
}
|
||||
|
@ -150,6 +153,7 @@ to003 = function () {
|
|||
// Add the owner role if missing
|
||||
upgradeOp = Role.findOne({name: fixtures.roles[3].name}).then(function (owner) {
|
||||
if (!owner) {
|
||||
logInfo('Adding owner role fixture');
|
||||
_.each(fixtures.roles.slice(3), function (role) {
|
||||
return Role.add(role);
|
||||
});
|
||||
|
@ -166,7 +170,9 @@ to003 = function () {
|
|||
|
||||
update = function (fromVersion, toVersion) {
|
||||
logInfo('Updating fixtures');
|
||||
if (fromVersion < '003' && toVersion >= '003') {
|
||||
// Are we migrating to, or past 003?
|
||||
if ((fromVersion < '003' && toVersion >= '003') ||
|
||||
fromVersion === '003' && toVersion === '003' && process.env.FORCE_MIGRATION) {
|
||||
return to003();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ var when = require('when'),
|
|||
to003;
|
||||
|
||||
logInfo = function logInfo(message) {
|
||||
errors.logInfo('Permissions Fixtures', message);
|
||||
errors.logInfo('Migrations', message);
|
||||
};
|
||||
|
||||
addRolesPermissionsForRole = function (roleName) {
|
||||
|
@ -72,6 +72,8 @@ addAllPermissions = function () {
|
|||
|
||||
// ## Populate
|
||||
populate = function () {
|
||||
logInfo('Populating permissions');
|
||||
|
||||
// ### Ensure all permissions are added
|
||||
return addAllPermissions().then(function () {
|
||||
// ### Ensure all roles_permissions are added
|
||||
|
@ -85,9 +87,12 @@ populate = function () {
|
|||
to003 = function () {
|
||||
var ops = [];
|
||||
|
||||
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
|
||||
models.Permissions.forge().fetch().then(function (permissions) {
|
||||
logInfo('Removing old permissions');
|
||||
permissions.each(function (permission) {
|
||||
ops.push(permission.related('roles').detach().then(function () {
|
||||
return permission.destroy();
|
||||
|
|
Loading…
Add table
Reference in a new issue