implement Phase 1-2
This commit is contained in:
parent
41573b3c4f
commit
b976cf3124
23 changed files with 1291 additions and 79 deletions
36
backend/WordVersioning.Api/Data/AppDbContext.cs
Normal file
36
backend/WordVersioning.Api/Data/AppDbContext.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using WordVersioning.Api.Models;
|
||||
|
||||
namespace WordVersioning.Api.Data;
|
||||
|
||||
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<Document> Documents => Set<Document>();
|
||||
|
||||
public DbSet<DocumentVersion> DocumentVersions => Set<DocumentVersion>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Document>(entity =>
|
||||
{
|
||||
entity.HasKey(x => x.Id);
|
||||
entity.Property(x => x.FileName).HasMaxLength(512);
|
||||
entity.Property(x => x.AddInSignature).HasMaxLength(64);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<DocumentVersion>(entity =>
|
||||
{
|
||||
entity.HasKey(x => x.Id);
|
||||
|
||||
// กัน versionNumber ซ้ำตอน upload พร้อมกัน (retry ที่ controller เมื่อชน constraint)
|
||||
entity.HasIndex(x => new { x.DocumentId, x.VersionNumber }).IsUnique();
|
||||
|
||||
entity.Property(x => x.ObjectKey).HasMaxLength(1024);
|
||||
entity.Property(x => x.ContentHash).HasMaxLength(64);
|
||||
|
||||
entity.HasOne(x => x.Document)
|
||||
.WithMany(d => d.Versions)
|
||||
.HasForeignKey(x => x.DocumentId);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue