π Table of Contents
- Overview & Purpose
- Migration Class Overview
- Key Functional Areas
- Dependencies & Technologies
- Schema Changes
5.1 Up() Method
5.2 Down() Method - Applying & Rolling Back the Migration
- CLI Commands & Samples
- UML Diagram
- Conclusion
1. Overview & Purpose
This migration adds a new boolean column, IsPdfPortfolio, to the irby.Ticket table in the database schema.
π― Goal: Enable tracking of whether a ticket is associated with a PDF portfolio.
- Schema:
irby(database schema) - Table:
Ticket
Why?
- To support new features in the application UI or API that filter or flag tickets containing PDF portfolios.
- To persist a simple
true/falseflag without altering existing ticket data structures.
2. Migration Class Overview
Filename:
IrbyImaging.DbContext/Migrations/20231122151808_IsPdfPortfolioColumn.cs
Namespace & Class:
namespace IrbyImaging.DbContext.Migrations
{
public partial class IsPdfPortfolioColumn : Migration
{
protected override void Up(MigrationBuilder migrationBuilder) { /* β¦ */ }
protected override void Down(MigrationBuilder migrationBuilder) { /* β¦ */ }
}
}
- Partial Class:
IsPdfPortfolioColumninherits fromMicrosoft.EntityFrameworkCore.Migrations.Migration. - Marked with
<inheritdoc />XML comments to inherit documentation from base class.
3. Key Functional Areas
-
Column Addition (Up)
- Adds
IsPdfPortfolioof typebit(SQL Serverβs boolean). - Sets default value to
falsefor existing records.
- Adds
-
Column Removal (Down)
- Drops
IsPdfPortfolioon rollback.
- Drops
4. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| Microsoft.EntityFrameworkCore | Core Entity Framework functionality. |
| Microsoft.EntityFrameworkCore.Migrations | Migration API for schema evolution. |
| .NET (C#) | Language and runtime. |
SQL Server (bit type) |
Underlying database platform and data type. |
5. Schema Changes
5.1 Up() Method
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsPdfPortfolio",
schema: "irby",
table: "Ticket",
type: "bit",
nullable: false,
defaultValue: false);
}
- AddColumn<bool>: Adds a new non-nullable
bitcolumn. - Name:
IsPdfPortfolio. - Schema:
"irby". - Table:
"Ticket". - DefaultValue:
falseensures existing rows get a valid boolean.
Behavior
- If you have 1,000 existing tickets, after
Up()all will haveIsPdfPortfolio = falseby default.
5.2 Down() Method
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsPdfPortfolio",
schema: "irby",
table: "Ticket");
}
- DropColumn: Removes
IsPdfPortfoliofromirby.Ticket. - Safe rollback: no data transformation, just column removal.
6. Applying & Rolling Back the Migration
-
Generate the Migration
(Already done; file exists) -
Apply (Update-Database)
Update-Database- Executes
Up(), commits schema change.
- Executes
-
Rollback (Revert to Previous Migration)
Update-Database <PreviousMigrationName>- Executes
Down(), removes the column.
- Executes
7. CLI Commands & Samples
# 1. Add migration (done by author)
dotnet ef migrations add IsPdfPortfolioColumn \
--context IrbyDbContext \
--output-dir Migrations
# 2. Apply to database
dotnet ef database update
# 3. Rollback to prior migration
dotnet ef database update 20231122094500_PreviousMigration
8. UML Diagram
classDiagram
class IsPdfPortfolioColumn {
<<Migration>>
+void Up(MigrationBuilder migrationBuilder)
+void Down(MigrationBuilder migrationBuilder)
}
class MigrationBuilder {
+AddColumn<T>(...)
+DropColumn(...)
}
IsPdfPortfolioColumn ..> MigrationBuilder : uses
9. Conclusion
β¨ IsPdfPortfolioColumn is a straightforward EF Core migration that augments the Ticket table with an IsPdfPortfolio flag.
- When to use: Deploy when you need PDF portfolio tracking on tickets.
- Impact: Minimal; default value of
falseensures backward compatibility. - Rollbacks: Clean removal of the column if business requirements change.
Feel free to integrate this migration into your CI/CD pipeline or apply it manually via the EF Core CLI. π