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
GetEnvironmentfunction available in thesql-migratelibrary, enabling programmatic access to environment configurations in non-CLI applications. Previously,GetEnvironmentwas internal to the CLI package (sql-migrate/sql-migrate), limiting its use in non-webserver programs. The fix movesGetEnvironmentto the main library, ensuring compatibility with both CLI and library usage.Key changes:
GetEnvironmentto a newconfig.goin the rootsql-migratepackage, exported for library use.sql-migrate/sql-migrate/config.go,command_migrate.go) to use the library’sGetEnvironment.ConfigandEnvironmentstructs to be part of the library.config_test.go) to verifyGetEnvironmentbehavior for valid and invalid cases.What are the main choices made to get to this solution?
GetEnvironmentto a newconfig.goin the root package to make it accessible without altering the library’s core structure.GetEnvironmentto make it public, following Go conventions, with parameters forconfigFileandenv.GetEnvironment, ensuring no regression in CLI functionality.fmt.Errorfwith context for all errors (e.g., file not found, invalid YAML), improving debuggability.GetEnvironmentto cover valid configs, missing files, and missing environments, ensuring robustness.What was discovered while working on it?
GetEnvironmentin the CLI was tightly coupled with command-line argument parsing, requiring refactoring to be reusable in the library.config.gowas created to centralize environment handling.developmentenvironment), which were preserved in the library function for consistency.