📑 Documentation: 20220614182210_NewColumnDocumentImageTable2.cs

Assembly: IrbyImaging.DbContext
Author: kvamshi
Created: 06-14-2022
Last Modified: 06-14-2022


🗂 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Model Changes
  5. Migration Class Details
  6. Usage Examples
  7. Error Handling & Rollbacks
  8. Third‑Party Integrations
  9. Conclusion

🔍 Overview & Purpose

This EF Core Migration adds a new Boolean column, IsLegalDocument, to two existing tables in the irby schema:

  • TempDocumentData
  • DocumentImage

Why?
To flag whether a document in these tables is categorized as a “legal document” within the system. This supports downstream logic that may filter, process or display legal documents differently.


🔑 Key Functional Areas

  • Schema Evolution: Introduces schema changes without data loss.
  • Backward‑Compatible: Default value ensures existing rows are set to false.
  • Reversible: Provides an explicit Down method to roll back the changes.

⚙️ Dependencies & Technologies

Technology Version / Details
Microsoft.EntityFrameworkCore Used for Migrations (Migration, MigrationBuilder)
C# / .NET Core Migration implemented in C#
SQL Server (assumed)** Column type bit

Note: Adjust database provider as needed; column type bit is standard in SQL Server for Boolean values.


🏗 Data Model Changes

New Columns Introduced

Schema Table Column SQL Type Nullable Default Value
irby TempDocumentData IsLegalDocument bit No false
irby DocumentImage IsLegalDocument bit No false

UML Diagram

+---------------------+
| <<Migration>>       |
| NewColumnDocument…  |
+---------------------+
| - Up(mb)            |
| - Down(mb)          |
+---------------------+
  • Up: Adds two columns
  • Down: Removes those columns

🛠 Migration Class Details

using Microsoft.EntityFrameworkCore.Migrations;

namespace IrbyImaging.DbContext.Migrations
{
    public partial class NewColumnDocumentImageTable2 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<bool>(
                name: "IsLegalDocument",
                schema: "irby",
                table: "TempDocumentData",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsLegalDocument",
                schema: "irby",
                table: "DocumentImage",
                type: "bit",
                nullable: false,
                defaultValue: false);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "IsLegalDocument",
                schema: "irby",
                table: "TempDocumentData");

            migrationBuilder.DropColumn(
                name: "IsLegalDocument",
                schema: "irby",
                table: "DocumentImage");
        }
    }
}

Up Method

  • Purpose: Apply schema changes.
  • Actions:
    1. AddColumn<bool>("IsLegalDocument", ...) on TempDocumentData
    2. AddColumn<bool>("IsLegalDocument", ...) on DocumentImage
  • DefaultValue: false ensures existing data remains consistent.

Down Method

  • Purpose: Revert schema to previous state.
  • Actions:
    1. DropColumn("IsLegalDocument") from TempDocumentData
    2. DropColumn("IsLegalDocument") from DocumentImage

🚀 Usage Examples

  1. Add Migration

    dotnet ef migrations add NewColumnDocumentImageTable2 \
      --project IrbyImaging.DbContext \
      --startup-project IrbyImaging.API
    
  2. Update Database

    dotnet ef database update \
      --project IrbyImaging.DbContext \
      --startup-project IrbyImaging.API
    
  3. Verify Schema

    SELECT COLUMN_NAME, DATA_TYPE, COLUMN_DEFAULT
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_SCHEMA = 'irby'
      AND TABLE_NAME   IN ('TempDocumentData','DocumentImage');
    

🛡 Error Handling & Rollbacks

  • Migration Errors: If adding a column fails (e.g., permission issues), the EF Core tooling will halt and report the issue.
  • Rollback Strategy:
    dotnet ef database update LastGoodMigration
    
    This invokes the Down methods of subsequent migrations automatically.

🌐 Third‑Party Integrations

  • Entity Framework Core Migrations: Handles schema diffs and generates SQL.
  • SQL Server: Column type bit is SQL Server–specific; adapt for other providers if required (e.g., boolean in PostgreSQL).

📝 Conclusion

This migration NewColumnDocumentImageTable2 elegantly extends your database model by tagging documents as “legal.” It’s:

  • Non‑disruptive: Default values preserve existing records.
  • Reversible: Provides a clean rollback.
  • Lightweight: Two straightforward schema operations.

Apply it via dotnet ef database update, and your application can immediately begin utilizing the new IsLegalDocument flags in queries, views or business logic. 🚀


Happy Coding! 🛠️🎉