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
@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.
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
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
createDatabase and dropDatabase implement on PR https://github.com/sequelize/sequelize/pull/10027 and https://github.com/sequelize/sequelize/pull/10033
I'm trying to use these API to solve #698 .
@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.
Most helpful comment
I agree with @cjancsar. We need either silent creation failing in case of EXISTS or an option to force that behavior.