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

ddev debug migrate-database mariadb:10.11 altered config.yaml more than needed #6847

Open
hanoii opened this issue Dec 20, 2024 · 9 comments

Comments

@hanoii
Copy link
Collaborator

hanoii commented Dec 20, 2024

I ran this command for the first time ever:

ddev debug migrate-database mariadb:10.11

All went fine but then I noticed the changed config.yaml had more than it should.

It basically brought in all changes by the add-ons present in the project, so the updated config.yaml was the merged result of all config.*.yaml present on this project.

Expected Behavior

Only mariadb should change, along with maybe what ddev config --auto or ddev config --update does, but definitely not altering it based on other config.*.yaml files.

@rfay
Copy link
Member

rfay commented Dec 20, 2024

Can you be more specific about what changed please? (Note that ddev debug migrate-database is in the debug section for a reason :)

I imagine you're seeing a general bug with use of config and specific parameters.

@hanoii
Copy link
Collaborator Author

hanoii commented Dec 20, 2024

In this particular project, I only had https://github.com/hanoii/ddev-pimp-my-shell/blob/f8edb376716397863bd21dbfa2644895b2866b6d/config.pimp-my-shell.yaml, and all of that appeared on the main config.yaml file along the db change. webimage_extra_packages was even formatted as a single line array.

@rfay
Copy link
Member

rfay commented Dec 20, 2024

I am surprised. Thanks.

@rfay
Copy link
Member

rfay commented Dec 21, 2024

I can reproduce this with your exact case.

The reason is that we use GetActiveApp() in

app, err := ddevapp.GetActiveApp("")

That's the full app, including config.*.yaml

Then we naively write the config back in

app.Database.Type = typeVals[0]
app.Database.Version = typeVals[1]
err = app.WriteConfig()

And what writes the whole thing.

I'm not sure what the exact fix is, but in this particular case we could do app.ReadConfig("", false) and change the database type and write. That, unfortunately, would miss the possible case where the database type and version were specified in config.*.yaml

@GuySartorelli
Copy link
Contributor

Is there a mechanism to identify which config file contains a given setting?

@rfay
Copy link
Member

rfay commented Dec 22, 2024

No, I don't think so. app.ReadConfig has the includeOverrides arg:

ddev/pkg/ddevapp/config.go

Lines 314 to 338 in 7a0c06c

func (app *DdevApp) ReadConfig(includeOverrides bool) ([]string, error) {
// Load base .ddev/config.yaml - original config
err := app.LoadConfigYamlFile(app.ConfigPath)
if err != nil {
return []string{}, fmt.Errorf("unable to load config file %s: %v", app.ConfigPath, err)
}
configOverrides := []string{}
// Load config.*.y*ml after in glob order
if includeOverrides {
glob := filepath.Join(filepath.Dir(app.ConfigPath), "config.*.y*ml")
configOverrides, err = filepath.Glob(glob)
if err != nil {
return []string{}, err
}
for _, item := range configOverrides {
err = app.mergeAdditionalConfigIntoApp(item)
if err != nil {
return []string{}, fmt.Errorf("unable to load config file %s: %v", item, err)
}
}
}

It would be a bit of a violation for DDEV to touch a config.*.yaml though, as those aren't ever changed by DDEV directly.

@hanoii
Copy link
Collaborator Author

hanoii commented Dec 22, 2024

I'm not sure what the exact fix is, but in this particular case we could do app.ReadConfig("", false) and change the database type and write.

I think this is OK, isn't this the same that ddev config --update does?

That, unfortunately, would miss the possible case where the database type and version were specified in config.*.yaml

I think that this is also currently the case: assume a mariadb of 10.4 on config.yaml, and a mariadb of 10.6 on config.db.yaml, running ddev debug migrate-database mariadb:10.11 would write 10.11 to config.yaml, but config.db.yaml would still be 10.6 which would continue to overwrite it.

It would be a bit of a violation for DDEV to touch a config.*.yaml though, as those aren't ever changed by DDEV directly.

Agreed, and the same reasoning should apply the other way around, it shouldn't care of what config.*.yaml does. So, if a config.something.yaml set a specific db (which I think should be very very rare), then there should be a reason for doing so even though the migration will be attempted, the config.something.yaml will continue to leave the db as it expects it to. At that case is up for the user to decide what to do.

Anything further I think is overcomplicating things. We could, if it's possible, process all config.*.yaml files independently in the same way we are doing now (without the main config.yaml( and then check to see if a db is being set, and warn accordingly.

But I think it's too much for a debug command.

@rfay
Copy link
Member

rfay commented Dec 22, 2024

It would probably be legit for ddev debug migrate-database to app.ReadConfig(false), then change the type/version, then do its job. That seems like a modest one-line change here that is in an off-the-beaten-track place. But one has to wonder where else this conflict might exist (read with includeOverrides, then write config). It doesn't seem like with current informal policies this is an easily solvable problem. But I think it would be fine to solve it here.

@GuySartorelli
Copy link
Contributor

Perhaps if the database isn't in the main config file there could be a message output to the terminal that no change was made.

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

3 participants