πŸ“‘ Documentation: Migration 20240130142012_MoreUpdatesToJobTable2


πŸ“‹ Table of Contents

  1. πŸš€ Overview & Purpose
  2. πŸ”§ Dependencies & Technologies
  3. 🧩 Key Functional Areas
  4. πŸ—„οΈ Data Model Changes
  5. πŸ’‘ Usage & Examples
  6. πŸ“ˆ UML Diagrams
  7. πŸ” Conclusion

πŸš€ Overview & Purpose

This Entity Framework Core migration adds seven new fields to the irby.Job table and provides the ability to roll back those changes.
The goal is to enrich the Job entity with additional metadataβ€”contract details, geographic region codes/descriptions, job categorization, revenue flags, status, and work classification.

Name: MoreUpdatesToJobTable2
Schema: irby
Table: Job


πŸ”§ Dependencies & Technologies

Technology / Package Purpose
Microsoft.EntityFrameworkCore Core ORM framework
Microsoft.EntityFrameworkCore.Migrations Provides Migration base class
.NET 6+ Runtime environment
SQL Server (NVARCHAR, INT types) Target database

🧩 Key Functional Areas

Up Method

/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.AddColumn<string>(
        name: "ContractType",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);

    migrationBuilder.AddColumn<string>(
        name: "GeoRegionCode",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);

    migrationBuilder.AddColumn<string>(
        name: "GeoRegionDescription",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);

    migrationBuilder.AddColumn<string>(
        name: "JobType",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);

    migrationBuilder.AddColumn<string>(
        name: "RevenueDerivative",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);

    migrationBuilder.AddColumn<int>(
        name: "Status",
        schema: "irby",
        table: "Job",
        type: "int",
        nullable: false,
        defaultValue: 0);

    migrationBuilder.AddColumn<string>(
        name: "WorkType",
        schema: "irby",
        table: "Job",
        type: "nvarchar(max)",
        nullable: true);
}

What it does

  1. Adds new columns to the Job table to capture additional metadata.
  2. Default value of 0 is set for the non-nullable Status column.

Down Method

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.DropColumn(name: "ContractType", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "GeoRegionCode", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "GeoRegionDescription", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "JobType", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "RevenueDerivative", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "Status", schema: "irby", table: "Job");
    migrationBuilder.DropColumn(name: "WorkType", schema: "irby", table: "Job");
}

What it does

  • Safely rolls back the schema changes by dropping each of the columns added in Up().

πŸ—„οΈ Data Model Changes

New Columns at a Glance

Column SQL Type Nullable Default Description
ContractType nvarchar(max) Yes β€” Type of contract (e.g., Fixed, T&M)
GeoRegionCode nvarchar(max) Yes β€” Short code for geographic region
GeoRegionDescription nvarchar(max) Yes β€” Full description of the region
JobType nvarchar(max) Yes β€” Category/type of job (e.g., Installation)
RevenueDerivative nvarchar(max) Yes β€” Revenue source/derivative indicator
Status int No 0 Job status (e.g., Open = 0, Closed = 1)
WorkType nvarchar(max) Yes β€” Labor classification

πŸ’‘ Usage & Examples

  1. Add the Migration

    dotnet ef migrations add MoreUpdatesToJobTable2 \
      --project IrbyImaging.DbContext \
      --context IrbyContext
    
  2. Apply the Migration

    dotnet ef database update --project IrbyImaging.DbContext
    
  3. Rollback (if needed)

    dotnet ef database update 20240130142012_PreviousMigrationName
    

πŸ“ˆ UML Diagrams

1. Class Hierarchy

classDiagram
    <<abstract>> Migration
    MoreUpdatesToJobTable2 --> Migration
    class MoreUpdatesToJobTable2 {
      +Up(MigrationBuilder)
      +Down(MigrationBuilder)
    }

2. Entity-Relationship

erDiagram
    JOB {
        int     Id PK
        string  Title
        -- New Columns --
        string  ContractType
        string  GeoRegionCode
        string  GeoRegionDescription
        string  JobType
        string  RevenueDerivative
        int     Status
        string  WorkType
    }

πŸ” Conclusion

With MoreUpdatesToJobTable2, the Job table is significantly enhanced to support richer reporting and business logic.

  • You can now classify jobs by contract, geography, type, and track their status.
  • The migration follows best practices: clear naming, idempotent Up/Down implementations, and sensible defaults.

Enjoy πŸš€ and happy coding!