Skip to content

Commit 4b89ad7

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

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/helpers/config-helper.js

+3-1
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

+62
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,60 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => {
402402
});
403403
});
404404

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

0 commit comments

Comments
 (0)