-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
159 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using BUTR.CrashReportServer.Contexts.Config; | ||
using BUTR.CrashReportServer.Models.Database; | ||
|
||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace BUTR.CrashReportServer.Contexts; | ||
|
||
public class FileEntityConfiguration : BaseEntityConfiguration<FileEntity> | ||
{ | ||
protected override void ConfigureModel(EntityTypeBuilder<FileEntity> builder) | ||
{ | ||
builder.Property<string>(nameof(IdEntity.FileId)).HasColumnName("file_id"); | ||
builder.Property(p => p.DataCompressed).HasColumnName("data_compressed"); | ||
builder.ToTable("file_entity").HasKey(nameof(IdEntity.FileId)).HasName("file_entity_pkey"); | ||
|
||
builder.HasOne(x => x.Id) | ||
.WithOne() | ||
.HasForeignKey<FileEntity>(nameof(IdEntity.FileId)) | ||
.HasPrincipalKey<IdEntity>(x => x.FileId) | ||
.OnDelete(DeleteBehavior.Cascade); | ||
|
||
builder.Navigation(x => x.Id).AutoInclude(); | ||
} | ||
} | ||
public class IdEntityConfiguration : BaseEntityConfiguration<IdEntity> | ||
{ | ||
protected override void ConfigureModel(EntityTypeBuilder<IdEntity> builder) | ||
{ | ||
builder.Property(x => x.FileId).HasColumnName("file_id").HasDefaultValueSql("hex(randomblob(3))"); | ||
builder.Property(x => x.CrashReportId).HasColumnName("crash_report_id"); | ||
builder.Property(x => x.Version).HasColumnName("version"); | ||
builder.Property(x => x.Created).HasColumnName("created"); | ||
builder.ToTable("id_entity").HasKey(x => x.FileId); | ||
|
||
builder.HasIndex(x => x.CrashReportId).IsUnique(false); | ||
} | ||
} | ||
public class OldJsonEntityConfiguration : BaseEntityConfiguration<OldJsonEntity> | ||
{ | ||
protected override void ConfigureModel(EntityTypeBuilder<OldJsonEntity> builder) | ||
{ | ||
builder.Property<string>(nameof(IdEntity.FileId)).HasColumnName("file_id"); | ||
builder.Property(p => p.CrashReportCompressed).HasColumnName("data_compressed"); | ||
builder.ToTable("json_entity").HasKey(nameof(IdEntity.FileId)); | ||
|
||
builder.HasOne(x => x.Id) | ||
.WithOne() | ||
.HasForeignKey<OldJsonEntity>(nameof(IdEntity.FileId)) | ||
.HasPrincipalKey<IdEntity>(x => x.FileId) | ||
.OnDelete(DeleteBehavior.Cascade); | ||
|
||
builder.Navigation(x => x.Id).AutoInclude(); | ||
} | ||
} | ||
|
||
public class OldAppDbContext : DbContext | ||
{ | ||
public OldAppDbContext(DbContextOptions<OldAppDbContext> options) : base(options) { } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
base.OnModelCreating(modelBuilder); | ||
|
||
modelBuilder.ApplyConfiguration(new IdEntityConfiguration()); | ||
modelBuilder.ApplyConfiguration(new FileEntityConfiguration()); | ||
modelBuilder.ApplyConfiguration(new OldJsonEntityConfiguration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace BUTR.CrashReportServer.Models.Database; | ||
|
||
public sealed record OldJsonEntity : IEntity | ||
{ | ||
public required IdEntity Id { get; set; } | ||
public required byte[] CrashReportCompressed { get; set; } | ||
} |
Oops, something went wrong.