datntdev.SchemaVersioner 1.1.1

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package datntdev.SchemaVersioner --version 1.1.1
                    
NuGet\Install-Package datntdev.SchemaVersioner -Version 1.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="datntdev.SchemaVersioner" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="datntdev.SchemaVersioner" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="datntdev.SchemaVersioner" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add datntdev.SchemaVersioner --version 1.1.1
                    
#r "nuget: datntdev.SchemaVersioner, 1.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package datntdev.SchemaVersioner@1.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=datntdev.SchemaVersioner&version=1.1.1
                    
Install as a Cake Addin
#tool nuget:?package=datntdev.SchemaVersioner&version=1.1.1
                    
Install as a Cake Tool

datntdev - SchemaVersioner

Quality Gate Status Coverage Vulnerabilities

datntdev.SchemaVersioner provides a robust solution for database schema management, ensuring that changes are applied consistently across different environments. It supports versioned migrations to track incremental changes and repeatable migrations for objects like views or stored procedures that might be updated frequently. The tool is designed to work on various database engines.

Core Components

  • datntdev.SchemaVersioner: The core class library (found in src/datntdev.SchemaVersioner/) containing the logic for discovering, tracking, and applying database migrations. This package can be installed into your .NET Application which provides a programmatically approach to migrate your databases from your application.
  • datntdev.SchemaVersioner.Cli: A command-line interface (CLI) tool (found in src/datntdev.SchemaVersioner.Cli/) that utilizes the core library to perform schema versioning operations. This allows for easy integration into build and deployment pipelines.

Key Features

  • Initialize New Database: Set up a new database using snapshot scripts.
  • Erase Database: Completely clear a database (use with extreme caution).
  • Validate Migrations: Check consistency between migration scripts and metadata.
  • Repair Metadata: Reconcile the metadata table based on available migration scripts.
  • Targeted Versioning: Upgrade or downgrade to a specific database version.
  • Migrate to Latest: Apply all pending migrations to bring the database to the most recent version.
  • Schema Snapshot Generation: Create scripts representing the current schema for supported databases.
  • CLI Tool for CI/CD Pipeline: Easily script and automate database migration processes.

Supported Database Engines

Database Initialize Command Erase Command Validate Command Repair Command Upgrade Command Downgrade Command Snapshot Command
SQLite ✅ ✅ ✅ ✅ ✅ ✅ ✅
MsSQL ✅ ✅ ✅ ✅ ✅ ✅ ✅
Ms Fabric ✅ ✅ ✅ ✅ ✅ ✅ ✅
PostgreSQL ✅ ✅ ✅ ✅ ✅ ✅ ❌

Getting Started

Prerequisites

  • For development with Nuget Package: .NET SDK 8.0 or later
  • For CLI tool usage: Windows - 64bit

Installation

  • CLI Tool: Download the appropriate version for your platform from latest release

  • Nuget Package: For using the library in your project

    dotnet add package datntdev.SchemaVersioner
    

Getting Started with CLI

A simple example of SQLite database which init a new database with a snapshot script. This command will initialize the database with the schema defined in the snapshot scripts located in Resources/SQLite/Snapshots and apply any migrations found in Resources/SQLite/Migrations as a metadata table to avoid running all migration versions for the next time of upgrade version.

datntdev.SchemaVersioner.Cli.exe --database-type=sqlite ^
--connection-string="Data Source=Resources/SQLite/database.db;Cache=Shared" ^
--migration-paths="Resources/SQLite/Migrations" ^
--snapshot-paths="Resources/SQLite/Snapshots" ^
init

Getting Started with Library

To use the datntdev.SchemaVersioner library in your .NET application, you can follow these steps:

try
{
    var logger = LoggerFactory.Create(builder => builder.AddSimpleConsole()).CreateLogger<SchemaVersioner>();
    var dbConnection = new SqliteConnection(SQLiteConnectionString);
    var versioner = new SchemaVersioner(dbConnection, logger,
        new SchemaVersionerOptions
        {
            MigrationPaths = new[] { "Resources/SQLite/Migrations" },
            SnapshotPaths = new[] { "Resources/SQLite/Snapshots" }
        });
    // Initialize a new database with snapshot scripts
    versioner.Init();
}
catch (Exception ex)
{
    Console.WriteLine($"An error occurred: {ex.Message}");
    // Handle exceptions as needed
}

Concepts

TBD: Detailed explanation of concepts like versioned migrations, repeatable migrations, and how they are applied in different database engines.

License

This project is licensed under the MIT License. See the LICENSE file for full details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.0-prerelease.20260203 4,138 2/3/2026
1.2.0-prerelease.20250930 156 9/30/2025
1.2.0-prerelease.20250920 5,419 9/20/2025
1.2.0-beta.20250920 182 9/20/2025
1.1.1 405 9/19/2025
1.1.1-beta.20250919 209 9/19/2025
1.1.0 150 6/29/2025
1.0.1 195 6/16/2025
1.0.0 198 6/15/2025
1.0.0--beta.20250616 967 6/16/2025
1.0.0--beta.20250615 141 6/15/2025
1.0.0--beta.20250614 131 6/14/2025
1.0.0--beta.20250612 302 6/12/2025