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

db:create should not fail if the database does exist #629

Closed
framled opened this issue Mar 15, 2018 · 10 comments · Fixed by #700
Closed

db:create should not fail if the database does exist #629

framled opened this issue Mar 15, 2018 · 10 comments · Fixed by #700
Labels

Comments

@framled
Copy link

framled commented Mar 15, 2018

What you are doing?

$ sequelize db:create

What do you expect to happen?

When the database does exist, I expect the command to exit with status code 0

What is actually happening?

The command fails with exit code 1

Dialect: mysql
Sequelize CLI version: 4.0.0
Sequelize version: 4.36.1

@Telokis
Copy link

Telokis commented May 7, 2018

@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.

@Telokis
Copy link

Telokis commented 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
Copy link
Contributor

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.

I will accept such PR for sequelize

@ALiangLiang
Copy link
Contributor

ALiangLiang commented Oct 16, 2018

createDatabase and dropDatabase implement on PR sequelize/sequelize#10027 and sequelize/sequelize#10033

I'm trying to use these API to solve #698 .

@cjancsar
Copy link

cjancsar commented 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
Copy link

I agree with @cjancsar. We need either silent creation failing in case of EXISTS or an option to force that behavior.

@Bossorcain
Copy link

Bossorcain commented 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
Copy link

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
Copy link

ledenis commented Aug 23, 2023

It seems this issue is not fixed for postgres

@WikiRik
Copy link
Member

WikiRik commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
10 participants