DbEasy.Migrations 1.0.0-beta07

This is a prerelease version of DbEasy.Migrations.
dotnet add package DbEasy.Migrations --version 1.0.0-beta07
                    
NuGet\Install-Package DbEasy.Migrations -Version 1.0.0-beta07
                    
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="DbEasy.Migrations" Version="1.0.0-beta07" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbEasy.Migrations" Version="1.0.0-beta07" />
                    
Directory.Packages.props
<PackageReference Include="DbEasy.Migrations" />
                    
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 DbEasy.Migrations --version 1.0.0-beta07
                    
#r "nuget: DbEasy.Migrations, 1.0.0-beta07"
                    
#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 DbEasy.Migrations@1.0.0-beta07
                    
#: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=DbEasy.Migrations&version=1.0.0-beta07&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DbEasy.Migrations&version=1.0.0-beta07&prerelease
                    
Install as a Cake Tool

DbEasy.Migrations

Lightweight and developer-friendly database migration and schema management system for .NET.

DbEasy.Migrations extends the DbEasy ecosystem with database schema snapshots, model comparison, migration operations, SQL generation, seed data, custom SQL, stored procedures, constraints, and developer-oriented validation and logging.


πŸš€ Overview

DbEasy.Migrations provides a lightweight migration infrastructure designed to detect database model changes and generate the required SQL operations.

It supports:

  • πŸ“Έ Database and model snapshots
  • πŸ” Snapshot comparison
  • πŸ—οΈ Table and column migrations
  • πŸ”„ Renamed tables and columns detection
  • πŸ” Constraint management
  • 🌱 Seed data
  • πŸ“ Custom SQL operations
  • βš™οΈ Stored procedures
  • πŸ›‘οΈ Migration validation
  • πŸ“‹ Migration logging
  • πŸ—„οΈ SQL Server support
  • 🐘 PostgreSQL support

πŸ“¦ Installation

dotnet add package DbEasy.Migrations

🧩 Main Features

πŸ“Έ Snapshot Management

DbEasy.Migrations can represent the structure of a database through snapshots.

Snapshots can contain:

  • Tables
  • Columns
  • Primary keys
  • Foreign keys
  • Unique constraints
  • Check constraints
  • Schema information

Snapshots can also be serialized, saved, loaded, validated, and compared.


πŸ” Snapshot Comparison

The migration system can compare two snapshots and identify structural differences.

Supported changes include:

  • Added tables
  • Removed tables
  • Added columns
  • Removed columns
  • Modified columns
  • Renamed tables
  • Renamed columns
  • Changed constraints

This allows migrations to be generated from differences between models or database schemas.


πŸ” Constraints

DbEasy.Migrations supports several constraint types.

Unique Constraints

Unique constraints can be represented in snapshots and converted into migration operations and SQL.

Check Constraints

Check constraints can be represented using their SQL expression.

Example:

ALTER TABLE [Users]
ADD CONSTRAINT [CK_Users_Age]
CHECK ([Age] >= 0);

Foreign Keys

Foreign key relationships contain:

  • Constraint name
  • Principal table
  • Principal column
  • Dependent table
  • Dependent column
  • Relationship type

🌱 Seed Data

DbEasy.Migrations provides migration operations for inserting initial data.

Example:

var operation =
    new SeedOperation(
        "Users",
        new Dictionary<string, object?>
        {
            ["Id"] = 1,
            ["Name"] = "Seed User",
            ["Age"] = 25
        });

Seed operations can be:

  • Generated as SQL
  • Executed against the database
  • Rolled back

πŸ“ Custom SQL

Custom SQL operations allow migration authors to execute SQL that is not covered by the standard migration operations.

Example:

var operation =
    new SqlOperation(
        "CREATE INDEX IX_Users_Name ON Users(Name);");

Custom SQL operations support:

  • SQL generation
  • Execution
  • Rollback

βš™οΈ Stored Procedures

DbEasy.Migrations supports stored procedure migration operations.

Supported operations include:

  • Create procedure
  • Drop procedure
  • SQL generation
  • SQL Server support
  • PostgreSQL support

πŸ›‘οΈ Migration Validation

The Developer Experience feature introduces validation mechanisms designed to detect invalid migration definitions before they are executed.

Duplicate Tables

The validation system detects duplicate table definitions.

Example error:

Duplicate table detected.
Table: 'Users'.
Occurrences: 2.
Table names must be unique within the same schema.

Duplicate Columns

Duplicate column definitions are detected within a table.

Example:

Duplicate column detected.
Table: 'Users'.
Column: 'Name'.
Occurrences: 2.
Column names must be unique within a table.

Duplicate Primary Key Columns

Primary key column definitions are validated to prevent the same column from being declared multiple times.


Relationship Validation

Foreign key relationships are validated against the snapshot.

The validation checks:

  • Foreign key name
  • Dependent table
  • Dependent column
  • Principal table
  • Principal column
  • Existence of referenced tables
  • Existence of referenced columns
  • Column type compatibility

Example:

Invalid foreign key 'FK_Orders_Users'.
Relationship: 'Orders.UserId' β†’ 'Users.Id'.
Principal table 'Users' does not exist in the snapshot.

