diff --git a/README.md b/README.md index 0b6a441..fa8fc3d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Lean Go API backend for ISeeU Tracker. - [x] Entry point created (`cmd/api/main.go`) - [x] Env config package created (`internal/config/config.go`) - [x] `.env` loading added with required DB variables +- [x] DB URL builder added in config (`DatabaseURL`) with schema `search_path` +- [x] DB package scaffold created (`internal/db/`) - [x] Local Postgres service available in `compose.yaml` (dev profile) - [ ] Database connection package (`internal/db`) not implemented yet - [ ] Goose migrations folder/files not created yet @@ -41,12 +43,13 @@ scripts/ # optional local/dev scripts - [x] Create `cmd/api/main.go` - [x] Create `internal/config` package - [x] Load `.env` and validate required DB env vars +- [x] Add DB URL builder method in config - [ ] Add `APP_PORT` env var with default fallback - [ ] Improve startup logs (without printing secrets) ### Chapter 2 - Database and Goose -- [ ] Add `internal/db/postgres.go` with `sqlx` connection +- [ ] Implement `internal/db/postgres.go` with `sqlx` connection (`pgx` driver) - [ ] Add `internal/db/migrate.go` to run Goose at startup - [ ] Create `migrations/` directory - [ ] Create first migration for `users` table @@ -100,3 +103,5 @@ scripts/ # optional local/dev scripts - Use `sqlx` for explicit SQL and scan helpers. - Use `goose` for schema versioning and run migrations automatically at startup. - Never store plain passwords; always use `password_hash`. +- Keep one shared `*sqlx.DB` pool for the app lifetime; do not open DB per request. +- Pass `context.Context` from handler (`r.Context()`) to service/repository methods. diff --git a/internal/config/config.go b/internal/config/config.go index fe6d8d7..ad985f4 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,7 +1,6 @@ package config import ( - "fmt" "log" "net" "net/url" diff --git a/internal/db/db.go b/internal/db/db.go index e69de29..3a49c63 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -0,0 +1 @@ +package db diff --git a/internal/db/postgres.go b/internal/db/postgres.go new file mode 100644 index 0000000..3a49c63 --- /dev/null +++ b/internal/db/postgres.go @@ -0,0 +1 @@ +package db