Skip to content

Commit

Permalink
fix: sqlite url config not working with relative paths
Browse files Browse the repository at this point in the history
Closes #965
  • Loading branch information
meufel committed Sep 29, 2022
1 parent 6412ab6 commit a81fb8b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/helpers/config-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}

Expand Down
62 changes: 62 additions & 0 deletions test/db/migrate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit a81fb8b

Please sign in to comment.