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

DATABASE_URL support #337

Closed
jney opened this issue Jan 17, 2016 · 11 comments
Closed

DATABASE_URL support #337

jney opened this issue Jan 17, 2016 · 11 comments
Labels

Comments

@jney
Copy link

jney commented Jan 17, 2016

As i read the doc DATABASE_URL env var is supported.
But, using db-migrate i accountered some awkward behaviours. Or i missed something.

$ echo $DATABASE_URL
postgres://[email protected]:5432/test
$ ./node_modules/.bin/db-migrate db:create
[INFO] Error: You must enter a database name!

At this point, why should i declare the db name as it is already explicitly declared in the DATABASE_URL var ?

$ ./node_modules/.bin/db-migrate db:create test
[ERROR] error: database "test" does not exist
  at [object Object].Connection.parseE (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:534:11)
  at [object Object].Connection.parseMessage (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:361:17)
  at Socket.<anonymous> (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:105:22)
  at emitOne (events.js:77:13)
  at Socket.emit (events.js:169:7)
  at readableAddChunk (_stream_readable.js:146:16)
  at Socket.Readable.push (_stream_readable.js:110:10)
  at TCP.onread (net.js:523:20)

Sure test does exist, i'm trying to create it.

@wzrdtales
Copy link
Member

Please provide the information you get from the verbose run. You start the verbose run by appending -v as parameter.

@wzrdtales
Copy link
Member

Also to add, if test wouldn't exist, this error wouldn't be thrown. If it already exists there is no need for you to execute this command.

And about the specified db, no this is not the way how this command should work. You're creating a new database with this command, while the configuration expects that this already exists. Thus this is clearly out of scope for db:create, maybe we can additionally add something like db:init, as this is initialization you talk about.

@wzrdtales
Copy link
Member

And last but not least, also always provide:

Used

  • node version
  • npm version
  • db-migrate version

@jney
Copy link
Author

jney commented Jan 17, 2016

./node_modules/.bin/db-migrate -v db:create test
[INFO] Using urlConfig settings: { driver: 'postgres',
  user: 'postgres',
  database: 'test',
  host: '0.0.0.0',
  port: '5432' }
[INFO] require: ./postgres
[INFO] connecting
[INFO] connected
[SQL] CREATE DATABASE "test"
[ERROR] error: database "test" does not exist
  at [object Object].Connection.parseE (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:534:11)
  at [object Object].Connection.parseMessage (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:361:17)
  at Socket.<anonymous> (/home/me/src/project/node_modules/db-migrate/node_modules/pg/lib/connection.js:105:22)
  at emitOne (events.js:77:13)
  at Socket.emit (events.js:169:7)
  at readableAddChunk (_stream_readable.js:146:16)
  at Socket.Readable.push (_stream_readable.js:110:10)
  at TCP.onread (net.js:523:20)

@wzrdtales
Copy link
Member

Yes, as suspected nothing wrong with this, test clearly already exists. Just don't use create if this already exists. This information also does not come from db-migrate, but the driver itself, db-migrate did its job to completion.

@jney
Copy link
Author

jney commented Jan 17, 2016

@wzrdtales i don't get it the previous message clearly says [ERROR] error: database "test" does not exist and :

$ psql postgres://[email protected]:5432/test
psql: FATAL:  database "test" does not exist

@wzrdtales
Copy link
Member

oh, ok, really have not seen the not, sry. This is because db-migrate always tries to connect to a database specified. This error is caused by your provided url which tries to connect to test. This is something that needs to be added, but in this case this is probably still an init instead of a create operation. Nevertheless, to have command execution supported without actually connecting to a database is in some cases not that unproblematic.
In case of MySQL/MariaDB this is easy, connecting without a database specified is not a problem at all. But for example postgres does always connect to some db. If no db is specified it uses the username of the executing user. Thus this probably has to be the default database that always exists.

@wzrdtales
Copy link
Member

@jney I have opened this as issue(task), #338.

@wzrdtales
Copy link
Member

@jney convenience feature for initialization also added as issue(task), #339

@wzrdtales
Copy link
Member

Closing this issue from here with those new items in place.

@jney
Copy link
Author

jney commented Jan 17, 2016

thank you 👍

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

No branches or pull requests

2 participants