Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created session table migration #9908

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions core/server/data/migrations/versions/2.2/1-add-sessions-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const common = require('../../../../lib/common');

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

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
Original file line number Diff line number Diff line change
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},

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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