Added members_feedback table (#15581)

fixes https://github.com/TryGhost/Team/issues/2041
This commit is contained in:
Simon Backx 2022-10-11 13:21:31 +02:00 committed by GitHub
parent 714e108d40
commit 74d749fa63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 2 deletions

View File

@ -40,7 +40,8 @@ const BACKUP_TABLES = [
'comment_reports',
'jobs',
'redirects',
'members_click_events'
'members_click_events',
'members_feedback'
];
// NOTE: exposing only tables which are going to be included in a "default" export file

View File

@ -0,0 +1,10 @@
const {addTable} = require('../../utils');
module.exports = addTable('members_feedback', {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
score: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
});

View File

@ -850,5 +850,13 @@ module.exports = {
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
redirect_id: {type: 'string', maxlength: 24, nullable: false, references: 'redirects.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false}
},
members_feedback: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
score: {type: 'integer', nullable: false, unsigned: true, defaultTo: 0},
member_id: {type: 'string', maxlength: 24, nullable: false, references: 'members.id', cascadeDelete: true},
post_id: {type: 'string', maxlength: 24, nullable: false, references: 'posts.id', cascadeDelete: true},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
}
};

View File

@ -0,0 +1,22 @@
const errors = require('@tryghost/errors');
const ghostBookshelf = require('./base');
const MemberFeedback = ghostBookshelf.Model.extend({
tableName: 'members_feedback',
post() {
return this.belongsTo('Post', 'post_id', 'id');
},
member() {
return this.belongsTo('Member', 'member_id', 'id');
}
}, {
async destroy() {
throw new errors.IncorrectUsageError({message: 'Cannot destroy MemberFeedback'});
}
});
module.exports = {
MemberFeedback: ghostBookshelf.model('MemberFeedback', MemberFeedback)
};

View File

@ -40,6 +40,7 @@ describe('Exporter', function () {
'members',
'members_cancel_events',
'members_email_change_events',
'members_feedback',
'members_labels',
'members_click_events',
'members_login_events',

View File

@ -35,7 +35,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route
*/
describe('DB version integrity', function () {
// Only these variables should need updating
const currentSchemaHash = '67009be314428b02976e75281de37b14';
const currentSchemaHash = 'c7f45ba40b60a81ce92d2d277009c681';
const currentFixturesHash = '8cf221f0ed930ac1fe8030a58e60d64b';
const currentSettingsHash = '2978a5684a2d5fcf089f61f5d368a0c0';
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';

View File

@ -0,0 +1,56 @@
const should = require('should');
const sinon = require('sinon');
const errors = require('@tryghost/errors');
const models = require('../../../../core/server/models');
describe('Unit: models/MemberFeedback', function () {
before(function () {
models.init();
});
afterEach(function () {
sinon.restore();
});
describe('validation', function () {
it('throws if member_id is missing', function () {
return models.MemberFeedback.add({score: 1, post_id: 'post'})
.then(function () {
throw new Error('expected ValidationError');
})
.catch(function (err) {
should(err).lengthOf(1);
(err[0] instanceof errors.ValidationError).should.eql(true);
err[0].context.should.match(/members_feedback\.member_id/);
});
});
it('throws if post_id is missing', function () {
return models.MemberFeedback.add({score: 1, member_id: '123'})
.then(function () {
throw new Error('expected ValidationError');
})
.catch(function (err) {
should(err).lengthOf(1);
(err[0] instanceof errors.ValidationError).should.eql(true);
err[0].context.should.match(/members_feedback\.post_id/);
});
});
});
it('Delete is disabled', function () {
return models.MemberFeedback.destroy({id: 'any'})
.then(function () {
throw new Error('expected IncorrectUsageError');
})
.catch(function (err) {
(err instanceof errors.IncorrectUsageError).should.eql(true);
});
});
it('Has post and member relations', function () {
const model = models.MemberFeedback.forge({id: 'any'});
model.post();
model.member();
});
});