Add PostgreSQL integration with EF Core + Notes demo page
This commit is contained in:
47
README.md
Normal file
47
README.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Freman.Sample.Web – Blazor + PostgreSQL (Docker) sample
|
||||
|
||||
This repo is a small demo for C# developers (e.g., Unity folks) who are new to web dev.
|
||||
|
||||
## Prereqs
|
||||
|
||||
- Docker Desktop
|
||||
- .NET SDK (matching the repo)
|
||||
- (Optional) EF tooling: `dotnet-ef`
|
||||
|
||||
## Quickstart (recommended)
|
||||
|
||||
1) Create a `.env` file next to `compose.yaml`:
|
||||
```text POSTGRES_PASSWORD=your_local_dev_password```
|
||||
|
||||
2) Start everything:
|
||||
```powershell docker compose up --build```
|
||||
|
||||
3) Open the app, then navigate to **Notes (Postgres)**.
|
||||
Type a note, click **Save**, refresh the page — it should persist.
|
||||
|
||||
## Running from Rider (server on host, DB in Docker)
|
||||
|
||||
Start just Postgres:
|
||||
|
||||
```powershell docker compose up postgres```
|
||||
|
||||
Then run the `Freman.Sample.Web` project from Rider.
|
||||
|
||||
> In this mode, the app uses `appsettings.Development.json` which points to `localhost:5432`.
|
||||
|
||||
## Migrations (EF Core)
|
||||
|
||||
Install EF CLI once:
|
||||
```powershell dotnet tool install --global dotnet-ef```
|
||||
|
||||
Add a migration:
|
||||
|
||||
```powershell dotnet ef migrations add InitialCreate --project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj --startup-project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj ` --output-dir Data\Migrations```
|
||||
|
||||
Apply it:
|
||||
```powershell dotnet ef database update --project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj --startup-project .\Freman.Sample.Web\Freman.Sample.Web\Freman.Sample.Web.csproj```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- **DB auth failed**: check `.env` password matches the connection string in `compose.yaml`.
|
||||
- **Port 5432 already in use**: stop the other Postgres instance or change the port mapping in `compose.yaml`.
|
||||
Reference in New Issue
Block a user