chore: adds PostgreSQL
This commit is contained in:
23
scripts/start-infrastructure.sh
Executable file
23
scripts/start-infrastructure.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set global configuration
|
||||
DATA_ROOT="/var/trakqr"
|
||||
POSTGRES_VERSION="latest"
|
||||
MONGODB_VERSION="latest"
|
||||
|
||||
# Start PostgreSQL
|
||||
if [ "$(docker ps -a -q -f name=^TRAKQR_POSTGRES$)" ]; then
|
||||
echo "PostgreSQL container exists. Starting..."
|
||||
docker start TRAKQR_POSTGRES
|
||||
else
|
||||
echo "PostgreSQL container does not exist. Creating..."
|
||||
docker run -d \
|
||||
--name TRAKQR_POSTGRES \
|
||||
-v "${DATA_ROOT}/postgres:/var/lib/postgresql/data" \
|
||||
-p 5400:5432 \
|
||||
-e POSTGRES_USER=sa \
|
||||
-e POSTGRES_PASSWORD=P@ssword123! \
|
||||
-e POSTGRES_DB=trakqr \
|
||||
postgres:$POSTGRES_VERSION
|
||||
fi
|
||||
|
||||
17
src/api/Data/AppDbContext.cs
Normal file
17
src/api/Data/AppDbContext.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Api.Data;
|
||||
|
||||
public class AppDbContext : DbContext
|
||||
{
|
||||
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Entity configurations will be added here as entities are created
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
using Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddDbContext<AppDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("PostgresConnection")));
|
||||
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
@@ -10,7 +16,7 @@ var app = builder.Build();
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi().CacheOutput();
|
||||
|
||||
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.SwaggerEndpoint("/openapi/v1.json", "v1");
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="10.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"PostgresConnection": "Host=localhost;Port=5400;Database=trakqr;Username=sa;Password=P@ssword123!"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,8 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"PostgresConnection": ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user