Skip to content

Make template support an optional provider interface - #7

Merged
bashhack merged 1 commit into
mainfrom
template-provider
Oct 22, 2026
Merged

bashhack merged 1 commit into
mainfrom
template-provider

Conversation

@bashhack

Copy link
Copy Markdown
Owner

Groundwork for a second database provider, in two small pieces.

TemplateProvider

CreateDatabaseFromTemplate and TemplateExists move from Provider into a new TemplateProvider interface that embeds it. PostgreSQL implements both. A provider for a database with no way to clone one database from another (MySQL) implements Provider alone instead of stubbing two methods with errors, and New returns ErrTemplatesNotSupported, naming the provider type, if WithTemplate is 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 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 (postgres.AdminDSNEnv); postgres.DefaultAdminDSN is now exported too. Postgres-only projects notice nothing.

Tests

A plainProvider test 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 that TEST_POSTGRES_URL wins and that the documented default is used when nothing is set.

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-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
testdb.go 83.33% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@bashhack
bashhack merged commit 34ee897 into main Oct 22, 2026
1 check passed
@bashhack
bashhack deleted the template-provider branch October 22, 2026 05:31
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

Successfully merging this pull request may close these issues.

2 participants