fix(03): revise plans based on checker feedback

This commit is contained in:
2026-03-24 09:04:19 +01:00
parent e8e0731adc
commit b6b7ca44dc
2 changed files with 38 additions and 37 deletions

View File

@@ -21,6 +21,7 @@ must_haves:
- "Docker Compose with --profile postgres activates a PostgreSQL service"
- "Default docker compose (no profile) remains SQLite-only"
- "Duplicate tag creation returns 409 on both SQLite and PostgreSQL"
- "Existing SQLite users can upgrade to this version with zero configuration changes and no data loss"
artifacts:
- path: "cmd/diunwebhook/main.go"
provides: "DATABASE_URL branching logic"
@@ -55,7 +56,7 @@ must_haves:
<objective>
Wire PostgresStore into the application and deployment infrastructure.
Purpose: Connects the PostgresStore (built in Plan 01) to the startup path, adds Docker Compose profiles for PostgreSQL deployments, creates build-tagged integration test helpers, and fixes the UNIQUE constraint detection to work across both database backends.
Purpose: Connects the PostgresStore (built in Plan 01) to the startup path, adds Docker Compose profiles for PostgreSQL deployments, creates build-tagged integration test helpers, and fixes the UNIQUE constraint detection to work across both database backends. Also updates all call sites that still reference the old `RunMigrations` name (renamed to `RunSQLiteMigrations` in Plan 01).
Output: Updated main.go with DATABASE_URL branching, compose files with postgres profiles, build-tagged test helper, cross-dialect error handling fix.
</objective>
@@ -106,18 +107,19 @@ func NewServer(store Store, webhookSecret string) *Server
<tasks>
<task type="auto">
<name>Task 1: Wire DATABASE_URL branching in main.go and fix cross-dialect UNIQUE detection</name>
<name>Task 1: Wire DATABASE_URL branching in main.go, update call sites, and fix cross-dialect UNIQUE detection</name>
<read_first>
- cmd/diunwebhook/main.go (current SQLite-only startup to add branching)
- pkg/diunwebhook/diunwebhook.go (TagsHandler line 172 - UNIQUE detection to fix)
- cmd/diunwebhook/main.go (current SQLite-only startup to rewrite with branching)
- pkg/diunwebhook/diunwebhook.go (TagsHandler - UNIQUE detection to fix)
- pkg/diunwebhook/export_test.go (calls RunMigrations - must rename to RunSQLiteMigrations)
- pkg/diunwebhook/postgres_store.go (verify NewPostgresStore exists from Plan 01)
- pkg/diunwebhook/migrate.go (verify RunSQLiteMigrations and RunPostgresMigrations exist from Plan 01)
</read_first>
<files>cmd/diunwebhook/main.go, pkg/diunwebhook/diunwebhook.go</files>
<files>cmd/diunwebhook/main.go, pkg/diunwebhook/diunwebhook.go, pkg/diunwebhook/export_test.go</files>
<action>
**1. Update `cmd/diunwebhook/main.go`** to branch on `DATABASE_URL` per D-07, D-08, D-09.
**1. Rewrite `cmd/diunwebhook/main.go`** with DATABASE_URL branching per D-07, D-08, D-09.
Replace the current database setup block (lines 18-33) with DATABASE_URL branching. The full main function should:
Replace the current database setup block with DATABASE_URL branching. The full main function should:
```go
package main
@@ -174,13 +176,17 @@ func main() {
Key changes:
- Add blank import `_ "github.com/jackc/pgx/v5/stdlib"` to register "pgx" driver name
- `DATABASE_URL` present -> `sql.Open("pgx", databaseURL)` -> `RunPostgresMigrations` -> `NewPostgresStore`
- `DATABASE_URL` absent -> existing SQLite path with `RunSQLiteMigrations` (renamed in Plan 01)
- `DATABASE_URL` absent -> existing SQLite path with `RunSQLiteMigrations` (renamed from `RunMigrations` in Plan 01)
- Log `"Using PostgreSQL database"` or `"Using SQLite database at %s"` per D-09
- Keep all existing code after the store setup unchanged (secret, server, mux, httpSrv, shutdown)
**2. Fix cross-dialect UNIQUE constraint detection in `pkg/diunwebhook/diunwebhook.go`.**
**2. Update `pkg/diunwebhook/export_test.go`** to use the renamed function.
In the `TagsHandler` method, line 172, change:
Change all occurrences of `RunMigrations(db)` to `RunSQLiteMigrations(db)` in export_test.go. This completes the rename that Plan 01 started in migrate.go.
**3. Fix cross-dialect UNIQUE constraint detection in `pkg/diunwebhook/diunwebhook.go`.**
In the `TagsHandler` method, change:
```go
if strings.Contains(err.Error(), "UNIQUE") {
```
@@ -203,12 +209,13 @@ Why: SQLite errors contain uppercase "UNIQUE" (e.g., `UNIQUE constraint failed:
- cmd/diunwebhook/main.go contains `log.Printf("Using SQLite database at %s", dbPath)`
- cmd/diunwebhook/main.go contains `_ "github.com/jackc/pgx/v5/stdlib"`
- cmd/diunwebhook/main.go contains `diun.RunSQLiteMigrations(db)` (not RunMigrations)
- pkg/diunwebhook/export_test.go contains `RunSQLiteMigrations` (not RunMigrations)
- pkg/diunwebhook/diunwebhook.go contains `strings.Contains(strings.ToLower(err.Error()), "unique")`
- pkg/diunwebhook/diunwebhook.go does NOT contain `strings.Contains(err.Error(), "UNIQUE")` (old pattern removed)
- `go build ./...` exits 0
- `go test -count=1 ./pkg/diunwebhook/` exits 0
- `go test -v -count=1 ./pkg/diunwebhook/` exits 0 (full test suite passes)
</acceptance_criteria>
<done>main.go branches on DATABASE_URL to select PostgreSQL or SQLite. pgx/v5/stdlib is blank-imported to register the driver. Startup log identifies the active backend. UNIQUE detection is case-insensitive for cross-dialect compatibility. All existing tests pass.</done>
<done>main.go branches on DATABASE_URL to select PostgreSQL or SQLite. pgx/v5/stdlib is blank-imported to register the driver. Startup log identifies the active backend. export_test.go updated with RunSQLiteMigrations. UNIQUE detection is case-insensitive for cross-dialect compatibility. All existing tests pass.</done>
</task>
<task type="auto">
@@ -349,7 +356,7 @@ func NewTestPostgresServer() (*Server, error) {
This file is in the `diunwebhook` package (internal, same as export_test.go pattern). The `//go:build postgres` tag ensures it only compiles when explicitly requested with `go test -tags postgres`. Without the tag, `go test ./pkg/diunwebhook/` skips this file entirely -- no pgx import, no PostgreSQL dependency.
</action>
<verify>
<automated>cd /home/jean-luc-makiola/Development/projects/DiunDashboard && go build ./... && docker compose config --quiet 2>&1; echo "exit: $?"</automated>
<automated>cd /home/jean-luc-makiola/Development/projects/DiunDashboard && go build ./... && go test -v -count=1 ./pkg/diunwebhook/ 2>&1 | tail -5</automated>
</verify>
<acceptance_criteria>
- compose.yml contains `profiles:` under the postgres service
@@ -371,7 +378,7 @@ This file is in the `diunwebhook` package (internal, same as export_test.go patt
- pkg/diunwebhook/postgres_test.go contains `NewPostgresStore(db)`
- pkg/diunwebhook/postgres_test.go contains `TEST_DATABASE_URL`
- `go build ./...` exits 0 (postgres_test.go is not compiled without build tag)
- `go test -count=1 ./pkg/diunwebhook/` exits 0 (SQLite tests still pass, postgres_test.go skipped)
- `go test -v -count=1 ./pkg/diunwebhook/` exits 0 (full SQLite test suite passes, postgres_test.go skipped)
</acceptance_criteria>
<done>Docker Compose files support optional PostgreSQL via profiles. Default deploy remains SQLite-only. Build-tagged test helper exists for PostgreSQL integration testing. Dockerfile needs no changes (pgx/v5 is pure Go).</done>
</task>