Skip to content

Commit

Permalink
feat: Add IdLength constant to DbContextBase
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-dudarev committed Sep 30, 2024
1 parent 0a8f491 commit 61d3e4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace VirtoCommerce.Platform.Data.Infrastructure
/// </summary>
public class DbContextBase : DbContextWithTriggers
{
public const int IdLength = 128;

public DbContextBase()
{
}
Expand Down
21 changes: 12 additions & 9 deletions src/VirtoCommerce.Platform.Data/Repositories/PlatformDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.EntityFrameworkCore;
using VirtoCommerce.Platform.Data.Infrastructure;
using VirtoCommerce.Platform.Data.Localizations;
Expand All @@ -7,7 +8,9 @@ namespace VirtoCommerce.Platform.Data.Repositories
{
public class PlatformDbContext : DbContextBase
{
[Obsolete("Use IdLength", DiagnosticId = "VC0009", UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions")]
protected const int _idLength128 = 128;

protected const int _idLength64 = 64;
protected const int _idLength2048 = 2048;

Expand All @@ -27,7 +30,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#region Change logging
modelBuilder.Entity<OperationLogEntity>().ToTable("PlatformOperationLog").HasKey(x => x.Id);
modelBuilder.Entity<OperationLogEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<OperationLogEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<OperationLogEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<OperationLogEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<OperationLogEntity>().Property(x => x.Detail).HasMaxLength(_idLength2048);
Expand All @@ -38,15 +41,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#region Settings
modelBuilder.Entity<SettingEntity>().ToTable("PlatformSetting").HasKey(x => x.Id);
modelBuilder.Entity<SettingEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<SettingEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<SettingEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<SettingEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<SettingEntity>().HasIndex(x => new { x.ObjectType, x.ObjectId })
.IsUnique(false)
.HasDatabaseName("IX_ObjectType_ObjectId");

modelBuilder.Entity<SettingValueEntity>().ToTable("PlatformSettingValue").HasKey(x => x.Id);
modelBuilder.Entity<SettingValueEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<SettingValueEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<SettingValueEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<SettingValueEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);

Expand All @@ -64,7 +67,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#region Localization
modelBuilder.Entity<LocalizedItemEntity>().ToTable("PlatformLocalizedItem").HasKey(x => x.Id);
modelBuilder.Entity<LocalizedItemEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<LocalizedItemEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<LocalizedItemEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<LocalizedItemEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<LocalizedItemEntity>()
Expand All @@ -76,15 +79,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
#region Dynamic Properties

modelBuilder.Entity<DynamicPropertyEntity>().ToTable("PlatformDynamicProperty").HasKey(x => x.Id);
modelBuilder.Entity<DynamicPropertyEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyEntity>().HasIndex(x => new { x.ObjectType, x.Name })
.HasDatabaseName("IX_PlatformDynamicProperty_ObjectType_Name")
.IsUnique(true);

modelBuilder.Entity<DynamicPropertyNameEntity>().ToTable("PlatformDynamicPropertyName").HasKey(x => x.Id);
modelBuilder.Entity<DynamicPropertyNameEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyNameEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyNameEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyNameEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyNameEntity>().HasOne(x => x.Property)
Expand All @@ -97,7 +100,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.IsUnique(true);

modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().ToTable("PlatformDynamicPropertyDictionaryItem").HasKey(x => x.Id);
modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyDictionaryItemEntity>().HasOne(x => x.Property)
Expand All @@ -110,7 +113,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.IsUnique(true);

modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().ToTable("PlatformDynamicPropertyDictionaryItemName").HasKey(x => x.Id);
modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().Property(x => x.CreatedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().Property(x => x.ModifiedBy).HasMaxLength(_idLength64);
modelBuilder.Entity<DynamicPropertyDictionaryItemNameEntity>().HasOne(x => x.DictionaryItem)
Expand All @@ -126,7 +129,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#region Raw license
modelBuilder.Entity<RawLicenseEntity>().ToTable("RawLicense").HasKey(x => x.Id);
modelBuilder.Entity<RawLicenseEntity>().Property(x => x.Id).HasMaxLength(_idLength128).ValueGeneratedOnAdd();
modelBuilder.Entity<RawLicenseEntity>().Property(x => x.Id).HasMaxLength(IdLength).ValueGeneratedOnAdd();
modelBuilder.Entity<RawLicenseEntity>().Property(x => x.Data);
#endregion
}
Expand Down

0 comments on commit 61d3e4f

Please sign in to comment.