diff --git a/src/helpers/config-helper.js b/src/helpers/config-helper.js index c68c2934..b95fd733 100644 --- a/src/helpers/config-helper.js +++ b/src/helpers/config-helper.js @@ -205,7 +205,9 @@ const api = { config.database.indexOf(':memory') !== 0 ) { config = _.assign(config, { - storage: '/' + config.database, + storage: config.host.match(/^\.+$/) + ? config.database + : '/' + config.database, }); } diff --git a/test/db/migrate.test.js b/test/db/migrate.test.js index ddfae393..88c3f9bd 100644 --- a/test/db/migrate.test.js +++ b/test/db/migrate.test.js @@ -402,6 +402,60 @@ describe(Support.getTestDialectTeaser('db:migrate'), () => { }); }); +describeOnlyForSQLite(Support.getTestDialectTeaser('db:migrate'), () => { + ['sqlite:./test.sqlite', 'sqlite:../test.sqlite'].forEach((url) => { + describe(`with url option containing relative path to a local storage file: ${url}`, () => { + const prepare = function (callback) { + const config = { url }; + const configContent = 'module.exports = ' + JSON.stringify(config); + let result = ''; + + return gulp + .src(Support.resolveSupportPath('tmp')) + .pipe(helpers.clearDirectory()) + .pipe(helpers.runCli('init')) + .pipe(helpers.removeFile('config/config.json')) + .pipe(helpers.copyMigration('createPerson.js')) + .pipe(helpers.overwriteFile(configContent, 'config/config.js')) + .pipe(helpers.runCli('db:migrate')) + .on('error', (e) => { + callback(e); + }) + .on('data', (data) => { + result += data.toString(); + }) + .on('end', () => { + callback(null, result); + }); + }; + + it('creates a SequelizeMeta table', function (done) { + const self = this; + + prepare(() => { + helpers.readTables(self.sequelize, (tables) => { + expect(tables).to.have.length(2); + expect(tables).to.contain('SequelizeMeta'); + done(); + }); + }); + }); + + it('creates the respective table', function (done) { + const self = this; + + prepare(() => { + helpers.readTables(self.sequelize, (tables) => { + expect(tables).to.have.length(2); + expect(tables).to.contain('Person'); + done(); + }); + }); + }); + }); + }); +}); + describe(Support.getTestDialectTeaser('db:migrate'), () => { describe('optional migration parameters', () => { const prepare = function (runArgs = '', callback) { @@ -626,3 +680,11 @@ function describeOnlyForESM(title, fn) { describe.skip(title, fn); } } + +function describeOnlyForSQLite(title, fn) { + if (Support.getTestDialect() === 'sqlite') { + describe(title, fn); + } else { + describe.skip(title, fn); + } +}