0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-08 02:52:39 -05:00

Added actions table including migration

refs 10431

- add actions table
- add migration
This commit is contained in:
kirrg001 2019-01-29 17:06:11 +01:00 committed by Katharina Irrgang
parent 8a441a04ab
commit c127b406fc
6 changed files with 53 additions and 5 deletions

View file

@ -0,0 +1,35 @@
const common = require('../../../../lib/common');
const commands = require('../../../schema').commands;
const table = 'actions';
const message1 = `Adding table: ${table}`;
const message2 = `Dropping table: ${table}`;
module.exports.up = (options) => {
const connection = options.connection;
return connection.schema.hasTable(table)
.then(function (exists) {
if (exists) {
common.logging.warn(message1);
return;
}
common.logging.info(message1);
return commands.createTable(table, connection);
});
};
module.exports.down = (options) => {
const connection = options.connection;
return connection.schema.hasTable(table)
.then(function (exists) {
if (!exists) {
common.logging.warn(message2);
return;
}
common.logging.info(message2);
return commands.deleteTable(table, connection);
});
};

View file

@ -383,5 +383,18 @@ module.exports = {
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
actions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
resource_id: {type: 'string', maxlength: 24, nullable: true},
resource_type: {type: 'string', maxlength: 50, nullable: false},
actor_id: {type: 'string', maxlength: 24, nullable: false},
actor_type: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The event column contains short buzzwords e.g. subscribed, started, added, deleted, edited etc.
// We already store and require the target resource type. No need to remember e.g. post.edited
event: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The context object can be used to store information about an action e.g. diffs, meta
context: {type: 'text', maxlength: 1000000000, nullable: true},
created_at: {type: 'dateTime', nullable: false}
}
};

View file

@ -66,7 +66,7 @@ describe('DB API', () => {
const jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(25);
Object.keys(jsonResponse.db[0].data).length.should.eql(26);
});
});

View file

@ -88,7 +88,7 @@ describe('DB API', function () {
var jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(25);
Object.keys(jsonResponse.db[0].data).length.should.eql(26);
done();
});
});
@ -106,7 +106,7 @@ describe('DB API', function () {
const jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(27);
Object.keys(jsonResponse.db[0].data).length.should.eql(28);
done();
});
});

View file

@ -61,7 +61,7 @@ describe('DB API', () => {
const jsonResponse = res.body;
should.exist(jsonResponse.db);
jsonResponse.db.should.have.length(1);
Object.keys(jsonResponse.db[0].data).length.should.eql(27);
Object.keys(jsonResponse.db[0].data).length.should.eql(28);
});
});

View file

@ -19,7 +19,7 @@ var should = require('should'),
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = 'b865478398cd2b0a1e5eaffebccdb88c';
const currentSchemaHash = 'ddca519660d4c9489259557438a41c78';
const currentFixturesHash = 'cc19eac0f38ed778d25c82753f687495';
// If this test is failing, then it is likely a change has been made that requires a DB version bump,