📑 20231219151103_RemoveIsPdfPortfolioColumn Migration Documentation


📚 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Migration Structure
  4. How to Apply & Roll Back
  5. Code Snippets & Examples
  6. UML Class Diagram
  7. 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 IsPdfPortfolio flag 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 Down method).

⚙️ 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.Ticket table
  • 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.Ticket table
  • Column Added: IsPdfPortfolio (bit / boolean)
  • Default Value: false
  • Emoji Summary: ➕🗄️

🚀 How to Apply & Roll Back

  1. Generate Migration (already done):

    dotnet ef migrations add RemoveIsPdfPortfolioColumn \
      --project IrbyImaging.DbContext \
      --output-dir Migrations
    
  2. Apply to Database (Up):

    dotnet ef database update
    
    • This will execute the Up method and drop the IsPdfPortfolio column.
  3. Roll Back (Down):

    dotnet ef database update [PreviousMigrationName]
    
    • This runs the Down method on this migration, re-adding the IsPdfPortfolio column with default false.

💡 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 Ticket table 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! 🎉