chore: adds PostgreSQL

This commit is contained in:
2026-01-27 14:23:58 -05:00
parent 40ea3f45fd
commit 33c6dadb78
6 changed files with 59 additions and 2 deletions

23
scripts/start-infrastructure.sh Executable file
View 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

View 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
}
}

View File

@@ -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();

View File

@@ -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>

View File

@@ -4,5 +4,8 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"PostgresConnection": "Host=localhost;Port=5400;Database=trakqr;Username=sa;Password=P@ssword123!"
}
}

View File

@@ -5,5 +5,8 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ConnectionStrings": {
"PostgresConnection": ""
}
}