📑 Migration: AddNotesColumnToTimeEntry
📋 Table of Contents
- 🎯 Overview & Purpose
- 🔧 Dependencies & Technologies
- 🛠️ Key Functional Areas
- 🗂️ Data Model Changes
- 🚀 Usage & Examples
- 📈 UML Diagram
- ✅ Conclusion
🎯 Overview & Purpose
File: IrbyImaging.DbContext/Migrations/20230707061245_AddNotesColumnToTimeEntry.cs
This Entity Framework Core migration adds a new nullable text column Notes to the TimeSheetEntry table (schema: irby).
- Allows users to attach free-form comments or additional context to time sheet entries.
- Ensures the model and database remain in sync when evolving the schema.
🔧 Dependencies & Technologies
| Dependency | Version/Package |
|---|---|
| .NET / .NET Core | (Your target framework, e.g., .NET 6) |
| Microsoft.EntityFrameworkCore | e.g., 6.x |
| Microsoft.EntityFrameworkCore.Migrations | e.g., 6.x |
Namespace Reference:
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
🛠️ Key Functional Areas
| Method | Purpose |
|---|---|
Up() |
Applies the migration by adding the Notes column (nvarchar(max), nullable). |
Down() |
Rolls back the migration by dropping the Notes column from the table. |
1. Up(MigrationBuilder)
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Notes",
schema: "irby",
table: "TimeSheetEntry",
type: "nvarchar(max)",
nullable: true
);
}
- AddColumn<T>: Creates a new column of type
T(string) - schema:
irby - table:
TimeSheetEntry - type: SQL type
nvarchar(max) - nullable:
true⇒ column acceptsNULL
2. Down(MigrationBuilder)
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Notes",
schema: "irby",
table: "TimeSheetEntry"
);
}
- DropColumn: Removes the
Notescolumn, reverting schema to its previous state.
🗂️ Data Model Changes
To keep your C# Entity in sync, add the property to the TimeSheetEntry class:
namespace IrbyImaging.Domain.Models
{
public class TimeSheetEntry
{
public int Id { get; set; }
// ... other properties ...
/// <summary>
/// Additional notes or comments for the time entry.
/// </summary>
public string? Notes { get; set; }
}
}
Tip: Mark the property as nullable (
string?) to match the nullable database column.
🚀 Usage & Examples
1. Adding the Migration
Using Package Manager Console (Visual Studio):
Add-Migration AddNotesColumnToTimeEntry -Context YourDbContext
Using dotnet CLI:
dotnet ef migrations add AddNotesColumnToTimeEntry \
--context YourDbContext \
--output-dir Migrations
2. Applying to Database
dotnet ef database update --context YourDbContext
- 🔄 Rollback to previous version:
dotnet ef database update LastGoodMigrationName
📈 UML Diagram
classDiagram
class Migration {
<<abstract>>
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
class AddNotesColumnToTimeEntry {
+Up(MigrationBuilder)
+Down(MigrationBuilder)
}
Migration <|-- AddNotesColumnToTimeEntry
✅ Conclusion
- What it does: Introduces a nullable
Notescolumn for enriching time sheet entries with custom text. - Why it matters: Provides flexibility in tracking additional details (e.g., special instructions, comments).
- Next steps:
- Commit & push migration file to your repository.
- Perform a CI/CD run to ensure migrations apply successfully in all environments.
- Update domain models and client code to leverage the new
Notesfield.
✨ With this migration in place, your application will support richer time-tracking data, empowering users to record context and remarks directly within each entry!