Skip to content

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

Closed

Description

@framled

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

Activity

  1. Telokis commented on May 7, 2018

    @Telokis

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

  2. Telokis commented on May 10, 2018

    @Telokis

    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

  3. sushantdhiman commented on May 11, 2018

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

  4. ALiangLiang commented on Oct 16, 2018

    @ALiangLiang
    Contributor

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

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

  5. cjancsar commented on Jun 26, 2019

    @cjancsar

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

  6. anatollix commented on Jul 5, 2019

    @anatollix

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

  7. Bossorcain commented on Dec 21, 2022

    @Bossorcain

    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.

  8. simonebenati commented on Jul 21, 2023

    @simonebenati

    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

  9. ledenis commented on Aug 23, 2023

    @ledenis

    It seems this issue is not fixed for postgres

  10. WikiRik commented on Aug 23, 2023

    @WikiRik
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions