π Documentation: Migration 20240130142012_MoreUpdatesToJobTable2
π Table of Contents
- π Overview & Purpose
- π§ Dependencies & Technologies
- π§© Key Functional Areas
- ποΈ Data Model Changes
- π‘ Usage & Examples
- π UML Diagrams
- π 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
- Adds new columns to the
Jobtable to capture additional metadata. - Default value of
0is set for the non-nullableStatuscolumn.
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
-
Add the Migration
dotnet ef migrations add MoreUpdatesToJobTable2 \ --project IrbyImaging.DbContext \ --context IrbyContext -
Apply the Migration
dotnet ef database update --project IrbyImaging.DbContext -
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/Downimplementations, and sensible defaults.
Enjoy π and happy coding!