Skip to content

Commit 59b2af8

Browse files
committed
Rollback on migration Adding_ChangeLog and fixed. ChangeLogItem description and ChangeLog response mapping fixed. New check workitem change to don't save duplicate.
1 parent 87dfce4 commit 59b2af8

10 files changed

+105
-92
lines changed

AzureDevopsTracker/Data/Context/AzureDevopsTrackerContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2323
property.SetColumnType("varchar(200)");
2424

2525
modelBuilder.HasDefaultSchema(DataBaseConfig.SchemaName);
26+
27+
modelBuilder.ApplyConfigurationsFromAssembly(typeof(AzureDevopsTrackerContext).Assembly);
2628
}
2729

2830
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using AzureDevopsTracker.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
5+
namespace AzureDevopsTracker.Data.Mapping
6+
{
7+
public class ChangeLogItemMapping : IEntityTypeConfiguration<ChangeLogItem>
8+
{
9+
public void Configure(EntityTypeBuilder<ChangeLogItem> builder)
10+
{
11+
builder.Property(d => d.Description)
12+
.HasColumnType("varchar(max)");
13+
}
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using AzureDevopsTracker.Entities;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
5+
namespace AzureDevopsTracker.Data.Mapping
6+
{
7+
public class ChangeLogMapping : IEntityTypeConfiguration<ChangeLog>
8+
{
9+
public void Configure(EntityTypeBuilder<ChangeLog> builder)
10+
{
11+
builder.Property(d => d.Response)
12+
.HasColumnType("varchar(max)");
13+
}
14+
}
15+
}

AzureDevopsTracker/Data/WorkItemRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public async Task<WorkItem> GetByWorkItemId(string workItemId)
1717
return await DbSet
1818
.Include(x => x.WorkItemsChanges)
1919
.Include(x => x.TimeByStates)
20+
.Include(x => x.ChangeLogItem)
2021
.FirstOrDefaultAsync(x => x.Id == workItemId);
2122
}
2223

@@ -25,6 +26,7 @@ public async Task<IEnumerable<WorkItem>> ListByWorkItemId(IEnumerable<string> wo
2526
return await DbSet
2627
.Include(x => x.WorkItemsChanges)
2728
.Include(x => x.TimeByStates)
29+
.Include(x => x.ChangeLogItem)
2830
.Where(x => workItemsId.Contains(x.Id))
2931
.ToListAsync();
3032
}
@@ -34,6 +36,7 @@ public async Task<IEnumerable<WorkItem>> ListByIterationPath(string iterationPat
3436
return await DbSet
3537
.Include(x => x.WorkItemsChanges)
3638
.Include(x => x.TimeByStates)
39+
.Include(x => x.ChangeLogItem)
3740
.Where(x => x.IterationPath == iterationPath)
3841
.ToListAsync();
3942
}

AzureDevopsTracker/Entities/ChangeLogItem.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,23 @@ public class ChangeLogItem : Entity
1515
public ChangeLog ChangeLog { get; private set; }
1616
private ChangeLogItem() { }
1717

18-
public ChangeLogItem(string workItemId, string title, string description, string workitemType)
18+
public ChangeLogItem(string workItemId, string title, string description, string workItemType)
1919
{
2020
WorkItemId = workItemId;
2121
Title = title;
2222
Description = description;
23-
WorkItemType = workitemType;
23+
WorkItemType = workItemType;
2424

2525
Validate();
2626
}
2727

28+
public void Update(string title, string workItemType, string description)
29+
{
30+
Title = title;
31+
WorkItemType = workItemType;
32+
Description = description;
33+
}
34+
2835
public void Release(string changeLogId)
2936
{
3037
ChangeLogId = changeLogId;

AzureDevopsTracker/Entities/WorkItem.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class WorkItem : Entity
2222
public string Activity { get; private set; }
2323
public string Lancado { get; private set; }
2424

25-
public string ChangeLogItemId { get; private set; }
2625
public ChangeLogItem ChangeLogItem { get; private set; }
2726

2827
private readonly List<WorkItemChange> _workItemsChanges;
@@ -111,10 +110,9 @@ public void ClearTimesByState()
111110

112111
public void VinculateChangeLogItem(ChangeLogItem changeLogItem)
113112
{
114-
if (ChangeLogItem == null)
113+
if (changeLogItem == null)
115114
throw new Exception("ChangeLogItem is null");
116115

117-
ChangeLogItemId = changeLogItem.Id;
118116
ChangeLogItem = changeLogItem;
119117
}
120118

AzureDevopsTracker/Migrations/20211206211800_Adding_ChangeLog.Designer.cs renamed to AzureDevopsTracker/Migrations/20211213213716_Adding_ChangeLog.Designer.cs

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AzureDevopsTracker/Migrations/20211206211800_Adding_ChangeLog.cs renamed to AzureDevopsTracker/Migrations/20211213213716_Adding_ChangeLog.cs

Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,14 @@ public partial class Adding_ChangeLog : Migration
88
{
99
protected override void Up(MigrationBuilder migrationBuilder)
1010
{
11-
migrationBuilder.AddColumn<string>(
12-
name: "ChangeLogItemId",
13-
schema: DataBaseConfig.SchemaName,
14-
table: "WorkItems",
15-
type: "varchar(200)",
16-
nullable: true);
17-
18-
migrationBuilder.AddColumn<string>(
19-
name: "ChangeLogItemId1",
20-
schema: DataBaseConfig.SchemaName,
21-
table: "WorkItems",
22-
type: "varchar(200)",
23-
nullable: true);
24-
2511
migrationBuilder.CreateTable(
2612
name: "ChangeLogs",
2713
schema: DataBaseConfig.SchemaName,
2814
columns: table => new
2915
{
3016
Id = table.Column<string>(type: "varchar(200)", nullable: false),
3117
CreatedAt = table.Column<DateTime>(nullable: false),
32-
Response = table.Column<string>(type: "varchar(200)", nullable: true),
18+
Response = table.Column<string>(type: "varchar(max)", nullable: true),
3319
Revision = table.Column<int>(nullable: false)
3420
},
3521
constraints: table =>
@@ -46,7 +32,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
4632
CreatedAt = table.Column<DateTime>(nullable: false),
4733
WorkItemId = table.Column<string>(type: "varchar(200)", nullable: true),
4834
Title = table.Column<string>(type: "varchar(200)", nullable: true),
49-
Description = table.Column<string>(type: "varchar(200)", nullable: true),
35+
Description = table.Column<string>(type: "varchar(max)", nullable: true),
5036
WorkItemType = table.Column<string>(type: "varchar(200)", nullable: true),
5137
ChangeLogId = table.Column<string>(type: "varchar(200)", nullable: true)
5238
},
@@ -60,60 +46,39 @@ protected override void Up(MigrationBuilder migrationBuilder)
6046
principalTable: "ChangeLogs",
6147
principalColumn: "Id",
6248
onDelete: ReferentialAction.Restrict);
49+
table.ForeignKey(
50+
name: "FK_ChangeLogItems_WorkItems_WorkItemId",
51+
column: x => x.WorkItemId,
52+
principalSchema: DataBaseConfig.SchemaName,
53+
principalTable: "WorkItems",
54+
principalColumn: "Id",
55+
onDelete: ReferentialAction.Restrict);
6356
});
6457

65-
migrationBuilder.CreateIndex(
66-
name: "IX_WorkItems_ChangeLogItemId1",
67-
schema: DataBaseConfig.SchemaName,
68-
table: "WorkItems",
69-
column: "ChangeLogItemId1");
70-
7158
migrationBuilder.CreateIndex(
7259
name: "IX_ChangeLogItems_ChangeLogId",
7360
schema: DataBaseConfig.SchemaName,
7461
table: "ChangeLogItems",
7562
column: "ChangeLogId");
7663

77-
migrationBuilder.AddForeignKey(
78-
name: "FK_WorkItems_ChangeLogItems_ChangeLogItemId1",
64+
migrationBuilder.CreateIndex(
65+
name: "IX_ChangeLogItems_WorkItemId",
7966
schema: DataBaseConfig.SchemaName,
80-
table: "WorkItems",
81-
column: "ChangeLogItemId1",
82-
principalSchema: DataBaseConfig.SchemaName,
83-
principalTable: "ChangeLogItems",
84-
principalColumn: "Id",
85-
onDelete: ReferentialAction.Restrict);
67+
table: "ChangeLogItems",
68+
column: "WorkItemId",
69+
unique: true,
70+
filter: "[WorkItemId] IS NOT NULL");
8671
}
8772

