mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Created session table migration (#9908)
refs #9865 - This table will be used for storing user sessions in
This commit is contained in:
parent
4c5bff0f49
commit
1d17f2aa91
4 changed files with 47 additions and 4 deletions
|
@ -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);
|
||||
});
|
||||
};
|
|
@ -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}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue