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

SQLite relative path doesn't work with URI #965

Open
jooohny opened this issue Sep 8, 2021 · 4 comments · May be fixed by #1167
Open

SQLite relative path doesn't work with URI #965

jooohny opened this issue Sep 8, 2021 · 4 comments · May be fixed by #1167
Labels

Comments

@jooohny
Copy link

jooohny commented Sep 8, 2021

I'm working on Windows. I have my config file in root\db-migration\config.js. Where root is my abstract working directory. And it contains the following:

module.exports = {
    development: {
        storage: 'private/db/db.sqlite3',
        dialect: 'sqlite',
    },
};

When I migrate everything is ok and database file appears in correct directory: root\private\db\db.sqlite3.
Once I'm trying to configure it as URI (and that's exactly what I need) like:

module.exports = {
    development: {
        url: 'sqlite:private/db/db.sqlite3',
    },
};

.. and I expect sequelize-cli to do exactly the same thing. But it creates directories in my disk : D:\db\db.sqlite3. Or in D:\private\db\db.sqlite3 if I specify url: 'sqlite:./private/db/db.sqlite3'. I've also tried some deviations with file: or something - I'm only getting errors or facing the same result.

@jooohny
Copy link
Author

jooohny commented Sep 13, 2021

Does anybody care at all?

@WikiRik
Copy link
Member

WikiRik commented Nov 11, 2021

Hi! Thanks for making an issue about this. This is due to the way that the URL is parsed for sqlite, see snippet below. Is there a reason that using storage and dialect instead of the URL is not possible?

parseDbUrl(urlString) {
let config = api.urlStringToConfigHash(urlString);
config = _.assign(config, {
dialect: config.protocol,
});
if (
config.dialect === 'sqlite' &&
config.database.indexOf(':memory') !== 0
) {
config = _.assign(config, {
storage: '/' + config.database,
});
}
return config;
},
};

@WikiRik WikiRik self-assigned this Nov 11, 2021
@jooohny
Copy link
Author

jooohny commented Nov 12, 2021

Hello. The reason is pretty clear: to use environment variable to keep DB connection string and set its value depending on environment in one place.

@WikiRik WikiRik added the bug label Nov 12, 2021
@WikiRik WikiRik removed their assignment Nov 12, 2021
@WikiRik
Copy link
Member

WikiRik commented Nov 12, 2021

Sounds fair, I will qualify this as a bug since you should be able to do this. A workaround is possible, but feel free to make a PR to solve this issue (or anyone else that reads this issue)

meufel pushed a commit to meufel/sequelize-cli that referenced this issue Sep 27, 2022
@meufel meufel linked a pull request Sep 27, 2022 that will close this issue
4 tasks
meufel pushed a commit to meufel/sequelize-cli that referenced this issue Sep 28, 2022
meufel pushed a commit to meufel/sequelize-cli that referenced this issue Sep 29, 2022
meufel pushed a commit to meufel/sequelize-cli that referenced this issue Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants