Skip to content

Commit ca5cfd7

Browse files
author
meufel
committed
fix: sqlite url config not working with relative paths
Closes #965
1 parent 7876465 commit ca5cfd7

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/helpers/config-helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ const api = {
205205
config.database.indexOf(':memory') !== 0
206206
) {
207207
config = _.assign(config, {
208-
storage: '/' + config.database,
208+
storage: config.host.match(/^\.+$/)
209+
? config.database
210+
: '/' + config.database,
209211
});
210212
}
211213

test/db/migrate.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,58 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
402402
});
403403
});
404404

405+
describeOnlyForSQLite(Support.getTestDialectTeaser('db:migrate'), () => {
406+
describe('with url option containing relative path to a local storage file', () => {
407+
const prepare = function (callback) {
408+
const config = { url: 'sqlite:../test.sqlite' };
409+
const configContent = 'module.exports = ' + JSON.stringify(config);
410+
let result = '';
411+
412+
return gulp
413+
.src(Support.resolveSupportPath('tmp'))
414+
.pipe(helpers.clearDirectory())
415+
.pipe(helpers.runCli('init'))
416+
.pipe(helpers.removeFile('config/config.json'))
417+
.pipe(helpers.copyMigration('createPerson.js'))
418+
.pipe(helpers.overwriteFile(configContent, 'config/config.js'))
419+
.pipe(helpers.runCli('db:migrate'))
420+
.on('error', (e) => {
421+
callback(e);
422+
})
423+
.on('data', (data) => {
424+
result += data.toString();
425+
})
426+
.on('end', () => {
427+
callback(null, result);
428+
});
429+
};
430+
431+
it('creates a SequelizeMeta table', function (done) {
432+
const self = this;
433+
434+
prepare(() => {
435+
helpers.readTables(self.sequelize, (tables) => {
436+
expect(tables).to.have.length(2);
437+
expect(tables).to.contain('SequelizeMeta');
438+
done();
439+
});
440+
});
441+
});
442+
443+
it('creates the respective table', function (done) {
444+
const self = this;
445+
446+
prepare(() => {
447+
helpers.readTables(self.sequelize, (tables) => {
448+
expect(tables).to.have.length(2);
449+
expect(tables).to.contain('Person');
450+
done();
451+
});
452+
});
453+
});
454+
});
455+
});
456+
405457
describe(Support.getTestDialectTeaser('db:migrate'), () => {
406458
describe('optional migration parameters', () => {
407459
const prepare = function (runArgs = '', callback) {
@@ -626,3 +678,11 @@ function describeOnlyForESM(title, fn) {
626678
describe.skip(title, fn);
627679
}
628680
}
681+
682+
function describeOnlyForSQLite(title, fn) {
683+
if (Support.getTestDialect() === 'sqlite') {
684+
describe(title, fn);
685+
} else {
686+
describe.skip(title, fn);
687+
}
688+
}

0 commit comments

Comments
 (0)