You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
db:create should not fail if the database does exist #629
@sushantdhiman Would you accept PRs for this issue? I was thinking of simply adding the IF NOT EXIST in the query by default but this could also be handled with a --if-not-exists option.
To correctly solve this you need to add createDatabase and dropDatabase to query interface, where based on dialect / version you can skip or add IF NOT EXISTS.
@ALiangLiang and @sushantdhiman was this functionality added? If so, what is the option to pass? If it wasn't added, why was this issue closed? I think this should be re-opened.
I agree with @cjancsar. We need either silent creation failing in case of EXISTS or an option to force that behavior.
Reacted by Cole Jancsar, Mike Blackstock, Leo Doldan, Hans Brito, wedaren, joschefski, Chris Shepherd, Vinícius Fraga Modesto, Kaushik Sridasyam, Vinay Valiyaparambil and 2 more
Hello, I am in need of this function as I'm trying to integrate the creation of dbs in my code if they don't exist but if they already exist it shouldn't throw an error and exit the code, in order to continue with the commands
Activity
Telokis commentedon May 7, 2018
@sushantdhiman Would you accept PRs for this issue? I was thinking of simply adding the
IF NOT EXISTin the query by default but this could also be handled with a--if-not-existsoption.Telokis commentedon May 10, 2018
Ok, I just tried doing this but it is more complicated that it seems.
You can see what I tried on my fork (https://github.com/Telokis/cli/blob/eb5d4b7e7981304cfae1cb584c27782c201e38e9/src/commands/database_create.js#L26).
The issue is that postgres does not support
EXISTS.A possible solution would be to check the error message for the word "exists" and to return without error if it does.
I'd like to hear your opinion, @sushantdhiman
sushantdhiman commentedon May 11, 2018
To correctly solve this you need to add
createDatabaseanddropDatabaseto query interface, where based on dialect / version you can skip or addIF NOT EXISTS.I will accept such PR for sequelize
ALiangLiang commentedon Oct 16, 2018
createDatabaseanddropDatabaseimplement on PR sequelize/sequelize#10027 and sequelize/sequelize#10033I'm trying to use these API to solve #698 .
cjancsar commentedon Jun 26, 2019
@ALiangLiang and @sushantdhiman was this functionality added? If so, what is the option to pass? If it wasn't added, why was this issue closed? I think this should be re-opened.
anatollix commentedon Jul 5, 2019
I agree with @cjancsar. We need either silent creation failing in case of EXISTS or an option to force that behavior.
Bossorcain commentedon Dec 21, 2022
Is there any recent informations about this behaviour? It does not seem to work as expected with:
Dialect: postgres
Sequelize CLI version: 6.5.2
Sequelize version: 6.25.5
It still throws an error in case of an existing database.
simonebenati commentedon Jul 21, 2023
Hello, I am in need of this function as I'm trying to integrate the creation of dbs in my code if they don't exist but if they already exist it shouldn't throw an error and exit the code, in order to continue with the commands
ledenis commentedon Aug 23, 2023
It seems this issue is not fixed for postgres
WikiRik commentedon Aug 23, 2023
Indeed this has not been fixed for postgres. Feel free to create a new issue or add support for it through a PR.