πŸ“‹ Migration Logging

DbEasy.Migrations provides a lightweight migration logging abstraction.

Logger

The logging system exposes:

IMigrationLogger

with support for:

LogInformation(...)
LogWarning(...)
LogError(...)
LogDebug(...)
LogSql(...)
LogExecutedSql(...)

Generated SQL Logging

Generated SQL can be logged before execution.

Example:

[DbEasy.Migrations SQL]
ALTER TABLE [Users] ADD [Email] NVARCHAR(255);

This makes it easier to inspect the SQL generated by the migration system.


Executed SQL Logging

SQL successfully executed against the database can also be logged.

Example:

[DbEasy.Migrations EXECUTED SQL]
ALTER TABLE [Users] ADD [Email] NVARCHAR(255);

The executed SQL is logged only after successful execution.


Error Logging

Migration execution errors can be logged together with the associated exception.

Example:

[DbEasy.Migrations ERROR] Migration execution failed.
Exception: SqlException
Message: ...

Errors are logged and then propagated to the caller so that migration failures are not silently ignored.


πŸ—„οΈ Database Support

DbEasy.Migrations currently targets relational databases through SQL dialect implementations.

Supported database providers include:

SQL Server

SQL Server migration operations are supported.

PostgreSQL

PostgreSQL-specific SQL generation is supported through the PostgreSQL dialect.


πŸ—οΈ Architecture

The migration system is organized around several main concepts:

DbEasy.Migrations
β”‚
β”œβ”€β”€ Snapshot
β”‚   β”œβ”€β”€ ModelSnapshot
β”‚   β”œβ”€β”€ SchemaSnapshot
β”‚   β”œβ”€β”€ TableSnapshot
β”‚   β”œβ”€β”€ ColumnSnapshot
β”‚   β”œβ”€β”€ ForeignKeySnapshot
β”‚   β”œβ”€β”€ UniqueConstraintSnapshot
β”‚   └── CheckConstraintSnapshot
β”‚
β”œβ”€β”€ Diff
β”‚   └── ModelDifference
β”‚
β”œβ”€β”€ Operations
β”‚   β”œβ”€β”€ Table operations
β”‚   β”œβ”€β”€ Column operations
β”‚   β”œβ”€β”€ Constraint operations
β”‚   β”œβ”€β”€ Seed operations
β”‚   β”œβ”€β”€ SQL operations
β”‚   └── Procedure operations
β”‚
β”œβ”€β”€ Sql
β”‚   β”œβ”€β”€ SQL generators
β”‚   └── Database dialects
β”‚
β”œβ”€β”€ Validation
β”‚   β”œβ”€β”€ DuplicateTableValidator
β”‚   β”œβ”€β”€ DuplicateColumnValidator
β”‚   └── RelationshipValidator
β”‚
└── Logging
    β”œβ”€β”€ IMigrationLogger
    └── MigrationLogger

πŸ”„ Migration Workflow

A typical migration workflow is:

Model / Database
       β”‚
       β–Ό
   Snapshot
       β”‚
       β–Ό
 Snapshot Comparison
       β”‚
       β–Ό
 ModelDifference
       β”‚
       β–Ό
Migration Operations
       β”‚
       β–Ό
   Validation
       β”‚
       β–Ό
   SQL Generation
       β”‚
       β–Ό
 Generated SQL Logging
       β”‚
       β–Ό
 SQL Execution
       β”‚
       β”œβ”€β”€ Success β†’ Executed SQL Logging
       β”‚
       └── Error   β†’ Error Logging

πŸ§ͺ Validation Example

var validator =
    new RelationshipValidator();

validator.Validate(snapshot);

If the snapshot contains an invalid relationship, an informative InvalidOperationException is raised.


πŸ“‹ Logging Example

var logger =
    new MigrationLogger();

logger.LogInformation(
    "Migration started.");

logger.LogSql(
    "ALTER TABLE [Users] ADD [Email] NVARCHAR(255);");

logger.LogExecutedSql(
    "ALTER TABLE [Users] ADD [Email] NVARCHAR(255);");

🎯 Developer Experience

The Developer Experience improvements are designed to make migrations easier to diagnose and maintain.

The system now provides:

  • Clear validation errors
  • Relationship validation
  • Duplicate definition detection
  • Generated SQL logging
  • Executed SQL logging
  • Exception logging
  • Consistent migration diagnostics

πŸ—ΊοΈ Roadmap

Future versions may extend:

  • Advanced migration validation
  • Additional constraint validation
  • More database providers
  • More migration operation types
  • Advanced logging providers
  • Migration history management
  • Automatic migration execution
  • Advanced schema comparison

πŸ“„ License

MIT License


πŸ“Œ Status

DbEasy.Migrations is currently distributed as a beta package.

The API may evolve before the first stable release.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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.0.0-beta07 61 8/31/2026
1.0.0-beta06 67 8/30/2026
1.0.0-beta05 62 8/27/2026
1.0.0-beta04 67 8/10/2026
1.0.0-beta03 68 8/6/2026
1.0.0-beta02 68 8/4/2026
1.0.0-beta01 74 7/31/2026