一键导入
ewl-database-migration
Database schema migration using FluentMigrator with the EWL Data Migrator project
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Database schema migration using FluentMigrator with the EWL Data Migrator project
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Configure opencode on a new development machine for EWL work by creating the global AGENTS.md and granting access to the EWL source, EWL System Manager source, EWL folder, and EWL client systems directory. Use when setting up opencode on a new machine, or when the user asks to bootstrap, initialize, or configure global opencode for EWL.
Run local EWL Development Utility (DU) operations on EWL systems. Use when asked to run DU operations such as sync or update-data against a particular path or system.
Inspect and troubleshoot EWL systems hosted in Azure — locating an installation's App Service, Container App Job, and Log Analytics workspace, and reliably reading Container App (data migrator) console and system logs. Use when checking whether a deploy's data migrator ran, reading container logs for a hosted installation, or investigating an installation's Azure resources. Companion to ewl-azure-pipelines, which covers the build/deploy pipelines that create these resources.
Test changes to EWL agent rules, subagents, skills, OpenCode plugins, and MCP tools by driving OpenCode headlessly, capturing transcripts, and cleaning up afterwards. Load this skill when verifying changes to anything under Library\Files\Agent Rules.md, Library\Files\Agents\, Library\Files\Agent Skills\, Library\Files\OpenCode Plugins\, or Library\Files\OpenCode Tools\.
Azure Pipelines CI/CD for EWL systems including build templates, deploy templates, and pipeline code generation
EWL generated data access layer including table retrievals, modifications, row constants, sequences, and caching
| name | ewl-database-migration |
| description | Database schema migration using FluentMigrator with the EWL Data Migrator project |
EWL uses FluentMigrator for database schema and reference data migrations.
Migrations run automatically during sync (for local
development) and during deployment via DataMigrator.exe.
If the Data Migrator project is not yet in your solution:
Data Migrator/Data Migrator.ewlt.csproj.csprojAdd migration classes to the Data Migrator project. Each migration class
must have a unique, sequential version number.
Rules:
ForwardOnlyMigration, not Migration. Only define Up().namespace DataMigrator; — always matches the RootNamespace
in Directory.Build.props, not the system namespace.CreateRooms, AddRoomsCapacity, AddManagerUserRole). Never use generic
names like Migration1.[ Migration( N ) ] with spaces inside brackets and
parentheses, per EWL style.Create.Table() call and .InSchema() (if any) on
the first line. Put each column's full spec chain (.WithColumn() through
all modifiers) on a single line.using FluentMigrator;
namespace DataMigrator;
[ Migration( 1 ) ]
public class CreateRooms: ForwardOnlyMigration {
public override void Up() {
Create.Table( "Rooms" )
.WithColumn( "RoomId" ).AsInt32().NotNullable().PrimaryKey( "RoomsPk" )
.WithColumn( "BuildingId" ).AsInt32().NotNullable().ForeignKey( "RoomsBuildingIdFk", "Buildings", "BuildingId" )
.WithColumn( "RoomName" ).AsString( 200 ).NotNullable()
.WithColumn( "IsActive" ).AsBoolean().NotNullable();
}
}
| Constraint | Pattern | Example |
|---|---|---|
| Primary key | <TableName>Pk | RoomsPk |
| Foreign key | <TableName><ColumnName>Fk | RoomsBuildingIdFk |
| Unique | <TableName><ColumnName>Unique | RoomsRoomNameUnique |
For inline foreign keys on a column definition, use:
.ForeignKey( "<Table><Column>Fk", "ReferencedTable", "ReferencedColumn" )
When the referenced table is in a different schema, add the schema argument:
.ForeignKey( "<Table><Column>Fk", "dbo", "ReferencedTable", "ReferencedColumn" )
Prefer inline .ForeignKey() on the column over separate
Create.ForeignKey() statements for single-column foreign keys.
To create a table in a non-default schema, first create the schema, then
use .InSchema():
Create.Schema( "Reporting" );
Create.Table( "MonthlyTotals" ).InSchema( "Reporting" )
.WithColumn( "MonthlyTotalId" ).AsInt32().NotNullable().PrimaryKey( "MonthlyTotalsPk" )
.WithColumn( "Amount" ).AsDecimal( 10, 2 ).NotNullable();
Use the built-in FluentMigrator type methods. Avoid .AsCustom() when a
proper API method exists.
| FluentMigrator method | SQL Server type |
|---|---|
.AsString( n ) | NVARCHAR(n) |
.AsString( int.MaxValue ) | NVARCHAR(MAX) |
.AsAnsiString( n ) | VARCHAR(n) |
.AsAnsiString( int.MaxValue ) | VARCHAR(MAX) |
.AsInt32() | INT |
.AsInt64() | BIGINT |
.AsInt16() | SMALLINT |
.AsByte() | TINYINT |
.AsBoolean() | BIT |
.AsDecimal( p, s ) | DECIMAL(p, s) |
.AsDateTime2() | DATETIME2 |
.AsDate() | DATE |
.AsGuid() | UNIQUEIDENTIFIER |
.AsBinary( n ) | VARBINARY(n) |
.AsCustom( "datetime2( 0 )" ) | DATETIME2(0) (precision variants) |
Reserve .AsCustom() for types that have no built-in method, such as
datetime2 with a specific precision.
Migrations run automatically when you execute sync. Each
installation tracks which migrations have already been applied. When you
deploy to a server, only new migrations run.
If you do not use the EWL System Manager, call DataMigrator.exe as part
of your deployment process.
[ Migration( 2 ) ]
public class AddRoomsCapacity: ForwardOnlyMigration {
public override void Up() {
Alter.Table( "Rooms" ).AddColumn( "Capacity" ).AsInt32().Nullable();
}
}
[ Migration( 3 ) ]
public class AddRoomsFloor: ForwardOnlyMigration {
public override void Up() {
Create.Column( "Floor" ).OnTable( "Rooms" ).AsInt32().NotNullable().SetExistingRowsTo( 1 );
}
}
[ Migration( 4 ) ]
public class AddManagerUserRole: ForwardOnlyMigration {
public override void Up() {
Insert.IntoTable( "UserRoles" ).Row( new { UserRoleId = 3, RoleName = "Manager" } );
}
}
For cursor-type logic that loops through rows, use Execute.WithConnection
and query with Dapper (add a Dapper package reference to the Data Migrator
project):
Execute.WithConnection( ( connection, transaction ) => {
var rows = connection.Query( "SELECT Id, OldValue FROM MyTable", transaction: transaction );
foreach( var row in rows ) {
connection.Execute(
"UPDATE MyTable SET NewValue = @val WHERE Id = @id",
new { val = Transform( row.OldValue ), id = row.Id },
transaction: transaction );
}
} );
After any migration that changes the schema, run sync to
regenerate the data-access layer (Generated Code\ files). This keeps
your C# retrieval and modification classes in sync with the database.