8873
protected override void Down(MigrationBuilder migrationBuilder)
8974
{
90-
migrationBuilder.DropForeignKey(
91-
name: "FK_WorkItems_ChangeLogItems_ChangeLogItemId1",
92-
schema: DataBaseConfig.SchemaName,
93-
table: "WorkItems");
94-
9575
migrationBuilder.DropTable(
9676
name: "ChangeLogItems",
9777
schema: DataBaseConfig.SchemaName);
9878

9979
migrationBuilder.DropTable(
10080
name: "ChangeLogs",
10181
schema: DataBaseConfig.SchemaName);
102-
103-
migrationBuilder.DropIndex(
104-
name: "IX_WorkItems_ChangeLogItemId1",
105-
schema: DataBaseConfig.SchemaName,
106-
table: "WorkItems");
107-
108-
migrationBuilder.DropColumn(
109-
name: "ChangeLogItemId",
110-
schema: DataBaseConfig.SchemaName,
111-
table: "WorkItems");
112-
113-
migrationBuilder.DropColumn(
114-
name: "ChangeLogItemId1",
115-
schema: DataBaseConfig.SchemaName,
116-
table: "WorkItems");
11782
}
11883
}
11984
}

AzureDevopsTracker/Migrations/AzureDevopsStateTrackerContextModelSnapshot.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
3030
.HasColumnType("datetime2");
3131

