Skip to content
Merged

Dev #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions CSM Database Core/Abstractions/Bases/DatabaseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,35 +263,7 @@ protected override void OnModelCreating(ModelBuilder mBuilder) {
etBuilder.HasKey(nameof(IEntity.Id));
etBuilder.Property<long>(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))
Expand All @@ -305,6 +277,39 @@ protected override void OnModelCreating(ModelBuilder mBuilder) {

base.OnModelCreating(mBuilder);
}

/// <summary>
/// Design business interfacing for business entities with their defined properties and behavior.
/// </summary>
/// <param name="etBuilder">
/// Entity model builder.
/// </param>
/// <param name="entity">
/// Entity instance modeled.
/// </param>
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();
}
}
}

/// <inheritdoc cref="EntityBase"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CSM_Database_Core.Abstractions.Bases;
/// <typeparam name="TDatabase">
/// Type of the <see cref="IDatabase"/> to build.
/// </typeparam>
public class DatabaseDesignFactoryBase<TDatabase>
public class DatabaseDesignerBase<TDatabase>
: IDesignTimeDbContextFactory<TDatabase>
where TDatabase : DbContext, IDatabase, new() {

Expand Down
36 changes: 30 additions & 6 deletions CSM Database Core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 |
|:----------------------------------------|:----------------:|:---------------:|
Expand All @@ -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 |
|:----------------------------------------|:----------------:|:---------------:|
Expand All @@ -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 |
|:----------------------------------------|:----------------:|:---------------:|
Expand All @@ -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 |
|:----------------------------------------|:----------------:|:---------------:|
Expand All @@ -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 |
|:----------------------------------------|:----------------:|:---------------:|
Expand Down
6 changes: 3 additions & 3 deletions CSM Database Core/CSM Database Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net10.0</TargetFrameworks>
<RootNamespace>CSM_Database_Core</RootNamespace>
<PackageId>CSM.Database.Core</PackageId>
<Version>6.1.0</Version>
<Version>7.0.0</Version>
<Authors>Renato Urrea</Authors>
<Company>Cosmos (CSM)</Company>
<RepositoryUrl>https://github.com/Cosmos-CSM/csm_database</RepositoryUrl>
Expand All @@ -22,8 +22,8 @@

<ItemGroup>
<PackageReference Include="CSM.Foundation.Core" Version="4.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.10" />
</ItemGroup>

</Project>
26 changes: 20 additions & 6 deletions CSM Database Core/Core/Utils/DatabaseUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<string, object?> {
{ "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;
}
Expand Down Expand Up @@ -212,7 +226,7 @@ public static async Task<TEntity> SanitizeEntity<TEntity>(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<>));

Expand Down
16 changes: 0 additions & 16 deletions CSM Database Core/Entities/Abstractions/Bases/CatalogEntityBase.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
/// <summary>
/// Represents an <see cref="IEntity"/> with enablement control.
/// </summary>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
/// <summary>
/// Represents an <see cref="IEntity"/> scope for a <see cref="IPartnerBridgeEntity"/>.
/// </summary>
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions CSM Database Testing/BaseDraftUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,53 +95,6 @@ static public TActivableEntity ActivableEntity<TActivableEntity>(TActivableEntit
return @ref;
}

/// <summary>
/// Drafts a <typeparamref name="TCatalogEntity"/> instance with random data.
/// </summary>
/// <typeparam name="TCatalogEntity">
/// Type of the entity to draft.
/// </typeparam>
/// <param name="ref">
/// Default entity values.
/// </param>
/// <returns>
/// A drafted <typeparamref name="TCatalogEntity"/> instance.
/// </returns>
static public TCatalogEntity CatalogEntity<TCatalogEntity>(TCatalogEntity? @ref = default)
where TCatalogEntity : ICatalogEntity, new() {

@ref ??= Entity(@ref);
@ref = NamedEntity(@ref);
@ref = ReferencedEntity(@ref);
@ref = ActivableEntity(@ref);

return @ref;
}

/// <summary>
/// Drafts a <typeparamref name="TReferencedEntity"/> instance with random data.
/// </summary>
/// <typeparam name="TReferencedEntity">
/// Type of the entity to draft.
/// </typeparam>
/// <param name="ref">
/// Default values for the entity.
/// </param>
/// <returns>
/// A drafted <typeparamref name="TReferencedEntity"/> instance.
/// </returns>
static public TReferencedEntity ReferencedEntity<TReferencedEntity>(TReferencedEntity? @ref = default)
where TReferencedEntity : IReferencedEntity, new() {

@ref ??= Entity(@ref);

if (string.IsNullOrWhiteSpace(@ref.Reference)) {
@ref.Reference = Rnd[..8];
}

return @ref;
}

/// <summary>
/// Drafts a <typeparamref name="TNamedEntity"/> instance with random data.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions CSM Database Testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CSM Database Testing/CSM Database Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>CSM_Database_Testing</RootNamespace>
<PackageId>CSM.Database.Testing</PackageId>
<Version>7.0.2</Version>
<Version>8.0.0</Version>
<Authors>Renato Urrea</Authors>
<Company>Cosmos (CSM)</Company>
<RepositoryUrl>https://github.com/Cosmos-CSM/csm_database</RepositoryUrl>
Expand Down
Loading
Loading