mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
update seed application
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Text;
|
|||||||
using Konscious.Security.Cryptography;
|
using Konscious.Security.Cryptography;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
|
||||||
|
|
||||||
string ConnectionString = Environment.GetEnvironmentVariable(
|
string ConnectionString = Environment.GetEnvironmentVariable(
|
||||||
"DB_CONNECTION_STRING"
|
"DB_CONNECTION_STRING"
|
||||||
)!;
|
)!;
|
||||||
@@ -17,14 +18,15 @@ static async Task BuildSchema(SqlConnection connection)
|
|||||||
|
|
||||||
static async Task AddStoredProcsAndFunctions(SqlConnection connection)
|
static async Task AddStoredProcsAndFunctions(SqlConnection connection)
|
||||||
{
|
{
|
||||||
// New approach: load functions first, then procedures, from dedicated folders.
|
|
||||||
// Fallback to legacy combined file if folders are missing.
|
|
||||||
string projectRoot = Path.GetFullPath(
|
string projectRoot = Path.GetFullPath(
|
||||||
Path.Combine(AppContext.BaseDirectory, "..", "..", "..")
|
Path.Combine(AppContext.BaseDirectory, "..", "..", "..")
|
||||||
);
|
);
|
||||||
|
|
||||||
string functionsDir = Path.Combine(projectRoot, "seed", "functions");
|
string functionsDir = Path.Combine(projectRoot, "seed", "functions");
|
||||||
string proceduresDir = Path.Combine(projectRoot, "seed", "procedures");
|
string proceduresDir = Path.Combine(projectRoot, "seed", "procedures");
|
||||||
|
string crudDir = Path.GetFullPath(
|
||||||
|
Path.Combine(projectRoot, "..", "DataAccessLayer", "Sql", "crud")
|
||||||
|
);
|
||||||
|
|
||||||
if (Directory.Exists(functionsDir))
|
if (Directory.Exists(functionsDir))
|
||||||
{
|
{
|
||||||
@@ -66,6 +68,26 @@ static async Task AddStoredProcsAndFunctions(SqlConnection connection)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Directory.Exists(crudDir))
|
||||||
|
{
|
||||||
|
foreach (
|
||||||
|
string file in Directory
|
||||||
|
.EnumerateFiles(
|
||||||
|
crudDir,
|
||||||
|
"*.sql",
|
||||||
|
SearchOption.TopDirectoryOnly
|
||||||
|
)
|
||||||
|
.OrderBy(f => f, StringComparer.OrdinalIgnoreCase)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
string sql = await File.ReadAllTextAsync(file);
|
||||||
|
await ExecuteScriptAsync(connection, sql);
|
||||||
|
Console.WriteLine(
|
||||||
|
$"Executed CRUD script: {Path.GetFileName(file)}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
"Functions and stored procedures added or updated successfully."
|
"Functions and stored procedures added or updated successfully."
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,37 +1,5 @@
|
|||||||
// Load a local .env file into environment variables when present (useful for local development)
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var envPath = Path.Combine(Directory.GetCurrentDirectory(), ".env");
|
|
||||||
if (File.Exists(envPath))
|
|
||||||
{
|
|
||||||
foreach (var line in File.ReadAllLines(envPath))
|
|
||||||
{
|
|
||||||
var trimmed = line.Trim();
|
|
||||||
if (string.IsNullOrEmpty(trimmed) || trimmed.StartsWith("#"))
|
|
||||||
continue;
|
|
||||||
var idx = trimmed.IndexOf('=');
|
|
||||||
if (idx <= 0)
|
|
||||||
continue;
|
|
||||||
var key = trimmed.Substring(0, idx).Trim();
|
|
||||||
var val = trimmed.Substring(idx + 1).Trim();
|
|
||||||
if (val.Length >= 2 && ((val.StartsWith("\"") && val.EndsWith("\"")) || (val.StartsWith("'") && val.EndsWith("'"))))
|
|
||||||
{
|
|
||||||
val = val.Substring(1, val.Length - 2);
|
|
||||||
}
|
|
||||||
if (Environment.GetEnvironmentVariable(key) == null)
|
|
||||||
Environment.SetEnvironmentVariable(key, val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// If dotenv loading fails, continue without blocking startup.
|
|
||||||
}
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
|
||||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
@@ -39,7 +7,6 @@ builder.Services.AddOpenApi();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
@@ -48,21 +15,6 @@ if (app.Environment.IsDevelopment())
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
var summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing",
|
|
||||||
"Bracing",
|
|
||||||
"Chilly",
|
|
||||||
"Cool",
|
|
||||||
"Mild",
|
|
||||||
"Warm",
|
|
||||||
"Balmy",
|
|
||||||
"Hot",
|
|
||||||
"Sweltering",
|
|
||||||
"Scorching",
|
|
||||||
};
|
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
ACCEPT_EULA: "Y"
|
ACCEPT_EULA: "Y"
|
||||||
SA_PASSWORD: "${SA_PASSWORD}"
|
SA_PASSWORD: "${SA_PASSWORD}"
|
||||||
|
ports:
|
||||||
|
- "1433:1433"
|
||||||
volumes:
|
volumes:
|
||||||
- sqlserverdata:/var/opt/mssql
|
- sqlserverdata:/var/opt/mssql
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: [ "CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "${SA_PASSWORD}", "-Q", "SELECT 1" ]
|
test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "${SA_PASSWORD}", "-Q", "SELECT 1" ]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 12
|
retries: 12
|
||||||
networks:
|
networks:
|
||||||
- devnet
|
- devnet
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
sqlserverdata:
|
sqlserverdata:
|
||||||
nuget-cache:
|
nuget-cache:
|
||||||
|
|||||||
Reference in New Issue
Block a user