📑 20231219151103_RemoveIsPdfPortfolioColumn Migration Documentation
📚 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Structure
- How to Apply & Roll Back
- Code Snippets & Examples
- UML Class Diagram
- Conclusion
📝 Overview & Purpose
Filename:
IrbyImaging.DbContext/Migrations/20231219151103_RemoveIsPdfPortfolioColumn.cs
What it does:
This Entity Framework Core (EF Core) migration removes the IsPdfPortfolio column from the Ticket table in the irby schema. It ensures your database schema stays in sync with updated domain models or business requirements, eliminating an obsolete boolean flag.
Why it's needed:
- The
IsPdfPortfolioflag is no longer used in the application logic. - Removing unused columns simplifies the database, improves performance, and reduces maintenance overhead.
- Provides the ability to roll back the change if needed (via the
Downmethod).
⚙️ Dependencies & Technologies
| Technology / Package | Version / Notes |
|---|---|
| .NET SDK | 6.0+ |
| Entity Framework Core | 6.0+ |
| Microsoft.EntityFrameworkCore | MigrationBuilder API |
| SQL Server / Other Relational DB | Supports bit type for boolean columns |
🏗 Migration Structure
This migration inherits from Microsoft.EntityFrameworkCore.Migrations.Migration and implements two primary methods:
1. Up Method
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsPdfPortfolio",
schema: "irby",
table: "Ticket");
}
- Operation:
DropColumn - Target:
irby.Tickettable - Column Removed:
IsPdfPortfolio(bit / boolean) - Emoji Summary: ❌🗄️
2. Down Method
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsPdfPortfolio",
schema: "irby",
table: "Ticket",
type: "bit",
nullable: false,
defaultValue: false);
}
- Operation:
AddColumn - Target:
irby.Tickettable - Column Added:
IsPdfPortfolio(bit / boolean) - Default Value:
false - Emoji Summary: ➕🗄️
🚀 How to Apply & Roll Back
-
Generate Migration (already done):
dotnet ef migrations add RemoveIsPdfPortfolioColumn \ --project IrbyImaging.DbContext \ --output-dir Migrations -
Apply to Database (Up):
dotnet ef database update- This will execute the
Upmethod and drop theIsPdfPortfoliocolumn.
- This will execute the
-
Roll Back (Down):
dotnet ef database update [PreviousMigrationName]- This runs the
Downmethod on this migration, re-adding theIsPdfPortfoliocolumn with defaultfalse.
- This runs the
💡 Code Snippets & Examples
Example: Checking Column Removal
After applying the migration, you can verify via SQL:
-- Should return 0 rows if column truly dropped
SELECT TOP 1 IsPdfPortfolio FROM irby.Ticket;
Expected error:
Msg 207, Level 16, State 1, Line 1
Invalid column name 'IsPdfPortfolio'.
Example: Querying Tickets
using var context = new IrbyDbContext();
var tickets = context.Tickets.ToList();
// Note: 'IsPdfPortfolio' property no longer exists in the model
🧩 UML Class Diagram
classDiagram
Migration <|-- RemoveIsPdfPortfolioColumn
class Migration {
<<abstract>>
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
class RemoveIsPdfPortfolioColumn {
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
✅ Conclusion
This migration is a small but vital step in maintaining a clean, efficient database schema for the Irby Imaging application. By dropping the unused IsPdfPortfolio flag, you:
- Simplify your
Tickettable structure - Prevent clutter of orphaned columns
- Keep your data model aligned with actual business logic
If you ever need to revert, the autogenerated Down method makes it trivial to restore the column. Always ensure you back up production data before applying schema changes! 🚧🔒
Happy Coding! 🎉