Skip to content

Add Migrator.EnsureDatabaseExistsAsync() for lightweight database creation#217

Merged
jeremydmiller merged 1 commit into
masterfrom
ensure-database-exists
Feb 16, 2026
Merged

Add Migrator.EnsureDatabaseExistsAsync() for lightweight database creation#217
jeremydmiller merged 1 commit into
masterfrom
ensure-database-exists

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Summary

  • Adds Migrator.EnsureDatabaseExistsAsync(DbConnection, CancellationToken) as a virtual method on the base Migrator class, with provider-specific overrides for all five database providers
  • Enables Wolverine multi-tenancy to create databases without relying on EF Core's EnsureCreatedAsync(), which does extra work that interferes with Wolverine (addresses Migrator.EnsureDatabaseExistsAsync() API for easier EF Core testing #211)
  • Each provider uses the lightest-weight approach: SQLite is a no-op, PostgreSQL checks via DatabaseExists() + DatabaseSpecification, SQL Server uses DB_ID() + CREATE DATABASE, MySQL uses atomic CREATE DATABASE IF NOT EXISTS, and Oracle runs the existing idempotent CreateSchemaStatementFor() PL/SQL block

Test plan

  • SQLite tests pass (ensure_database_exists_is_noop_for_memory, ensure_database_exists_is_noop_for_file)
  • Core tests pass
  • PostgreSQL integration tests (can_ensure_database_that_does_not_exist, ensure_database_is_idempotent) — requires Docker
  • SQL Server integration tests (can_ensure_database_that_does_not_exist, ensure_database_is_idempotent) — requires Docker
  • MySQL integration tests (can_ensure_database_that_does_not_exist, ensure_database_is_idempotent) — requires Docker
  • Oracle integration test (ensure_database_is_idempotent) — requires Docker

🤖 Generated with Claude Code

…ation

Adds a virtual method to ensure a database exists without running schema
migrations or DDL, addressing the need for Wolverine multi-tenancy to
create databases without EF Core's EnsureCreatedAsync() side effects.

Each provider implements the appropriate strategy:
- SQLite: no-op (auto-creates on connection open)
- PostgreSQL: connects to 'postgres' DB, checks/creates via DatabaseSpecification
- SQL Server: connects to 'master', checks via DB_ID(), creates with CREATE DATABASE
- MySQL: atomic CREATE DATABASE IF NOT EXISTS
- Oracle: runs idempotent CreateSchemaStatementFor() PL/SQL block

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 906f177 into master Feb 16, 2026
14 of 21 checks passed
@jeremydmiller jeremydmiller deleted the ensure-database-exists branch February 16, 2026 18:06
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.

1 participant