added migrations to ensure db creation etc.

This commit is contained in:
aroffman
2026-05-14 02:11:01 +02:00
parent 233da7e7ea
commit f0fdc93316
6 changed files with 136 additions and 5 deletions
+3 -3
View File
@@ -4,10 +4,10 @@ EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src WORKDIR /src
COPY *.csproj ./ COPY demo001.csproj ./
RUN dotnet restore RUN dotnet restore demo001.csproj
COPY . . COPY . .
RUN dotnet publish -c Release -o /app/publish RUN dotnet publish demo001.csproj -c Release -o /app/publish
FROM base AS final FROM base AS final
WORKDIR /app WORKDIR /app
+41
View File
@@ -0,0 +1,41 @@
using Demo001.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo001.Migrations
{
[DbContext(typeof(AppDbContext))]
partial class AppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "8.0.0");
modelBuilder.Entity("Demo001.Models.TodoItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsComplete")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("TodoItems");
});
}
}
}
+44
View File
@@ -0,0 +1,44 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo001.Migrations
{
[DbContext(typeof(Demo001.Data.AppDbContext))]
[Migration("20260514000000_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "8.0.0");
modelBuilder.Entity("Demo001.Models.TodoItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<bool>("IsComplete")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("TodoItems");
});
}
}
}
+34
View File
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Demo001.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "TodoItems",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: true),
IsComplete = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TodoItems", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TodoItems");
}
}
}
Executable
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
docker compose down
docker compose build --no-cache api
docker compose up
+8 -2
View File
@@ -11,6 +11,11 @@ services:
- "5432:5432" - "5432:5432"
volumes: volumes:
- pgdata:/var/lib/postgresql/data - pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U demo"]
interval: 10s
timeout: 5s
retries: 5
api: api:
build: build:
@@ -19,9 +24,10 @@ services:
environment: environment:
ConnectionStrings__DefaultConnection: "Host=db;Port=5432;Database=demo;Username=demo;Password=demo" ConnectionStrings__DefaultConnection: "Host=db;Port=5432;Database=demo;Username=demo;Password=demo"
ports: ports:
- "5000:80" - "5000:8080"
depends_on: depends_on:
- db db:
condition: service_healthy
volumes: volumes:
pgdata: pgdata: