Skip to content

Architecture

dbsh is built as a layered .NET solution with clear separation of concerns.

Project structure

dbsh/
  src/
    dbsh.Core/             Pure domain model (zero dependencies)
    dbsh.Engine/           Script parsing, migration execution
    dbsh.Infrastructure/   Database providers, file system config
    dbsh.CLI/              The dbsh executable
  tests/
    dbsh.Engine.Tests/     Unit + integration tests

Layer diagram

┌──────────────────────────────────────────┐
│              dbsh.CLI                 │
│   Program.cs · Commands · ConsoleHelper  │
└──────────────────┬───────────────────────┘
                   │ uses
        ┌──────────┴─────────┐     ┌──────────────────┐
        │    Engine          │     │      Core         │
        │ ScriptParser       │────▶│ Entities · Enums  │
        │ MigrationExec      │     │ ValueObjects      │
        │ InMemory impls     │     └──────────────────┘
        └──────────┬─────────┘              ▲
                   │ implements             │ implements
    ┌──────────────┴────────────────────────┴───────────────┐
    │                  Infrastructure                       │
    │  Providers/                                           │
    │    PostgreSql · SqlServer · MySql · Sqlite            │
    │  Relational{Tracker, LockManager, Executor, Audit}    │
    │  FileSystemConfigLoader                               │
    └───────────────────────────────────────────────────────┘

Core (dbsh.Core)

Pure domain model with zero external dependencies.

NamespaceKey Types
EntitiesMigrationRecord, MigrationAuditEntry, MigrationLock
EnumsMigrationStatus, MigrationType, AuditAction
InterfacesIMigrationTracker, IMigrationLockManager, IAuditLogger, IEnvironmentProvider, IMigrationScriptExecutor, IConfigLoader
ValueObjectsMigrationConfiguration, EnvironmentConfiguration, DeploymentWindow, ParsedMigration, MigrationContext
ExceptionsdbshException, ScriptParseException, MigrationConfigurationException, UnsupportedProviderException

Engine (dbsh.Engine)

Application core that orchestrates the migration workflow.

ClassResponsibility
ScriptParserParses Flyway-style filenames, generates SHA-256 hashes (LF-normalized), extracts metadata headers, validates content
MigrationExecutorOrchestrates validation, planning, deployment, rollback, and repair. Coordinates tracker, lock manager, audit log, environment provider, and script executor
InMemoryMigrationTrackerIn-memory test double for offline workflows
InMemoryMigrationLockManagerIn-memory lock manager
InMemoryAuditLoggerIn-memory audit logger

Infrastructure (dbsh.Infrastructure)

Database-specific implementations and file system access.

ClassResponsibility
PostgreSqlProviderPostgreSQL via Npgsql. Schema-based module isolation. Lock: INSERT ... ON CONFLICT DO UPDATE
SqlServerProviderSQL Server via Microsoft.Data.SqlClient. Schema-based module isolation. Lock: MERGE ... WITH (HOLDLOCK)
MySqlProviderMySQL via MySqlConnector. Table-prefix module isolation. Lock: INSERT ... ON DUPLICATE KEY UPDATE
SqliteProviderSQLite via Microsoft.Data.Sqlite. Table-prefix module isolation. Lock: INSERT ... ON CONFLICT DO UPDATE
RelationalMigrationTrackerProvider-agnostic history tracking using System.Data.Common
RelationalMigrationLockManagerRow-based distributed lock with lease expiry
FileSystemConfigLoaderLoads migration.json and environments/*.json, expands ${VAR} tokens

CLI (dbsh.CLI)

The dbsh executable built with Spectre.Console.Cli.

ClassResponsibility
ProgramEntry point, command registration
CliCommandBaseShared helpers for all commands
CliHostComposition root — resolves providers, wires implementations
ConsoleHelperSpectre.Console UI: banners, tables, spinners, gradient text
ThemeColor palette and glyphs

Adding a new provider

Every database-specific behavior is encapsulated behind IDatabaseProvider. Adding a new provider requires implementing this single interface. The Relational* classes use System.Data.Common base types (DbConnection, DbCommand, DbDataReader) so the same code path works across all engines.

Released under the MIT License.