Skip to content

Commit

Permalink
Created session table migration (#9908)
Browse files Browse the repository at this point in the history
refs #9865

- This table will be used for storing user sessions in
  • Loading branch information
allouis authored and kirrg001 committed Sep 27, 2018
1 parent 4c5bff0 commit 1d17f2a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
35 changes: 35 additions & 0 deletions core/server/data/migrations/versions/2.2/1-add-sessions-table.js
@@ -0,0 +1,35 @@
const common = require('../../../../lib/common');
const commands = require('../../../schema').commands;
const table = 'sessions';
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);
});
};
8 changes: 8 additions & 0 deletions core/server/data/schema/schema.js
Expand Up @@ -300,5 +300,13 @@ module.exports = {
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
sessions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
session_id: {type: 'string', maxlength: 32, nullable: false, unique: true},
user_id: {type: 'string', maxlength: 24, nullable: false},
session_data: {type: 'string', maxlength: 2000, nullable: false},
created_at: {type: 'dateTime', nullable: false},
updated_at: {type: 'dateTime', nullable: true}
}
};
4 changes: 2 additions & 2 deletions core/test/functional/routes/api/db_spec.js
Expand Up @@ -72,7 +72,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(21);
Object.keys(jsonResponse.db[0].data).length.should.eql(22);
done();
});
});
Expand All @@ -90,7 +90,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(23);
Object.keys(jsonResponse.db[0].data).length.should.eql(24);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions core/test/unit/data/schema/integrity_spec.js
Expand Up @@ -19,8 +19,8 @@ var should = require('should'),
*/
describe('DB version integrity', function () {
// Only these variables should need updating
var currentSchemaHash = '22d24b1de23d118b90e9547fefae5ad7',
currentFixturesHash = 'eab42b1e9cd754e76600f1c57c4a7af8';
const currentSchemaHash = 'be8d6ff382ae07b238c60d5b453a2944';
const currentFixturesHash = 'eab42b1e9cd754e76600f1c57c4a7af8';

// If this test is failing, then it is likely a change has been made that requires a DB version bump,
// and the values above will need updating as confirmation
Expand Down

0 comments on commit 1d17f2a

Please sign in to comment.