mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
Fix seed pipeline crash and make seeding failures fail CI (#309)
This commit is contained in:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -33,7 +33,7 @@ jobs:
|
|||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
status=0
|
status=0
|
||||||
for name in test-env-api-specs test-env-unit-tests test-env-frontend-tests; do
|
for name in test-env-database-migrations test-env-database-seed test-env-api-specs test-env-unit-tests test-env-frontend-tests; do
|
||||||
code="$(docker inspect -f '{{.State.ExitCode}}' "$name" 2>/dev/null || echo 1)"
|
code="$(docker inspect -f '{{.State.ExitCode}}' "$name" 2>/dev/null || echo 1)"
|
||||||
echo "$name exited with $code"
|
echo "$name exited with $code"
|
||||||
if [ "$code" != "0" ]; then
|
if [ "$code" != "0" ]; then
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Database.Seed;
|
|||||||
|
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
private static IMediator CreateMediator()
|
private static ServiceProvider BuildServiceProvider()
|
||||||
{
|
{
|
||||||
IConfiguration configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build();
|
IConfiguration configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build();
|
||||||
|
|
||||||
@@ -38,11 +38,10 @@ internal class Program
|
|||||||
.RegisterServicesFromAssemblyContaining<UploadPhotoCommand>()
|
.RegisterServicesFromAssemblyContaining<UploadPhotoCommand>()
|
||||||
);
|
);
|
||||||
|
|
||||||
using ServiceProvider provider = services.BuildServiceProvider();
|
return services.BuildServiceProvider();
|
||||||
return provider.GetRequiredService<IMediator>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Main()
|
public static async Task<int> Main()
|
||||||
{
|
{
|
||||||
using CancellationTokenSource cts = new();
|
using CancellationTokenSource cts = new();
|
||||||
Console.CancelKeyPress += (_, e) =>
|
Console.CancelKeyPress += (_, e) =>
|
||||||
@@ -54,20 +53,24 @@ internal class Program
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IMediator mediator = CreateMediator();
|
await using ServiceProvider provider = BuildServiceProvider();
|
||||||
|
IMediator mediator = provider.GetRequiredService<IMediator>();
|
||||||
SeedRepository reader = new SeedRepository(
|
SeedRepository reader = new SeedRepository(
|
||||||
connectionString: "Data Source=SeedData/biergarten_seed_2026-08-25T20-45-50.697244Z.sqlite"
|
connectionString: "Data Source=SeedData/biergarten_seed_2026-08-25T20-45-50.697244Z.sqlite"
|
||||||
);
|
);
|
||||||
await new BiergartenDataSeeder(mediator, reader).Run(cts.Token);
|
await new BiergartenDataSeeder(mediator, reader).Run(cts.Token);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine("[yellow]Seeding cancelled.[/]");
|
AnsiConsole.MarkupLine("[yellow]Seeding cancelled.[/]");
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine("[red]Seeding failed.[/]");
|
AnsiConsole.MarkupLine("[red]Seeding failed.[/]");
|
||||||
AnsiConsole.WriteException(ex);
|
AnsiConsole.WriteException(ex);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,13 +58,13 @@ public sealed class SeedRepository : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sealed record BreweryRow(
|
private sealed record BreweryRow(
|
||||||
int Id,
|
long Id,
|
||||||
string NameEn,
|
string NameEn,
|
||||||
string DescriptionEn,
|
string DescriptionEn,
|
||||||
string NameLocal,
|
string NameLocal,
|
||||||
string DescriptionLocal,
|
string DescriptionLocal,
|
||||||
int AddressId,
|
long AddressId,
|
||||||
int CityId,
|
long CityId,
|
||||||
double Longitude,
|
double Longitude,
|
||||||
double Latitude,
|
double Latitude,
|
||||||
string AddressLine1,
|
string AddressLine1,
|
||||||
@@ -101,27 +101,27 @@ public sealed class SeedRepository : IDisposable
|
|||||||
|
|
||||||
return [.. rows.Select(row => new BreweryResult
|
return [.. rows.Select(row => new BreweryResult
|
||||||
{
|
{
|
||||||
Id = row.Id,
|
Id = (int)row.Id,
|
||||||
NameEn = row.NameEn,
|
NameEn = row.NameEn,
|
||||||
DescriptionEn = row.DescriptionEn,
|
DescriptionEn = row.DescriptionEn,
|
||||||
NameLocal = row.NameLocal,
|
NameLocal = row.NameLocal,
|
||||||
DescriptionLocal = row.DescriptionLocal,
|
DescriptionLocal = row.DescriptionLocal,
|
||||||
Address = new BreweryAddress
|
Address = new BreweryAddress
|
||||||
{
|
{
|
||||||
Id = row.AddressId,
|
Id = (int)row.AddressId,
|
||||||
CityId = row.CityId,
|
CityId = (int)row.CityId,
|
||||||
BreweryId = row.Id,
|
BreweryId = (int)row.Id,
|
||||||
Longitude = row.Longitude,
|
Longitude = row.Longitude,
|
||||||
Latitude = row.Latitude,
|
Latitude = row.Latitude,
|
||||||
AddressLine1 = row.AddressLine1,
|
AddressLine1 = row.AddressLine1,
|
||||||
PostalCode = row.PostalCode,
|
PostalCode = row.PostalCode,
|
||||||
City = cities[row.CityId],
|
City = cities[(int)row.CityId],
|
||||||
},
|
},
|
||||||
})];
|
})];
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed record UserRow(
|
private sealed record UserRow(
|
||||||
int Id,
|
long Id,
|
||||||
string FirstName,
|
string FirstName,
|
||||||
string LastName,
|
string LastName,
|
||||||
string Gender,
|
string Gender,
|
||||||
@@ -130,8 +130,8 @@ public sealed class SeedRepository : IDisposable
|
|||||||
double ActivityWeight,
|
double ActivityWeight,
|
||||||
string Email,
|
string Email,
|
||||||
string DateOfBirth,
|
string DateOfBirth,
|
||||||
int AddressId,
|
long AddressId,
|
||||||
int CityId,
|
long CityId,
|
||||||
double Longitude,
|
double Longitude,
|
||||||
double Latitude
|
double Latitude
|
||||||
);
|
);
|
||||||
@@ -172,16 +172,16 @@ public sealed class SeedRepository : IDisposable
|
|||||||
DateOfBirth = row.DateOfBirth,
|
DateOfBirth = row.DateOfBirth,
|
||||||
Address = new UserAddress
|
Address = new UserAddress
|
||||||
{
|
{
|
||||||
Id = row.AddressId,
|
Id = (int)row.AddressId,
|
||||||
CityId = row.CityId,
|
CityId = (int)row.CityId,
|
||||||
UserId = row.Id,
|
UserId = (int)row.Id,
|
||||||
Longitude = row.Longitude,
|
Longitude = row.Longitude,
|
||||||
Latitude = row.Latitude,
|
Latitude = row.Latitude,
|
||||||
City = cities[row.CityId],
|
City = cities[(int)row.CityId],
|
||||||
},
|
},
|
||||||
User = new UserResult
|
User = new UserResult
|
||||||
{
|
{
|
||||||
Id = row.Id,
|
Id = (int)row.Id,
|
||||||
FirstName = row.FirstName,
|
FirstName = row.FirstName,
|
||||||
LastName = row.LastName,
|
LastName = row.LastName,
|
||||||
Gender = row.Gender,
|
Gender = row.Gender,
|
||||||
@@ -193,7 +193,7 @@ public sealed class SeedRepository : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sealed record CityRow(
|
private sealed record CityRow(
|
||||||
int Id,
|
long Id,
|
||||||
string CityName,
|
string CityName,
|
||||||
string StateProvince,
|
string StateProvince,
|
||||||
string Iso31662,
|
string Iso31662,
|
||||||
@@ -231,10 +231,10 @@ public sealed class SeedRepository : IDisposable
|
|||||||
IEnumerable<CityRow> rows = await connection.QueryAsync<CityRow>(command);
|
IEnumerable<CityRow> rows = await connection.QueryAsync<CityRow>(command);
|
||||||
|
|
||||||
return rows.ToDictionary(
|
return rows.ToDictionary(
|
||||||
row => row.Id,
|
row => (int)row.Id,
|
||||||
row => new City
|
row => new City
|
||||||
{
|
{
|
||||||
Id = row.Id,
|
Id = (int)row.Id,
|
||||||
CityName = row.CityName,
|
CityName = row.CityName,
|
||||||
StateProvinceName = row.StateProvince,
|
StateProvinceName = row.StateProvince,
|
||||||
ISO_3166_2 = row.Iso31662,
|
ISO_3166_2 = row.Iso31662,
|
||||||
|
|||||||
Reference in New Issue
Block a user