π Documentation: 20250317161629_UpdateCrewEmployeeTime.cs
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Data Model Impact
- Detailed Workflow
5.1 Up Method
5.2 Down Method - UML & Schema Diagrams
- Usage Examples & Commands
- 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,timetypes)
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
StartTimecolumn todatetime2. - Preserves nullability (
nullable: true).
- Alters the
- 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
timeif you undo the migration.
- Rolls the column back to
- 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
-
Add Migration
dotnet ef migrations add UpdateCrewEmployeeTime \ --project IrbyImaging.DbContext \ --output-dir Migrations -
Apply to Database
dotnet ef database update \ --project IrbyImaging.DbContext \ --context YourDbContext -
Rollback
dotnet ef database update LastGoodMigration \ --project IrbyImaging.DbContext
π Conclusion
- This migration is a safe, reversible schema change to enrich
StartTimewith full date context. - It leverages EF Coreβs fluent API to track, apply, and rollback database changes systematically.
- After applying, your
CrewEmployee.StartTimecolumn supports richer scheduling scenarios.
β¨ Happy coding! If you have any questions or need further adjustments, feel free to ask!