postgres: db:create should not fail if the database does exist

Open
#1,368 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js, postgresql
Domain
cli, databases

Research direction

Start with the sequelize db:create entry point and reproduce the issue using the PostgreSQL Docker command and URL shown. Trace the PostgreSQL database-creation path and verify that running the command a second time exits successfully when the database already exists.

Written by the indexing model from the issue text.

Description

What you are doing?

To reproduce:

Launch a postgres database:

docker run -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:11

Create a directory with this package.json:

{
  "name": "sequelize-test",
  "scripts": {
    "db:create": "sequelize db:create --url 'postgres://postgres:password@localhost:5432/database'"
  },
  "dependencies": {
    "pg": "8.11.3",
    "sequelize": "6.32.1",
    "sequelize-cli": "6.6.1"
  }
}

Then run:

$ npm i
$ npm run db:create

> db:create
> sequelize db:create --url 'postgres://postgres:password@localhost:5432/database'


Sequelize CLI [Node: 18.16.1, CLI: 6.6.1, ORM: 6.32.1]

Parsed url postgres://postgres:*****@localhost:5432/database
Database database created.

$ npm run db:create

> db:create
> sequelize db:create --url 'postgres://postgres:password@localhost:5432/database'


Sequelize CLI [Node: 18.16.1, CLI: 6.6.1, ORM: 6.32.1]

Parsed url postgres://postgres:*****@localhost:5432/database

ERROR: database "database" already exists

What do you expect to happen?

The second db:create should not fail with an error

What is actually happening?

The second db:create is failing with an error : database "database" already exists

A previous issue was intended to address it but was closed: https://github.com/sequelize/cli/issues/629

Dialect: postgres
Database version: 11
Sequelize CLI version: 6.6.1
Sequelize version: 6.32.1

Dominant language
JavaScript
Stars
2.6k
Forks
524
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sequelize/cli

All issues in sequelize/cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.