edgedb / edgedb-cli

The EdgeDB CLI
https://www.edgedb.com/docs/cli/index
Apache License 2.0
166 stars 23 forks source link

`project init` errors if using an existing instance that isn't running #324

Closed jaclarke closed 3 years ago

jaclarke commented 3 years ago

Steps to Reproduce:

$ edgedb project init
Found `edgedb.toml` in `/home/james/example`
Initializing project...
Specify the name of EdgeDB instance to use with this project [default: example_y1zk20g]:
> example_docker
Do you want to use existing instance "example_docker" for the project? [y/n]
> y
Applying migrations...
edgedb error: cannot establish connection for 30s: Connection refused (os error 111)

Since the CLI knows whether a named instance is running or not, it seems like it should start the existing instance before applying the migrations here, instead of assuming the instance is already running.

jaclarke commented 3 years ago

Also the same happens when using an existing 'native package' instance, though I'm not sure what the correct behaviour would be in this case since on WSL the CLI can't detect if the instance is running. It looks like it handles creating a new instance by starting it temporarily for the migrations:

$ edgedb project init
Found `edgedb.toml` in `/home/james/example`
Initializing project...
Specify the name of EdgeDB instance to use with this project [default: example_pn0w54b]:
> example_pn0w54b
Type a number to select an option:
How would you like to run EdgeDB for this project?
1. Local (native package)
2. Local (docker)
> 1
Checking EdgeDB versions...
┌────────────────────────┬─────────────────────────────────┐
│ Project directory      │ /home/james/example             │
│ Project config         │ /home/james/example/edgedb.toml │
│ Schema dir (non-empty) │ /home/james/example/dbschema    │
│ Installation method    │ Native System Package           │
│ Version                │ 1.0b1-2021030102~focal          │
│ Instance name          │ example_pn0w54b                 │
└────────────────────────┴─────────────────────────────────┘
Initializing EdgeDB instance...
Failed to connect to bus: No such file or directory
INFO 2353 2021-05-03 12:30:40,300 edb.server: EdgeDB server (1.0-beta.1+g2eee1afe4.d20210301) starting.
INFO 2353 2021-05-03 12:30:44,666 edb.server: Serving on 127.0.0.1:10703
INFO 2353 2021-05-03 12:30:44,666 edb.server: Serving on /home/james/.runstate/edgedb-example_pn0w54b/.s.EDGEDB.10703
INFO 2353 2021-05-03 12:30:44,666 edb.server: Serving admin on /home/james/.runstate/edgedb-example_pn0w54b/.s.EDGEDB.admin.10703
INFO 2353 2021-05-03 12:30:44,751 edb.server: Shutting down.
edgedb error: cannot create service: process "systemctl" "--user" "daemon-reload" failed: exit code: 1
Applying migrations...
INFO 2383 2021-05-03 12:30:46,782 edb.server: EdgeDB server (1.0-beta.1+g2eee1afe4.d20210301) starting.
INFO 2383 2021-05-03 12:30:51,255 edb.server: Serving on 127.0.0.1:10703
INFO 2383 2021-05-03 12:30:51,256 edb.server: Serving on /home/james/.runstate/edgedb-example_pn0w54b/.s.EDGEDB.10703
INFO 2383 2021-05-03 12:30:51,256 edb.server: Serving admin on /home/james/.runstate/edgedb-example_pn0w54b/.s.EDGEDB.admin.10703
Applied m17c3hvniaf7fexbanken722hubwzcnenyel42pp5xij6b4n6pnplq (00001.edgeql)
Applied m1vivy4blepytjuk7ycqsazo266t76yhg43cqwwsytl5qnb2dnflrq (00002.edgeql)
Applied m1nl5vl6vxhu42qstldlth42dubllgreeltxjbo7xktm2kfs72chpa (00003.edgeql)
INFO 2383 2021-05-03 12:30:55,372 edb.server: Shutting down.
Bootstrapping complete, but there was an error creating the service. You can run server manually via:
  edgedb server start --foreground example_pn0w54b

but I assume it can't do this for existing instances since it could already be running with --foreground.

Maybe it should attempt to connect, then if it can't show a message on how to start the instance for that system manually in another terminal, and then wait for the user to say they've done that (like a 'Press enter to continue' sort of prompt) before applying the migrations.

tailhook commented 3 years ago

Added a dialog:

Applying migrations...
edgedb error: cannot establish connection for 30s
Cannot connect to an instance "test2". What to do?
1. Start the service (if possible).
2. Start in the foreground, apply migrations and shutdown.
3. I have just started it manually. Try again!
4. Skip migrations.
Type a number to select an option:
> 2
Applying migrations...
INFO 4344 2021-05-04 13:53:10,568 edb.server: EdgeDB server (1.0-alpha.7+g85a3931a7.d20210113) starting.
INFO 4344 2021-05-04 13:53:15,456 edb.server: Serving on 127.0.0.1:10701
INFO 4344 2021-05-04 13:53:15,456 edb.server: Serving on /run/user/1000/edgedb-test2/.s.EDGEDB.10701
INFO 4344 2021-05-04 13:53:15,456 edb.server: Serving admin on /run/user/1000/edgedb-test2/.s.EDGEDB.admin.10701
Everything is up to date. Revision m14vtpxpzlxhxli4gz2fgpbggfwgo2zzxitxheevjqyym7x5rr7pgq
INFO 4344 2021-05-04 13:53:17,692 edb.server: Shutting down.
Project initialialized.
To connect to test2, just run `edgedb`