πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Migration Class Overview
  3. Key Functional Areas
  4. Dependencies & Technologies
  5. Schema Changes
    5.1 Up() Method
    5.2 Down() Method
  6. Applying & Rolling Back the Migration
  7. CLI Commands & Samples
  8. UML Diagram
  9. 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/false flag 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: IsPdfPortfolioColumn inherits from Microsoft.EntityFrameworkCore.Migrations.Migration.
  • Marked with <inheritdoc /> XML comments to inherit documentation from base class.

3. Key Functional Areas

  • Column Addition (Up)

    • Adds IsPdfPortfolio of type bit (SQL Server’s boolean).
    • Sets default value to false for existing records.
  • Column Removal (Down)

    • Drops IsPdfPortfolio on rollback.

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 bit column.
  • Name: IsPdfPortfolio.
  • Schema: "irby".
  • Table: "Ticket".
  • DefaultValue: false ensures existing rows get a valid boolean.

Behavior

  • If you have 1,000 existing tickets, after Up() all will have IsPdfPortfolio = false by default.

5.2 Down() Method

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropColumn(
        name: "IsPdfPortfolio",
        schema: "irby",
        table: "Ticket");
}
  • DropColumn: Removes IsPdfPortfolio from irby.Ticket.
  • Safe rollback: no data transformation, just column removal.

6. Applying & Rolling Back the Migration

  1. Generate the Migration
    (Already done; file exists)

  2. Apply (Update-Database)

    Update-Database
    
    • Executes Up(), commits schema change.
  3. Rollback (Revert to Previous Migration)

    Update-Database <PreviousMigrationName>
    
    • Executes Down(), removes the column.

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 false ensures 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. πŸŽ‰