๐Ÿ“š Documentation: 20230620124309_AddIndexTagColumnToDocumentImage.cs


๐Ÿ—‚ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Model Changes
  4. Key Functional Areas
  5. Error Handling & Rollback
  6. Usage Examples
  7. UML Diagram
  8. Conclusion

1. Overview & Purpose ๐Ÿš€

The AddIndexTagColumnToDocumentImage migration introduces a new column, IndexTag, to the existing DocumentImage table in the irby schema. This column will store optional string tags for indexing, searching, and categorizing document images within the system.

  • Namespace: IrbyImaging.DbContext.Migrations
  • Class: AddIndexTagColumnToDocumentImage
  • Type: Migration (Entity Framework Core)

Why?

  • Enhance searchability by tagging images
  • Support future indexing and filtering operations
  • Maintain backward compatibility with existing records (nullable column)

2. Dependencies & Technologies โš™๏ธ

Technology Version / Reference Purpose
Microsoft.EntityFrameworkCore.Migrations โ‰ฅ 6.0.0 (typical) Core EF Migration infrastructure
.NET / C# .NET 6+ / C# 10+ Language & runtime

No external packages or thirdโ€‘party integrations are required by this migration alone. It piggybacks on the existing EF Core setup in your DbContext.


3. Data Model Changes ๐Ÿ“ฆ

Before migration:

Column Type Nullable
Id int No
FileName nvarchar(max) No
CreatedDate datetime2 No
โ€ฆ โ€ฆ โ€ฆ

After migration:

Column Type Nullable Notes
IndexTag nvarchar(max) Yes New freeโ€‘text tag for indexing & filtering

Tip: Making this column nullable ensures zero downtime for existing records.


4. Key Functional Areas ๐Ÿ”

Up Method (Apply Migration)

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<string>(
        name: "IndexTag",
        schema: "irby",
        table: "DocumentImage",
        type: "nvarchar(max)",
        nullable: true);
}
  • Action: Adds IndexTag to irby.DocumentImage
  • Schema: irby
  • Table: DocumentImage
  • Column Type: string โ†’ nvarchar(max)
  • Nullable: true

Down Method (Revert Migration)

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropColumn(
        name: "IndexTag",
        schema: "irby",
        table: "DocumentImage");
}
  • Action: Removes IndexTag
  • Provides clean rollback to preโ€‘migration state.

5. Error Handling & Rollback ๐Ÿ”„

  • EF Core wraps Up/Down executions in transactions by default.
  • If any statement in Up fails, the entire migration is rolled back.
  • Downโ€‘migrations will only run if you explicitly revert:
    dotnet ef database update PreviousMigrationName
    

Warning: Dropping a column (Down) will permanently delete all data in IndexTag.


6. Usage Examples ๐Ÿ“

  1. Add Migration
    dotnet ef migrations add AddIndexTagColumnToDocumentImage \
      --context IrbyImagingDbContext \
      --output-dir Migrations
    
  2. Apply to Database
    dotnet ef database update
    
  3. Revert (if needed)
    dotnet ef database update 20230620120000_PreviousMigration
    

7. UML Diagram ๐Ÿ“Š

classDiagram
    class AddIndexTagColumnToDocumentImage <<Migration>> {
      +Up(MigrationBuilder)
      +Down(MigrationBuilder)
    }
    class DocumentImage {
      +int Id
      +string FileName
      +string? IndexTag
      +DateTime CreatedDate
      // โ€ฆ other columns โ€ฆ
    }
    AddIndexTagColumnToDocumentImage --> DocumentImage : modifies

8. Conclusion โœ…

The AddIndexTagColumnToDocumentImage migration is a targeted schema update to enhance the DocumentImage entity with an IndexTag field. This change lays the groundwork for advanced search and categorization features while preserving existing data integrity. Follow the Usage Examples to integrate this migration into your deployment pipeline, and remember to backup critical data before downgrades.


๐Ÿ’ก Next Steps

  • Update related Entity and Repository classes to surface the new property.
  • Implement search/filter logic utilizing IndexTag.
  • Write unit/integration tests to verify indexing behavior.