πŸ“š Documentation: 20250317161629_UpdateCrewEmployeeTime.cs


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Model Impact
  5. Detailed Workflow
    5.1 Up Method
    5.2 Down Method
  6. UML & Schema Diagrams
  7. Usage Examples & Commands
  8. Conclusion

🧐 Overview & Purpose

The UpdateCrewEmployeeTime migration adjusts the schema of the CrewEmployee table. Specifically, it converts the StartTime column from a time type (representing only a TimeSpan) to a datetime2 type (representing a full DateTime).

Why?

  • To capture both date and time for crew members’ start times, rather than just the time of day.
  • To enable richer scheduling functionality, historical logging, and cross-day workflows.

🌟 Key Functional Areas

Feature Description
Column Type Alteration Swaps time β†’ datetime2 for StartTime.
Schema Versioning Encapsulated in an EF Core Migration class.
Reversibility Provides a Down method to roll back to the original time.

πŸ›  Dependencies & Technologies

  • .NET Entity Framework Core
  • C# 10 / .NET 6+
  • Microsoft.EntityFrameworkCore.Migrations
  • SQL Server (datetime2, time types)

No external third‑party integrations or APIs are directly involved.


πŸ—„ Data Model Impact

Before Migration

Table Column Type Nullable
irby.CrewEmployee StartTime time TRUE

After Migration

Table Column Type Nullable
irby.CrewEmployee StartTime datetime2 TRUE

πŸ” Detailed Workflow

Up Method

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AlterColumn<DateTime>(
        name: "StartTime",
        schema: "irby",
        table: "CrewEmployee",
        type: "datetime2",
        nullable: true,
        oldClrType: typeof(TimeSpan),
        oldType: "time",
        oldNullable: true);
}
  • Purpose:
    • Alters the StartTime column to datetime2.
    • Preserves nullability (nullable: true).
  • Key Parameters:
    • name: Column name.
    • schema & table: Target schema and table.
    • type: New database type.
    • oldClrType & oldType: Original CLR and SQL types for EF to compute the delta.

Down Method

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AlterColumn<TimeSpan>(
        name: "StartTime",
        schema: "irby",
        table: "CrewEmployee",
        type: "time",
        nullable: true,
        oldClrType: typeof(DateTime),
        oldType: "datetime2",
        oldNullable: true);
}
  • Purpose:
    • Rolls the column back to time if you undo the migration.
  • Reversibility:
    • Ensures database schema can revert to previous state.

πŸ”§ UML & Schema Diagrams

1. Class Diagram

classDiagram
    Migration <|-- UpdateCrewEmployeeTime
    class Migration {
        <<abstract>>
        +void Up(MigrationBuilder)
        +void Down(MigrationBuilder)
    }
    class UpdateCrewEmployeeTime {
        +void Up(MigrationBuilder)
        +void Down(MigrationBuilder)
    }

2. Entity-Relationship (Before/After)

Before

erDiagram
    CREW_EMPLOYEE {
      INT    Id PK
      TIME   StartTime
      /* other columns */
    }

After

erDiagram
    CREW_EMPLOYEE {
      INT       Id PK
      DATETIME2 StartTime
      /* other columns */
    }

πŸš€ Usage Examples & Commands

  1. Add Migration

    dotnet ef migrations add UpdateCrewEmployeeTime \
      --project IrbyImaging.DbContext \
      --output-dir Migrations
    
  2. Apply to Database

    dotnet ef database update \
      --project IrbyImaging.DbContext \
      --context YourDbContext
    
  3. Rollback

    dotnet ef database update LastGoodMigration \
      --project IrbyImaging.DbContext
    

🏁 Conclusion

  • This migration is a safe, reversible schema change to enrich StartTime with full date context.
  • It leverages EF Core’s fluent API to track, apply, and rollback database changes systematically.
  • After applying, your CrewEmployee.StartTime column supports richer scheduling scenarios.

✨ Happy coding! If you have any questions or need further adjustments, feel free to ask!