diff --git a/CSM Database Core/Abstractions/Bases/DatabaseBase.cs b/CSM Database Core/Abstractions/Bases/DatabaseBase.cs index f36490a..e91c45c 100644 --- a/CSM Database Core/Abstractions/Bases/DatabaseBase.cs +++ b/CSM Database Core/Abstractions/Bases/DatabaseBase.cs @@ -263,35 +263,7 @@ protected override void OnModelCreating(ModelBuilder mBuilder) { etBuilder.HasKey(nameof(IEntity.Id)); etBuilder.Property(nameof(IEntity.Id)).IsRequired(); - if (entity is INamedEntity) { - PropertyInfo nameProperty = entity.GetProperty(nameof(INamedEntity.Name)); - PropertyInfo descriptionProperty = entity.GetProperty(nameof(INamedEntity.Description)); - - etBuilder.HasIndex(nameProperty.Name).IsUnique(); - etBuilder.Property(nameProperty.Name).HasMaxLength(100).IsRequired(); - - etBuilder.Property(descriptionProperty.Name).HasMaxLength(200); - } - - if (entity is IReferencedEntity) { - PropertyInfo referenceProperty = entity.GetProperty(nameof(IReferencedEntity.Reference)); - - etBuilder.HasIndex(referenceProperty.Name) - .IsUnique(); - - etBuilder.Property(referenceProperty.Name) - .HasMaxLength(8) - .IsFixedLength() - .IsRequired(); - } - - if (entity is IActivableEntity) { - PropertyInfo isEnabledProperty = entity.GetProperty(nameof(IActivableEntity.IsEnabled)); - - etBuilder.Property(isEnabledProperty.Name) - .IsRequired(); - } - + DesignEntityInterfacing(etBuilder, entity); DesignEntity(entity, etBuilder); etBuilder.Property(nameof(IEntity.Timestamp)) @@ -305,6 +277,39 @@ protected override void OnModelCreating(ModelBuilder mBuilder) { base.OnModelCreating(mBuilder); } + + /// + /// Design business interfacing for business entities with their defined properties and behavior. + /// + /// + /// Entity model builder. + /// + /// + /// Entity instance modeled. + /// + static void DesignEntityInterfacing(EntityTypeBuilder etBuilder, EntityBase entity) { + if (entity is INamedEntity) { + PropertyInfo nameProperty = entity.GetProperty(nameof(INamedEntity.Name)); + PropertyInfo descriptionProperty = entity.GetProperty(nameof(INamedEntity.Description)); + + etBuilder + .HasIndex(nameProperty.Name) + .IsUnique(); + etBuilder + .Property(nameProperty.Name) + .HasMaxLength(100).IsRequired(); + + etBuilder + .Property(descriptionProperty.Name); + } + + if (entity is IActivableEntity) { + PropertyInfo isEnabledProperty = entity.GetProperty(nameof(IActivableEntity.IsEnabled)); + + etBuilder.Property(isEnabledProperty.Name) + .IsRequired(); + } + } } /// diff --git a/CSM Database Core/Abstractions/Bases/DatabaseDesignFactoryBase.cs b/CSM Database Core/Abstractions/Bases/DatabaseDesignerBase.cs similarity index 94% rename from CSM Database Core/Abstractions/Bases/DatabaseDesignFactoryBase.cs rename to CSM Database Core/Abstractions/Bases/DatabaseDesignerBase.cs index ca0175d..0321bef 100644 --- a/CSM Database Core/Abstractions/Bases/DatabaseDesignFactoryBase.cs +++ b/CSM Database Core/Abstractions/Bases/DatabaseDesignerBase.cs @@ -13,7 +13,7 @@ namespace CSM_Database_Core.Abstractions.Bases; /// /// Type of the to build. /// -public class DatabaseDesignFactoryBase +public class DatabaseDesignerBase : IDesignTimeDbContextFactory where TDatabase : DbContext, IDatabase, new() { diff --git a/CSM Database Core/CHANGELOG.md b/CSM Database Core/CHANGELOG.md index cbb642c..4d90278 100644 --- a/CSM Database Core/CHANGELOG.md +++ b/CSM Database Core/CHANGELOG.md @@ -1,12 +1,36 @@ # CSM Database Core CHANGELOG +## [7.0.0] - 21.07-2026 + +### Changes + +- Now when database connection options weren't found on app assemblies a detailed console message is displayed on Design an Development time. + +### Breaks + +- Now [NamedEntity] have new properties definitions. + + - [Description]: Now it doesn't have length limit. + - [Name]: Now is unique along entities. + +- Renamed [DatabaseDesignFactoryBase] to [DatabaseDesignerBase] to keep shorter naming conventions with sense. +- Removed [CatalogEntity] and [ReferencedEntity] since [NamedEntities] have enough properties to deteermine an entity efficient search and constant referencing. + +### Dependencies + +| Package | Previous Version | New Version | +|:----------------------------------------|:----------------:|:---------------:| +| CSM.Foundation.Core | 4.0.0 | 4.0.0 | +| Microsoft.EntityFrameworkCore | 10.0.9 | 10.0.10 | +| Microsoft.EntityFrameworkCore.SqlServer | 10.0.9 | 10.0.10 | + ## [6.1.0] - 24.06-2026 -### Added +### Changes - Now relations are able to be added no matter what direction of relationship they have at update operations. -#### Dependencies +### Dependencies | Package | Previous Version | New Version | |:----------------------------------------|:----------------:|:---------------:| @@ -20,7 +44,7 @@ - Fixed [DepotBase] [Update] method issue for a safe entity relation update just when the Ids are different. -#### Dependencies +### Dependencies | Package | Previous Version | New Version | |:----------------------------------------|:----------------:|:---------------:| @@ -34,7 +58,7 @@ - Fixed [DepotBase] [Update] method issue for a safe entity relation update just when the Ids are different. -#### Dependencies +### Dependencies | Package | Previous Version | New Version | |:----------------------------------------|:----------------:|:---------------:| @@ -48,7 +72,7 @@ - Fixed [DepotBase] [Update] method issue that was causing not relation inclussion on original entity object. -#### Dependencies +### Dependencies | Package | Previous Version | New Version | |:----------------------------------------|:----------------:|:---------------:| @@ -62,7 +86,7 @@ - Fixed [DepotBase] [Update] method issue that was causing miss calculation of Flat relations upgrading. -#### Dependencies +### Dependencies | Package | Previous Version | New Version | |:----------------------------------------|:----------------:|:---------------:| diff --git a/CSM Database Core/CSM Database Core.csproj b/CSM Database Core/CSM Database Core.csproj index bf42dde..703a830 100644 --- a/CSM Database Core/CSM Database Core.csproj +++ b/CSM Database Core/CSM Database Core.csproj @@ -4,7 +4,7 @@ net10.0 CSM_Database_Core CSM.Database.Core - 6.1.0 + 7.0.0 Renato Urrea Cosmos (CSM) https://github.com/Cosmos-CSM/csm_database @@ -22,8 +22,8 @@ - - + + diff --git a/CSM Database Core/Core/Utils/DatabaseUtils.cs b/CSM Database Core/Core/Utils/DatabaseUtils.cs index b4236eb..b2e3f9b 100644 --- a/CSM Database Core/Core/Utils/DatabaseUtils.cs +++ b/CSM Database Core/Core/Utils/DatabaseUtils.cs @@ -44,7 +44,7 @@ static ConnectionOptions GetTestingConnectionOptions(string sign) { string connVar = string.Format(Q_CONNTION_TMPLATE, sign); string connPath = Environment.GetEnvironmentVariable(connVar) - ?? throw new Exception($" Testing connection options path variable not found for ({sign}) (Make sure the environment variable [{connVar}] is set at the .runsettings tests context file)"); + ?? throw new Exception($"Testing connection options path variable not found for ({sign}) (Make sure the environment variable [{connVar}] is set at the .runsettings tests context file)"); using FileStream fileReader = new(connPath, FileMode.Open, FileAccess.Read); @@ -111,10 +111,24 @@ public static ConnectionOptions GetConnectionOptions(string sign, bool forTestin string fileName = $"{sign.ToLower()}.{envPrefix}.connection.json"; string[] appDirFiles = Directory.GetFiles(appDir); - string appDirConnFile = appDirFiles - .Where(file => file.Contains(fileName)) - .FirstOrDefault() - ?? throw new FileNotFoundException($"{appDir}\\{fileName} not in app assemblies"); + string? appDirConnFile = appDirFiles + .FirstOrDefault(file => file.Contains(fileName)); + + if(appDirConnFile is null) { + ConsoleUtils.Error( + "Database connection options not found in app assemblies", + details: new Dictionary { + { "Environment Variable Name", envVarName }, + { "Environment Variable Value", envVarValue }, + { "Environment Variable Target", usedEnvTarget }, + { "Assemblies Directory", AppContext.BaseDirectory }, + { "Signature", sign }, + { "File", fileName }, + } + ); + + throw new FileNotFoundException($"{appDir}\\{fileName} not in app assemblies"); + } filePath = appDirConnFile; } @@ -212,7 +226,7 @@ public static async Task SanitizeEntity(DbContext database, TE bool isEntity = relType.IsAssignableTo(typeof(IEntity)); bool isCollectionOfEntities = false; - if(!isEntity) { + if (!isEntity) { Type genericDefinition = relType.GetGenericTypeDefinition(); bool isCollection = genericDefinition.IsAssignableTo(typeof(ICollection<>)); diff --git a/CSM Database Core/Entities/Abstractions/Bases/CatalogEntityBase.cs b/CSM Database Core/Entities/Abstractions/Bases/CatalogEntityBase.cs deleted file mode 100644 index b7217b2..0000000 --- a/CSM Database Core/Entities/Abstractions/Bases/CatalogEntityBase.cs +++ /dev/null @@ -1,16 +0,0 @@ -using CSM_Database_Core.Entities.Abstractions.Interfaces; - -namespace CSM_Database_Core.Entities.Abstractions.Bases; - -/// -/// Represents an with catalog identification properties. -/// -public abstract class CatalogEntityBase - : NamedEntityBase, ICatalogEntity { - - /// - public string Reference { get; set; } = string.Empty; - - /// - public bool IsEnabled { get; set; } -} diff --git a/CSM Database Core/Entities/Abstractions/Bases/ReferencedEntityBase.cs b/CSM Database Core/Entities/Abstractions/Bases/ReferencedEntityBase.cs deleted file mode 100644 index 160ed64..0000000 --- a/CSM Database Core/Entities/Abstractions/Bases/ReferencedEntityBase.cs +++ /dev/null @@ -1,14 +0,0 @@ -using CSM_Database_Core.Entities.Abstractions.Interfaces; - -namespace CSM_Database_Core.Entities.Abstractions.Bases; - -/// -/// Represents an with a unique property wich allows its identification along -/// data storages migrations as this property is absolute static. -/// -public abstract class ReferencedEntityBase - : EntityBase, IReferencedEntity { - - /// - public string Reference { get; set; } = string.Empty; -} \ No newline at end of file diff --git a/CSM Database Core/Entities/Abstractions/Interfaces/IActivableEntity.cs b/CSM Database Core/Entities/Abstractions/Interfaces/IActivableEntity.cs index 6e988d7..cf9876c 100644 --- a/CSM Database Core/Entities/Abstractions/Interfaces/IActivableEntity.cs +++ b/CSM Database Core/Entities/Abstractions/Interfaces/IActivableEntity.cs @@ -1,6 +1,4 @@ -using CSM_Database_Core.Entities.Abstractions.Bases; - -namespace CSM_Database_Core.Entities.Abstractions.Interfaces; +namespace CSM_Database_Core.Entities.Abstractions.Interfaces; /// /// Represents an with enablement control. /// diff --git a/CSM Database Core/Entities/Abstractions/Interfaces/ICatalogEntity.cs b/CSM Database Core/Entities/Abstractions/Interfaces/ICatalogEntity.cs deleted file mode 100644 index 86f0256..0000000 --- a/CSM Database Core/Entities/Abstractions/Interfaces/ICatalogEntity.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace CSM_Database_Core.Entities.Abstractions.Interfaces; - - -/// -/// Represents an with catalog identification properties. -/// -public interface ICatalogEntity - : IEntity, INamedEntity, IReferencedEntity, IActivableEntity { -} diff --git a/CSM Database Core/Entities/Abstractions/Interfaces/IPartnerScopeEntity.cs b/CSM Database Core/Entities/Abstractions/Interfaces/IPartnerScopeEntity.cs index 5b5d486..d4fb1f5 100644 --- a/CSM Database Core/Entities/Abstractions/Interfaces/IPartnerScopeEntity.cs +++ b/CSM Database Core/Entities/Abstractions/Interfaces/IPartnerScopeEntity.cs @@ -1,6 +1,4 @@ -using CSM_Database_Core.Entities.Abstractions.Bases; - -namespace CSM_Database_Core.Entities.Abstractions.Interfaces; +namespace CSM_Database_Core.Entities.Abstractions.Interfaces; /// /// Represents an scope for a . /// diff --git a/CSM Database Core/Entities/Abstractions/Interfaces/IReferencedEntity.cs b/CSM Database Core/Entities/Abstractions/Interfaces/IReferencedEntity.cs deleted file mode 100644 index 9a19209..0000000 --- a/CSM Database Core/Entities/Abstractions/Interfaces/IReferencedEntity.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -using CSM_Database_Core.Entities.Abstractions.Bases; - -namespace CSM_Database_Core.Entities.Abstractions.Interfaces; - -/// -/// Represents an with a unique property wich allows its identification along -/// data storages migrations as this property is absolute static. -/// -public interface IReferencedEntity - : IEntity { - - /// - /// Unique reference value. - /// - /// - /// It's lenght must be strict 8. - /// - [StringLength(8, MinimumLength = 8)] - public string Reference { get; set; } -} \ No newline at end of file diff --git a/CSM Database Testing/BaseDraftUtils.cs b/CSM Database Testing/BaseDraftUtils.cs index fc09a81..d2d762a 100644 --- a/CSM Database Testing/BaseDraftUtils.cs +++ b/CSM Database Testing/BaseDraftUtils.cs @@ -95,53 +95,6 @@ static public TActivableEntity ActivableEntity(TActivableEntit return @ref; } - /// - /// Drafts a instance with random data. - /// - /// - /// Type of the entity to draft. - /// - /// - /// Default entity values. - /// - /// - /// A drafted instance. - /// - static public TCatalogEntity CatalogEntity(TCatalogEntity? @ref = default) - where TCatalogEntity : ICatalogEntity, new() { - - @ref ??= Entity(@ref); - @ref = NamedEntity(@ref); - @ref = ReferencedEntity(@ref); - @ref = ActivableEntity(@ref); - - return @ref; - } - - /// - /// Drafts a instance with random data. - /// - /// - /// Type of the entity to draft. - /// - /// - /// Default values for the entity. - /// - /// - /// A drafted instance. - /// - static public TReferencedEntity ReferencedEntity(TReferencedEntity? @ref = default) - where TReferencedEntity : IReferencedEntity, new() { - - @ref ??= Entity(@ref); - - if (string.IsNullOrWhiteSpace(@ref.Reference)) { - @ref.Reference = Rnd[..8]; - } - - return @ref; - } - /// /// Drafts a instance with random data. /// diff --git a/CSM Database Testing/CHANGELOG.md b/CSM Database Testing/CHANGELOG.md index 2d23c24..008f85d 100644 --- a/CSM Database Testing/CHANGELOG.md +++ b/CSM Database Testing/CHANGELOG.md @@ -2,6 +2,19 @@ ## [7.0.2] - 18.06-2026 +### Removed + +- Removed drafting for [CatalogEntity] and [ReferencedEntity] since they were removed at version [7.0.0] of [CSM Database Core]. + +### Dependencies + +| Package | Previous Version | New Version | +|:----------------------------------------|:----------------:|:---------------:| +| CSM.Foundation.Core | 4.0.0 | 4.0.0 | +| xunit.v3 | 3.2.2 | 3.2.2 | + +## [7.0.2] - 18.06-2026 + ### Fixed - Fixed code style diff --git a/CSM Database Testing/CSM Database Testing.csproj b/CSM Database Testing/CSM Database Testing.csproj index 36c5cb7..3fb0b0b 100644 --- a/CSM Database Testing/CSM Database Testing.csproj +++ b/CSM Database Testing/CSM Database Testing.csproj @@ -4,7 +4,7 @@ net10.0 CSM_Database_Testing CSM.Database.Testing - 7.0.2 + 8.0.0 Renato Urrea Cosmos (CSM) https://github.com/Cosmos-CSM/csm_database diff --git a/local.integration_tests.runsettings b/local.integration_tests.runsettings index 0c53b74..ad856dc 100644 --- a/local.integration_tests.runsettings +++ b/local.integration_tests.runsettings @@ -4,7 +4,7 @@ net10.0 TestResults - C:\Users\Usuar\Desktop\projects\Cosmos (CSM)\csm_database\DatabaseProxy\csmdq.dev.connection.json + C:\Users\Usuar\Desktop\workspaces\Cosmos (CSM)\csm_database\DatabaseProxy\csmdq.dev.connection.json \ No newline at end of file