2017-01-26 13:12:00 +01:00
|
|
|
var sinon = require('sinon'),
|
2016-07-15 18:22:41 +02:00
|
|
|
rewire = require('rewire'),
|
|
|
|
_ = require('lodash'),
|
2017-02-14 13:41:28 +01:00
|
|
|
should = require('should'),
|
2016-07-15 18:22:41 +02:00
|
|
|
Promise = require('bluebird'),
|
|
|
|
crypto = require('crypto'),
|
|
|
|
fs = require('fs'),
|
2016-07-14 12:59:42 +02:00
|
|
|
models = require('../../server/models'),
|
|
|
|
exporter = require('../../server/data/export'),
|
|
|
|
schema = require('../../server/data/schema'),
|
2017-01-25 14:47:49 +01:00
|
|
|
backupDatabase = rewire('../../server/data/db/backup'),
|
|
|
|
fixtures = require('../../server/data/schema/fixtures'),
|
2016-02-25 08:10:36 +01:00
|
|
|
sandbox = sinon.sandbox.create();
|
2014-12-20 10:16:29 +00:00
|
|
|
|
2017-02-14 13:41:28 +01:00
|
|
|
should.equal(true, true);
|
|
|
|
|
2016-03-21 12:44:23 +00:00
|
|
|
// Check version integrity
|
|
|
|
// These tests exist to ensure that developers are not able to modify the database schema, or permissions fixtures
|
|
|
|
// without knowing that they also need to update the default database version,
|
|
|
|
// both of which are required for migrations to work properly.
|
2017-01-25 14:47:49 +01:00
|
|
|
describe('DB version integrity', function () {
|
2016-03-21 12:44:23 +00:00
|
|
|
// Only these variables should need updating
|
🚨 database: change hard limits and field types (#7932)
refs #7432
🚨 database: change hard limits and field types
- we went over all schema fields and decided to decrease/increase the hard limits
- the core goal is to have more flexibility in the future
- we reconsidered string vs. text
There are 5 groups:
- small strings: 50 characters
- static strings
- status, visibility, language, role name, permission name, client name etc.
- medium strings: 191 characters
- all unique fields or fields which can be unique in the future
- slug, tokens, user name, password, tag name, email
- large strings: 1000-2000 characters
- these fields need to be very flexible
- these fields get a soft limit attached (in a different PR)
- post title, meta title, meta description, urls
- medium text: 64kb characters
- bio, settings, location, tour
- long text: 1000000000 chars
- html, amp, mobiledoc, markdown
🙄 sort_order for tests
- sort order was not set for the tests, so it was always 0
- mysql could return a different result
in my case:
- field length 156 returned the following related tags ["bacon", "kitchen"]
- field length 157 returned the following related tags ["kitchen", "kitchen"]
Change client.secret to 191
Tweak field lengths
- Add 24 char limit for ids
- Limited fields are the exact length they need
- Unified 1000 and 2000 char string classes to all be 2000
- Changed descriptions to be either 2000, except user & tag which is text 65535 as these may be used to store HTML later?!
- Updated tests
🛠 Update importer tests
- The old 001-003 tests are kind of less relevant now.
- Rather than worrying about past versions of the data structure, we should check that the importer only imports what we consider to be valid data
- I've changed the tests to treat the title-length check as a length-validation check, rather than a test for each of the old versions
🔥 Remove foreign key from subscribers.post_id
- There's no real need to have an index on this column, it just makes deleting posts hard.
- Same as created_by type columns, we can reference ids without needing keys/indexes
2017-02-17 23:20:59 +01:00
|
|
|
var currentSchemaHash = 'e648a7d1f9b9c5eb19512999756cd4db',
|
2017-01-25 22:08:09 +01:00
|
|
|
currentFixturesHash = 'b9e684a87353c592df9b23948e364c05';
|
2016-03-21 12:44:23 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
it('should not change without fixing this test', function () {
|
|
|
|
var tablesNoValidation = _.cloneDeep(schema.tables),
|
|
|
|
schemaHash,
|
|
|
|
fixturesHash;
|
|
|
|
|
|
|
|
_.each(tablesNoValidation, function (table) {
|
|
|
|
return _.each(table, function (column, name) {
|
|
|
|
table[name] = _.omit(column, 'validations');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
schemaHash = crypto.createHash('md5').update(JSON.stringify(tablesNoValidation)).digest('hex');
|
2017-01-25 14:47:49 +01:00
|
|
|
fixturesHash = crypto.createHash('md5').update(JSON.stringify(fixtures)).digest('hex');
|
2016-03-21 12:44:23 +00:00
|
|
|
|
|
|
|
schemaHash.should.eql(currentSchemaHash);
|
|
|
|
fixturesHash.should.eql(currentFixturesHash);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-01-25 14:47:49 +01:00
|
|
|
describe('Migrations', function () {
|
2016-07-14 12:59:42 +02:00
|
|
|
before(function () {
|
|
|
|
models.init();
|
|
|
|
});
|
|
|
|
|
2016-02-25 08:10:36 +01:00
|
|
|
afterEach(function () {
|
|
|
|
sandbox.restore();
|
2014-12-20 10:16:29 +00:00
|
|
|
});
|
2016-02-25 08:10:36 +01:00
|
|
|
|
2016-03-13 20:49:30 +00:00
|
|
|
describe('Backup', function () {
|
2016-03-23 15:02:40 +00:00
|
|
|
var exportStub, filenameStub, fsStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
exportStub = sandbox.stub(exporter, 'doExport').returns(new Promise.resolve());
|
|
|
|
filenameStub = sandbox.stub(exporter, 'fileName').returns(new Promise.resolve('test'));
|
|
|
|
fsStub = sandbox.stub(fs, 'writeFile').yields();
|
|
|
|
});
|
2016-03-13 20:49:30 +00:00
|
|
|
|
2016-03-23 15:02:40 +00:00
|
|
|
it('should create a backup JSON file', function (done) {
|
2017-01-25 14:47:49 +01:00
|
|
|
backupDatabase().then(function () {
|
2016-03-13 20:49:30 +00:00
|
|
|
exportStub.calledOnce.should.be.true();
|
|
|
|
filenameStub.calledOnce.should.be.true();
|
|
|
|
fsStub.calledOnce.should.be.true();
|
|
|
|
|
|
|
|
done();
|
|
|
|
}).catch(done);
|
|
|
|
});
|
|
|
|
});
|
2014-12-20 10:16:29 +00:00
|
|
|
});
|