feat: Set table name based on flag or environment variable#932
Merged
mfridman merged 3 commits intopressly:mainfrom Apr 3, 2025
Merged
feat: Set table name based on flag or environment variable#932mfridman merged 3 commits intopressly:mainfrom
mfridman merged 3 commits intopressly:mainfrom
Conversation
Collaborator
|
I think this seems reasonable, will take a pass in the next few days. |
mfridman
reviewed
Apr 3, 2025
cmd/goose/main.go
Outdated
| goose.SetTableName(*table) | ||
|
|
||
| // Envvars should have lower priority than flags. | ||
| goose.SetTableName(firstNonEmpty(*table, envConfig.table)) |
Collaborator
There was a problem hiding this comment.
I don't think this will work, since *table will be set to the default from line 31:
flags.String("table", "goose_db_version", "migrations table name")
I think what might work here is:
- goose.SetTableName(firstNonEmpty(*table, envConfig.table))
+ goose.SetTableName(firstNonEmpty(*table, envConfig.table, "goose_db_version"))And then remove the flag default:
- table = flags.String("table", "goose_db_version", "migrations table name")
+ table = flags.String("table", "", "migrations table name")I believe that should maintain the order of precedence of flag > env > default.
Contributor
Author
There was a problem hiding this comment.
Thanks for looking into this @mfridman! I’ve made a change that should fix it. Please let me know if there are any other changes.
Replaced the hardcoded DefaultTable variable with the goose package's DefaultTablename. This ensures a single source of truth for the default table name and improves maintainability.
Collaborator
|
Thank you for the contribution, lgtm. |
Contributor
Author
|
Thanks @mfridman! Do you have any estimates of when a new release might be created? |
Collaborator
|
Within the next few weeks, I typically try and stagger the releases to avoid too many updates on consumers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Created a new environment variable,
GOOSE_TABLE, that enables users to configure a custom table name. Updated theSetTableNamelogic to prioritize flags over the new environment variable, following the previous behaviour for other env vars. Implemented a helper function,firstNonEmpty, to facilitate flexible value selection. Wrote unit tests to validate the function. Updated theREADME.mdwith the newly createGOOSE_TABLEenvironment variable.Example:
Please let me know if any other change is required.