Skip to content

Commit e847204

Browse files
jaybarden1jbarden
andauthored
Features/continue recreating dbcontext extensions (#4)
* A bunch of clean-up * Update migrations and continue with FileDetail extensions * Fix missed test * Glad that the password isn't for production! Or, for that matter anywhere but still... Oops! * Quite possibly pointless but playing with separating the Sonar step * Bring in offline updates * Update test data and impacted tests * Fix path in the previous commit. My bad * Small cleanup --------- Co-authored-by: Jason Barden <[email protected]>
1 parent 6ed5d6f commit e847204

File tree

80 files changed

+138571
-4629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+138571
-4629
lines changed

.editorconfig

Lines changed: 280 additions & 292 deletions
Large diffs are not rendered by default.

.github/workflows/main_astar-dev.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build .NET Core application
1+
name: Build and analyse the DatabaseTesting Solution
22
on:
33
pull_request:
44
types: [ opened, synchronize, reopened ]
@@ -50,14 +50,23 @@ jobs:
5050
New-Item -Path .\.sonar\scanner -ItemType Directory
5151
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
5252
53-
- name: 🔍 Restore, 🛠 Build and 🧪 Test with ☁️ SonarCloud / Qube
53+
- name: 🔍 Restore,
54+
shell: powershell
55+
run: |
56+
dotnet restore
57+
58+
- name: 🛠 Build
59+
shell: powershell
60+
run: |
61+
dotnet build --no-restore
62+
63+
- name: 🧪 Test and analyse with ☁️ SonarCloud / Qube
5464
env:
5565
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5666
shell: powershell
5767
run: |
5868
dotnet tool install --global dotnet-coverage
5969
.\.sonar\scanner\dotnet-sonarscanner begin /k:"astar-development_astar-dev-database-testing" /o:"astar-development" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.scanner.scanAll=false /d:sonar.scanner.skipJreProvisioning=true
60-
dotnet build
6170
dotnet-coverage collect 'dotnet test --filter "FullyQualifiedName!~Tests.EndToEnd"' -f xml -o 'coverage.xml'
6271
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
6372
#

src/AStar.Dev.Infrastructure.FilesDb/AStar.Dev.Infrastructure.FilesDb.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,29 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="AStar.Dev.Functional.Extensions" Version="0.2.0" />
24-
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.0.15" />
25-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.7" />
23+
<PackageReference Include="AStar.Dev.Functional.Extensions" Version="0.2.0"/>
24+
<PackageReference Include="TestableIO.System.IO.Abstractions.Wrappers" Version="22.0.15"/>
25+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.7"/>
2626
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.7">
2727
<PrivateAssets>all</PrivateAssets>
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2929
</PackageReference>
30-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7" />
30+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.7"/>
3131
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.7">
3232
<PrivateAssets>all</PrivateAssets>
3333
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3434
</PackageReference>
3535
</ItemGroup>
3636

3737
<ItemGroup>
38-
<None Include="LICENSE" Pack="true" PackagePath="" />
39-
<None Include="Readme.md" Pack="true" PackagePath="" />
38+
<None Include="LICENSE" Pack="true" PackagePath=""/>
39+
<None Include="Readme.md" Pack="true" PackagePath=""/>
4040
</ItemGroup>
4141

4242
<ItemGroup>
4343
<ProjectReference Include="..\..\support\AStar.Dev.Technical.Debt.Reporting\AStar.Dev.Technical.Debt.Reporting.csproj"/>
4444
<ProjectReference Include="..\..\support\AStar.Dev.Utilities\AStar.Dev.Utilities.csproj"/>
45-
<ProjectReference Include="..\AStar.Dev.Infrastructure\AStar.Dev.Infrastructure.csproj" />
45+
<ProjectReference Include="..\AStar.Dev.Infrastructure\AStar.Dev.Infrastructure.csproj"/>
4646
</ItemGroup>
4747

4848
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/AStar.Dev.Infrastructure.FilesDb/AStar.Dev.Infrastructure.FilesDb.xml

Lines changed: 243 additions & 99 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AStar.Dev.Infrastructure.FilesDb/Data/Configurations/DirectoryNameConfiguration.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ namespace AStar.Dev.Infrastructure.FilesDb.Data.Configurations;
77

88
internal sealed class DirectoryNameConfiguration : IComplexPropertyConfiguration<DirectoryName>
99
{
10-
public void Configure(ComplexPropertyBuilder<DirectoryName> builder)
11-
{
10+
public void Configure(ComplexPropertyBuilder<DirectoryName> builder) =>
1211
builder.Property(directoryName => directoryName.Value)
13-
.HasColumnName("DirectoryName")
14-
.HasColumnType("nvarchar(256)");
15-
}
12+
.HasColumnName("DirectoryName")
13+
.HasColumnType("nvarchar(256)");
1614
}

src/AStar.Dev.Infrastructure.FilesDb/Data/Configurations/FileDetailConfiguration.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using AStar.Dev.Infrastructure.Data.Configurations;
1+
using AStar.Dev.Infrastructure.Data.Configurations;
22
using AStar.Dev.Infrastructure.FilesDb.Models;
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
@@ -19,10 +19,7 @@ public void Configure(EntityTypeBuilder<FileDetail> builder)
1919
builder.Property(file => file.Id)
2020
.HasConversion(fileId => fileId.Value, fileId => new (fileId));
2121

22-
builder.Property(file => file.FileName)
23-
.HasColumnType("nvarchar(256)")
24-
.HasConversion(fileName => fileName.Value, fileName => new (fileName));
25-
22+
builder.Ignore(fileDetail => fileDetail.FileName);
2623
builder.Ignore(fileDetail => fileDetail.DirectoryName);
2724
builder.Ignore(fileDetail => fileDetail.FullNameWithPath);
2825

@@ -31,16 +28,23 @@ public void Configure(EntityTypeBuilder<FileDetail> builder)
3128
.HasConversion(fileHandle => fileHandle.Value, fileHandle => new (fileHandle));
3229

3330
builder.ComplexProperty(fileDetail => fileDetail.ImageDetail)
34-
.Configure(new ImageDetailConfiguration());
31+
.Configure(new ImageDetailConfiguration());
32+
3533
builder.ComplexProperty(fileDetail => fileDetail.DirectoryName)
36-
.Configure(new DirectoryNameConfiguration());
34+
.Configure(new DirectoryNameConfiguration());
35+
36+
builder.ComplexProperty(fileDetail => fileDetail.FileName)
37+
.Configure(new FileNameConfiguration());
3738

3839
builder.ComplexProperty(fileDetail => fileDetail.DeletionStatus)
3940
.Configure(new DeletionStatusConfiguration());
4041

41-
// Will want the handle to be unique, but not yet
42-
builder.HasIndex(fileDetail => fileDetail.FileHandle);
43-
builder.HasIndex(fileDetail => fileDetail.FileName);
42+
builder.HasIndex(fileDetail => fileDetail.FileHandle).IsUnique();
4443
builder.HasIndex(fileDetail => fileDetail.FileSize);
44+
45+
// Composite index to optimize duplicate images search (partial optimization)
46+
// Note: ImageHeight and ImageWidth can't be indexed directly as they're complex properties
47+
builder.HasIndex(fileDetail => new { fileDetail.IsImage, fileDetail.FileSize })
48+
.HasDatabaseName("IX_FileDetail_DuplicateImages");
4549
}
4650
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using AStar.Dev.Infrastructure.Data.Configurations;
2+
using AStar.Dev.Infrastructure.FilesDb.Models;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
6+
namespace AStar.Dev.Infrastructure.FilesDb.Data.Configurations;
7+
8+
internal sealed class FileNameConfiguration : IComplexPropertyConfiguration<FileName>
9+
{
10+
public void Configure(ComplexPropertyBuilder<FileName> builder) =>
11+
builder.Property(fileName => fileName.Value)
12+
.HasColumnName("FileName")
13+
.HasColumnType("nvarchar(256)");
14+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using AStar.Dev.Infrastructure.FilesDb.Models;
2+
3+
namespace AStar.Dev.Infrastructure.FilesDb.Data;
4+
5+
/// <summary>
6+
/// </summary>
7+
public static class FileDetailDeletionStatusExtensions
8+
{
9+
/// <summary>
10+
/// </summary>
11+
/// <param name="files"></param>
12+
/// <param name="includeDeleted"></param>
13+
/// <returns></returns>
14+
public static IQueryable<FileDetail> IncludeDeletedOrDeletePending(this IQueryable<FileDetail> files, bool includeDeleted)
15+
=> includeDeleted
16+
? files
17+
: files.Where(f => f.DeletionStatus.HardDeletePending == null
18+
&& f.DeletionStatus.SoftDeletePending == null
19+
&& f.DeletionStatus.SoftDeleted == null);
20+
}

src/AStar.Dev.Infrastructure.FilesDb/Data/FileDetailDirectoryNameExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
namespace AStar.Dev.Infrastructure.FilesDb.Data;
55

66
/// <summary>
7-
///
87
/// </summary>
98
public static class FileDetailDirectoryNameExtensions
109
{
1110
/// <summary>
12-
///
1311
/// </summary>
14-
/// <param name="filesContext"></param>
12+
/// <param name="files"></param>
1513
/// <param name="directoryName"></param>
1614
/// <param name="includeSubDirectories"></param>
1715
/// <returns></returns>
18-
public static IQueryable<FileDetail> WhereDirectoryNameMatches(this IQueryable<FileDetail> filesContext, string directoryName, bool includeSubDirectories) =>
16+
public static IQueryable<FileDetail> WhereDirectoryNameMatches(this IQueryable<FileDetail> files, string directoryName, bool includeSubDirectories) =>
1917
includeSubDirectories
20-
? filesContext.Where(file => file.DirectoryName.Value.StartsWith(directoryName.RemoveTrailing(@"\")))
21-
: filesContext.Where(file => file.DirectoryName.Value == directoryName.RemoveTrailing(@"\"));
18+
? files.Where(file => file.DirectoryName.Value.Contains(directoryName.RemoveTrailing(@"\")))
19+
: files.Where(file => file.DirectoryName.Value == directoryName.RemoveTrailing(@"\"));
2220
}

src/AStar.Dev.Infrastructure.FilesDb/Data/FileDetailLastViewedExtensions.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
namespace AStar.Dev.Infrastructure.FilesDb.Data;
44

55
/// <summary>
6-
///
76
/// </summary>
87
public static class FileDetailLastViewedExtensions
98
{
109
/// <summary>
11-
/// A lot of variations of this method have been tried, but none of them worked as expected.
12-
/// This one does not work as we're using SQLite for testing, and it does not support DateTimeOffset.
10+
/// A lot of variations of this method have been tried, but none of them worked as expected.
11+
/// This one does not work as we're using SQLite for testing, and it does not support DateTimeOffset.
1312
/// </summary>
14-
/// <param name="filesContext"></param>
13+
/// <param name="files"></param>
1514
/// <param name="days"></param>
1615
/// <param name="time"></param>
1716
/// <returns></returns>
18-
public static IQueryable<FileDetail> WhereLastViewedIsOlderThan(this IQueryable<FileDetail> filesContext, int days, TimeProvider time)
17+
public static IQueryable<FileDetail> WhereLastViewedIsOlderThan(this IQueryable<FileDetail> files, int days, TimeProvider time)
1918
=> days == 0
20-
? filesContext
21-
: filesContext.Where(file => !file.FileLastViewed.HasValue || file.FileLastViewed.Value <= time.GetUtcNow().AddDays(-days));
19+
? files
20+
: files.Where(file => !file.FileLastViewed.HasValue || file.FileLastViewed.Value <= time.GetUtcNow().AddDays(-days));
2221
}

0 commit comments

Comments
 (0)