Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sqlite url config not working with relative paths #1167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}