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

Running ghost config without params appears to wipe database #1896

Open
ErisDS opened this issue Nov 8, 2024 · 7 comments
Open

Running ghost config without params appears to wipe database #1896

ErisDS opened this issue Nov 8, 2024 · 7 comments

Comments

@ErisDS
Copy link
Member

ErisDS commented Nov 8, 2024

Summary

It seems that typing 'ghost config' without an argument, at least while in development mode, apparently wipes the database and resets everything.  This is very unexpected

Steps to Reproduce

  1. Use Ghost CLI to install a site locally
  2. Run ghost config without a param
  3. Try to do something else

If arguments are required, the command should output some help, not perform a distructive action

@vikaspotluri123
Copy link
Member

I'll probably take a look tomorrow

@vikaspotluri123
Copy link
Member

Was your db set to a non-default path by chance? Calling config without any arguments (incorrectly) runs config with the default values, but I'm not able to repro/trace it deleting e.g. a database 😕

@cathysarisky
Copy link

cathysarisky commented Nov 12, 2024

I have accidentally triggered this behavior. Will see if I can do so again. :)

(It's very possible that config with the wrong arguments looks a lot like deleting... Yeah, I think it's an accidental switch of database location, causing a reinitialization of the db. Which is better than a data wipe, to be sure.)

@acburdine
Copy link
Member

acburdine commented Nov 14, 2024

ok I replicated this locally and figured out what's going on:

step 1 - ghost install local

outputs this config.development.json:

{
  // other fields omitted for brevity
  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/Users/acburdine/code/ghost/sandbox/content/data/ghost-local.db"
    }
  }
}

then running ghost config with no arguments updates config.development.json to this:

{
  // other fields omitted for brevity
  "database": {
    "client": "sqlite3",
    "connection": {
      "filename": "/Users/acburdine/code/ghost/sandbox/content/data/ghost-dev.db"
    }
  }
}

so the sqlite db path is getting changed from ghost-local.db to ghost-dev.db.

there's definitely a quick fix here to avoid changing the db path, but I'm wondering if there isn't a better way to have the ghost config handle no arguments being passed. One thought I had was that if someone runs ghost config with no arguments it starts prompting the user for values, using the existing config values as the defaults. 🤔

@cathysarisky
Copy link

Channeling my noob self (some of you may assert that I do this all of the time...) I might type ghost config as a way to figure out what the arguments were. I've seen just enough command line utils treat missing args as the same as --help.

Walking through all the options would be OK (with existing config given), but it might be equally helpful if the output told me that Ghost was already at least partially configured and provided the output of ghost config --help, so that I could pick the option I was actually wanting, rather than walking through them all.

The current output of ghost config --help is ok, but it would be even more helpful if it told me what keys were possible. Or is that's too much, it could give me a url to see all the keys or some common usage examples.

@acburdine
Copy link
Member

acburdine commented Nov 14, 2024

hmm that's not a bad option - if no args are passed, simply output the available config args with the current values in the config if set

that fixes half of the issue, the other half is to make it so the "default" values for those flags are derived from the config if it already exists, so that if you run ghost config --url <whatever>, it only updates the url and doesn't change any of the other values

Should be able to get a PR up for this tomorrow or Friday

@vikaspotluri123
Copy link
Member

@acburdine #1902 is a draft for the first half - feel free to take it over.

I was thinking the same thing for the second half - we don't have a simple way right now to detect if the default value was used or the user passed the default value (I think).

Does it make sense that a fresh install defaults to ghost-local.db while the default config defaults to ghost-dev.db?

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

No branches or pull requests

4 participants