Repository navigation
Make template support an optional provider interface - #7
Merged
Merged
Conversation
CreateDatabaseFromTemplate and TemplateExists move from Provider into TemplateProvider. PostgreSQL implements both; a provider for a database with no way to clone one database from another implements Provider alone, and New returns ErrTemplatesNotSupported, naming the provider, before touching the server if WithTemplate is used with it. ResolveAdminDSN takes the provider's own environment variables, tried before the shared TEST_DATABASE_URL and DATABASE_URL, so a project that tests against two database servers can point each provider at its own. PostgreSQL's is TEST_POSTGRES_URL.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Groundwork for a second database provider, in two small pieces.
TemplateProviderCreateDatabaseFromTemplateandTemplateExistsmove fromProviderinto a newTemplateProviderinterface that embeds it. PostgreSQL implements both. A provider for a database with no way to clone one database from another (MySQL) implementsProvideralone instead of stubbing two methods with errors, andNewreturnsErrTemplatesNotSupported, naming the provider type, ifWithTemplateis used with it. The check runs before the provider is initialized: it is a configuration error, not a connection problem.Per-provider admin DSN variable
ResolveAdminDSN(cfg, default, providerEnv...)tries the provider's own variables before the sharedTEST_DATABASE_URLandDATABASE_URL, so a project that tests against two database servers can point each provider at its own. PostgreSQL's isTEST_POSTGRES_URL(postgres.AdminDSNEnv);postgres.DefaultAdminDSNis now exported too. Postgres-only projects notice nothing.Tests
A
plainProvidertest double that deliberately lacks the template methods proves the refusal (and that the provider is never initialized), a table test pins the full resolution order, and the postgres package checks thatTEST_POSTGRES_URLwins and that the documented default is used when nothing is set.