Expose GetEnvironment in sql-migrate Library (#22) #287
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.
Expose GetEnvironment in sql-migrate Library (#22)
Description
What is being done in this PR?
This PR resolves Issue #22 by making the
GetEnvironment
function available in thesql-migrate
library, enabling programmatic access to environment configurations in non-CLI applications. Previously,GetEnvironment
was internal to the CLI package (sql-migrate/sql-migrate
), limiting its use in non-webserver programs. The fix movesGetEnvironment
to the main library, ensuring compatibility with both CLI and library usage.Key changes:
GetEnvironment
to a newconfig.go
in the rootsql-migrate
package, exported for library use.sql-migrate/sql-migrate/config.go
,command_migrate.go
) to use the library’sGetEnvironment
.Config
andEnvironment
structs to be part of the library.config_test.go
) to verifyGetEnvironment
behavior for valid and invalid cases.What are the main choices made to get to this solution?
GetEnvironment
to a newconfig.go
in the root package to make it accessible without altering the library’s core structure.GetEnvironment
to make it public, following Go conventions, with parameters forconfigFile
andenv
.GetEnvironment
, ensuring no regression in CLI functionality.fmt.Errorf
with context for all errors (e.g., file not found, invalid YAML), improving debuggability.GetEnvironment
to cover valid configs, missing files, and missing environments, ensuring robustness.What was discovered while working on it?
GetEnvironment
in the CLI was tightly coupled with command-line argument parsing, requiring refactoring to be reusable in the library.config.go
was created to centralize environment handling.development
environment), which were preserved in the library function for consistency.