-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π·ββοΈ 306 move seed data and migrations out of api (#309)
* Initial version of up.ps1 * Updated up.ps1 * Fixes from code review * Update README.md * Fixed integration tests * Removed unneeded code * Added missing call to interceptor * Removed unneeded code
- Loading branch information
1 parent
2a42120
commit 91d1b69
Showing
15 changed files
with
160 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>SSW.CleanArchitecture.Database</RootNamespace> | ||
<AssemblyName>SSW.CleanArchitecture.Database</AssemblyName> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Infrastructure\Infrastructure.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
<PackageReference Include="Bogus" Version="34.0.2" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="appsettings.json" /> | ||
<Content Include="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
ο»Ώusing Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using SSW.CleanArchitecture.Application.Common.Interfaces; | ||
using SSW.CleanArchitecture.Database; | ||
using SSW.CleanArchitecture.Infrastructure; | ||
using SSW.CleanArchitecture.Infrastructure.Persistence; | ||
using SSW.CleanArchitecture.Infrastructure.Persistence.Interceptors; | ||
|
||
var builder = Host.CreateDefaultBuilder(args); | ||
|
||
builder.ConfigureServices((context, services) => | ||
{ | ||
services.AddDbContext<ApplicationDbContext>(options => | ||
{ | ||
options.UseSqlServer(context.Configuration.GetConnectionString("DefaultConnection"), opt => | ||
{ | ||
opt.MigrationsAssembly(typeof(DependencyInjection).Assembly.FullName); | ||
}); | ||
options.AddInterceptors(services.BuildServiceProvider().GetRequiredService<EntitySaveChangesInterceptor>()); | ||
}); | ||
services.AddScoped<ApplicationDbContextInitializer>(); | ||
}); | ||
|
||
var app = builder.Build(); | ||
app.Start(); | ||
|
||
// Initialise and seed database | ||
using var scope = app.Services.CreateScope(); | ||
var initializer = scope.ServiceProvider.GetRequiredService<ApplicationDbContextInitializer>(); | ||
await initializer.InitializeAsync(); | ||
await initializer.SeedAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"ConnectionStrings": { | ||
"DefaultConnection": "Server=localhost,1433;Initial Catalog=CleanArchitecture;Persist Security Info=False;User ID=sa;Password=yourStrong(!)Password;MultipleActiveResultSets=True;TrustServerCertificate=True;Connection Timeout=30;" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Param( | ||
[switch]$skipDeploy = $false | ||
) | ||
|
||
Write-Host "π’ Starting Docker Compose" -ForegroundColor Green | ||
docker compose up -d | ||
|
||
if (-not $skipDeploy) { | ||
$upScriptPath = $Script:MyInvocation.MyCommand.Path | Split-Path | ||
|
||
Write-Host "π Creating and Seeding Database" -ForegroundColor Green | ||
Set-Location ./tools/Database/ | ||
dotnet run | ||
|
||
Set-Location $upScriptPath | ||
} |