Allow eventId in notifications table to be null
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
exports.up = function(db, callback) {
|
||||
async.series([
|
||||
db.runSql.bind(db, 'START TRANSACTION;'),
|
||||
// WARNING in the future always give constraints proper names to not rely on automatic ones
|
||||
db.runSql.bind(db, 'ALTER TABLE notifications DROP FOREIGN KEY notifications_ibfk_1'),
|
||||
db.runSql.bind(db, 'ALTER TABLE notifications MODIFY eventId VARCHAR(128)'),
|
||||
db.runSql.bind(db, 'COMMIT')
|
||||
], callback);
|
||||
};
|
||||
|
||||
exports.down = function(db, callback) {
|
||||
async.series([
|
||||
db.runSql.bind(db, 'START TRANSACTION;'),
|
||||
db.runSql.bind(db, 'ALTER TABLE notifications MODIFY eventId VARCHAR(128) NOT NULL'),
|
||||
db.runSql.bind(db, 'ALTER TABLE notifications ADD FOREIGN KEY(eventId) REFERENCES eventlog(id)'),
|
||||
db.runSql.bind(db, 'COMMIT')
|
||||
], callback);
|
||||
};
|
||||
@@ -215,14 +215,13 @@ CREATE TABLE IF NOT EXISTS tasks(
|
||||
CREATE TABLE IF NOT EXISTS notifications(
|
||||
id int NOT NULL AUTO_INCREMENT,
|
||||
userId VARCHAR(128) NOT NULL,
|
||||
eventId VARCHAR(128) NOT NULL,
|
||||
eventId VARCHAR(128),
|
||||
title VARCHAR(512) NOT NULL,
|
||||
message TEXT,
|
||||
action VARCHAR(512) NOT NULL,
|
||||
acknowledged BOOLEAN DEFAULT false,
|
||||
creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
FOREIGN KEY (eventId) REFERENCES eventlog(id),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
|
||||
@@ -163,6 +163,14 @@ describe('database', function () {
|
||||
action: 'usually a url'
|
||||
};
|
||||
|
||||
var NOTIFICATION_3 = {
|
||||
userId: USER_0.id,
|
||||
eventId: null,
|
||||
title: 'third one',
|
||||
message: 'some message there',
|
||||
action: 'usually a url'
|
||||
};
|
||||
|
||||
before(function (done) {
|
||||
async.series([
|
||||
userdb.add.bind(null, USER_0.id, USER_0),
|
||||
@@ -286,6 +294,14 @@ describe('database', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can add notification without eventId', function (done) {
|
||||
notificationdb.add(NOTIFICATION_3, function (error) {
|
||||
expect(error).to.equal(null);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('domains', function () {
|
||||
|
||||
Reference in New Issue
Block a user