3232
b.Property<string>("Response")
33-
.HasColumnType("varchar(200)");
33+
.HasColumnType("varchar(max)");
3434

3535
b.Property<int>("Revision")
3636
.HasColumnType("int");
@@ -52,7 +52,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
5252
.HasColumnType("datetime2");
5353

5454
b.Property<string>("Description")
55-
.HasColumnType("varchar(200)");
55+
.HasColumnType("varchar(max)");
5656

5757
b.Property<string>("Title")
5858
.HasColumnType("varchar(200)");
@@ -67,6 +67,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
6767

6868
b.HasIndex("ChangeLogId");
6969

70+
b.HasIndex("WorkItemId")
71+
.IsUnique()
72+
.HasFilter("[WorkItemId] IS NOT NULL");
73+
7074
b.ToTable("ChangeLogItems");
7175
});
7276

@@ -111,12 +115,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
111115
b.Property<string>("AssignedTo")
112116
.HasColumnType("varchar(200)");
113117

114-
b.Property<string>("ChangeLogItemId")
115-
.HasColumnType("varchar(200)");
116-
117-
b.Property<string>("ChangeLogItemId1")
118-
.HasColumnType("varchar(200)");
119-
120118
b.Property<DateTime>("CreatedAt")
121119
.HasColumnType("datetime2");
122120

@@ -155,8 +153,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
155153

156154
b.HasKey("Id");
157155

158-
b.HasIndex("ChangeLogItemId1");
159-
160156
b.ToTable("WorkItems");
161157
});
162158

@@ -204,6 +200,10 @@ protected override void BuildModel(ModelBuilder modelBuilder)
204200
b.HasOne("AzureDevopsTracker.Entities.ChangeLog", "ChangeLog")
205201
.WithMany("ChangeLogItems")
206202
.HasForeignKey("ChangeLogId");
203+
204+
b.HasOne("AzureDevopsTracker.Entities.WorkItem", null)
205+
.WithOne("ChangeLogItem")
206+
.HasForeignKey("AzureDevopsTracker.Entities.ChangeLogItem", "WorkItemId");
207207
});
208208

209209
modelBuilder.Entity("AzureDevopsTracker.Entities.TimeByState", b =>
@@ -213,13 +213,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
213213
.HasForeignKey("WorkItemId");
214214
});
215215

216-
modelBuilder.Entity("AzureDevopsTracker.Entities.WorkItem", b =>
217-
{
218-
b.HasOne("AzureDevopsTracker.Entities.ChangeLogItem", "ChangeLogItem")
219-
.WithMany()
220-
.HasForeignKey("ChangeLogItemId1");
221-
});
222-
223216
modelBuilder.Entity("AzureDevopsTracker.Entities.WorkItemChange", b =>
224217
{
225218
b.HasOne("AzureDevopsTracker.Entities.WorkItem", "WorkItem")

0 commit comments

Comments
 (0)