DbEasy.Migrations
1.0.0-beta07
dotnet add package DbEasy.Migrations --version 1.0.0-beta07
NuGet\Install-Package DbEasy.Migrations -Version 1.0.0-beta07
<PackageReference Include="DbEasy.Migrations" Version="1.0.0-beta07" />
<PackageVersion Include="DbEasy.Migrations" Version="1.0.0-beta07" />
<PackageReference Include="DbEasy.Migrations" />
paket add DbEasy.Migrations --version 1.0.0-beta07
#r "nuget: DbEasy.Migrations, 1.0.0-beta07"
#:package DbEasy.Migrations@1.0.0-beta07
#addin nuget:?package=DbEasy.Migrations&version=1.0.0-beta07&prerelease
#tool nuget:?package=DbEasy.Migrations&version=1.0.0-beta07&prerelease
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 | Versions 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. |
-
net6.0
- DbEasy (>= 1.5.0-alpha10)
- DbEasy.Abstractions (>= 1.0.0-beta02)
-
net7.0
- DbEasy (>= 1.5.0-alpha10)
- DbEasy.Abstractions (>= 1.0.0-beta02)
-
net8.0
- DbEasy (>= 1.5.0-alpha10)
- DbEasy.Abstractions (>= 1.0.0-beta02)
-
net9.0
- DbEasy (>= 1.5.0-alpha10)
- DbEasy.Abstractions (>= 1.0.0-beta02)
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 |