mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
34 lines
868 B
C#
34 lines
868 B
C#
using DBSeed;
|
|
using Microsoft.Data.SqlClient;
|
|
|
|
try
|
|
{
|
|
var connectionString = Environment.GetEnvironmentVariable(
|
|
"DB_CONNECTION_STRING"
|
|
);
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
throw new InvalidOperationException(
|
|
"Environment variable DB_CONNECTION_STRING is not set or is empty."
|
|
);
|
|
|
|
await using var connection = new SqlConnection(connectionString);
|
|
await connection.OpenAsync();
|
|
|
|
Console.WriteLine("Connected to database.");
|
|
|
|
await LocationSeeder.SeedAsync(connection);
|
|
Console.WriteLine("Seeded locations.");
|
|
|
|
await UserSeeder.SeedAsync(connection);
|
|
Console.WriteLine("Seeded users.");
|
|
|
|
Console.WriteLine("Seed completed successfully.");
|
|
return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.Error.WriteLine("Seed failed:");
|
|
Console.Error.WriteLine(ex);
|
|
return 1;
|
|
}
|