π Documentation: 20220608152519_MoreColumnsForLegalImaging.cs
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- 3.1 Migration Class Structure
- 3.2 Up Method
- 3.3 Down Method
- Schema Changes Summary
- 4.1 Before Migration
- 4.2 After Migration
- UML Class Diagram
- Sample Usage & Commands
- Error Handling & Return Types
- ThirdβParty Integrations
- Conclusion
π§ Overview & Purpose
This migration adds a new AttributeType column to the DocumentAttribute table within the irby schema.
It is part of the IrbyImaging.DbContext.Migrations assembly and is intended to enhance the Legal Imaging feature by categorizing document attributes.
- Filename:
20220608152519_MoreColumnsForLegalImaging.cs - Created/Modified: 06-08-2022 by kvamshi
- Migration ID:
20220608152519
π§ Dependencies & Technologies
| Component | Version / Info |
|---|---|
| .NET / C# | .NET Core / .NET 5+ |
| Microsoft.EntityFrameworkCore.Migrations | EF Core Migrations API |
| SQL Database | Target relational database (e.g., SQL Server) |
| Assembly | IrbyImaging.DbContext |
π Key Functional Areas
3.1 Migration Class Structure
public partial class MoreColumnsForLegalImaging : Migration
{
protected override void Up(MigrationBuilder migrationBuilder) { ... }
protected override void Down(MigrationBuilder migrationBuilder){ ... }
}
- Inherits from
Migration(EF Core). - Contains two core methods:
Up: Applies changes to the database schema.Down: Reverts those changes.
3.2 Up Method
Purpose: Add a new column AttributeType to the DocumentAttribute table.
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "AttributeType",
schema: "irby",
table: "DocumentAttribute",
type: "int",
nullable: false,
defaultValue: 0
);
}
- name:
"AttributeType" - schema:
"irby" - table:
"DocumentAttribute" - type:
"int" - nullable:
false - defaultValue:
0
β¨ Note: Setting
nullable: falsewith adefaultValueensures existing records get0for the new column.
3.3 Down Method
Purpose: Remove the previously added column.
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "AttributeType",
schema: "irby",
table: "DocumentAttribute"
);
}
- Reverses the
AddColumnoperation. - Ensures clean rollback if migration is undone.
π Schema Changes Summary
4.1 Before Migration
| Column Name | Data Type | Nullable? |
|---|---|---|
| Id | int |
No |
| DocumentId | int |
No |
| Name | nvarchar |
Yes |
| Value | nvarchar |
Yes |
| (no AttributeType) |
4.2 After Migration
| Column Name | Data Type | Nullable? | Default Value |
|---|---|---|---|
| Id | int |
No | β |
| DocumentId | int |
No | β |
| Name | nvarchar |
Yes | β |
| Value | nvarchar |
Yes | β |
| AttributeType | int |
No | 0 |
π UML Class Diagram
+------------------------------------------------+
| MoreColumnsForLegalImaging : Migration |
+------------------------------------------------+
| - (inherits Migration) |
+------------------------------------------------+
| + Up(migrationBuilder: MigrationBuilder) : void|
| + Down(migrationBuilder: MigrationBuilder) : void|
+------------------------------------------------+
π§° Sample Usage & Commands
- Add Migration
dotnet ef migrations add MoreColumnsForLegalImaging - Apply Migration
dotnet ef database update - Rollback Migration
dotnet ef database update [PreviousMigrationName]
βοΈ After running, check the
DocumentAttributetable under theirbyschema for the new column.
β οΈ Error Handling & Return Types
- Return Type: Both
UpandDownmethods returnvoid. - Error Handling:
- EF Core will throw exceptions (e.g.,
SqlException) if the migration fails (e.g., naming conflicts, permission issues). - Ensure database user has ALTER permissions.
- EF Core will throw exceptions (e.g.,
π ThirdβParty Integrations
- Microsoft.EntityFrameworkCore
Utilizes the EF Core migrations engine. - SQL Providers
Works with any EF Coreβsupported database (e.g., SQL Server, PostgreSQL). Thetype: "int"may vary based on the provider.
β¨ Conclusion
This migration enhances the Legal Imaging domain by introducing an AttributeType discriminator for document attributes.
By following standard EF Core migration patterns, it ensures both forward (Up) and backward (Down) compatibility.
π Next Steps:
- Adjust application code to use
AttributeTypewhen processingDocumentAttributeentities.- Update business logic, APIs, or UI to leverage the new column.
Generated by the Irby Imaging team documentation generator. π