Conversation
There was a problem hiding this comment.
Code Review
This pull request establishes the foundational structure for the Kelompok project, including a Go-based CLI and HTTP API, a custom database migration system, and an initial PostgreSQL schema. Feedback suggests several technical improvements: parameterizing database connection pool settings, enhancing HTTP server resilience with additional timeouts, implementing locking mechanisms for the migration runner to prevent concurrent execution issues, and addressing potential permission constraints when creating database extensions. Additionally, improvements to error handling in the CLI and environment configuration loader were recommended.
| config.MaxConns = 5 | ||
| config.MinConns = 0 | ||
| config.MaxConnLifetime = 30 * time.Minute | ||
| config.MaxConnIdleTime = 5 * time.Minute | ||
| config.HealthCheckPeriod = time.Minute |
| return &http.Server{ | ||
| Addr: s.config.APIAddr, | ||
| Handler: s.Handler(), | ||
| ReadHeaderTimeout: 5 * time.Second, | ||
| } |
There was a problem hiding this comment.
The HTTP server is configured with only ReadHeaderTimeout. To improve resilience against resource exhaustion and certain Denial of Service (DoS) attacks like Slowloris, it is recommended to also set ReadTimeout, WriteTimeout, and IdleTimeout.
| return &http.Server{ | |
| Addr: s.config.APIAddr, | |
| Handler: s.Handler(), | |
| ReadHeaderTimeout: 5 * time.Second, | |
| } | |
| return &http.Server{ | |
| Addr: s.config.APIAddr, | |
| Handler: s.Handler(), | |
| ReadHeaderTimeout: 5 * time.Second, | |
| ReadTimeout: 15 * time.Second, | |
| WriteTimeout: 15 * time.Second, | |
| IdleTimeout: 60 * time.Second, | |
| } |
| return err | ||
| } | ||
|
|
||
| for _, migration := range migrations { |
There was a problem hiding this comment.
The migration runner lacks a concurrency control mechanism (e.g., a distributed lock or a PostgreSQL advisory lock). If multiple instances of the application attempt to run migrations simultaneously during a deployment, they may conflict or attempt to apply the same migration twice. Consider wrapping the migration logic in a lock to ensure atomicity across multiple processes.
| @@ -0,0 +1,242 @@ | |||
| CREATE EXTENSION IF NOT EXISTS pgcrypto; | |||
There was a problem hiding this comment.
Creating extensions like pgcrypto typically requires superuser privileges. In many managed database environments (e.g., AWS RDS, Supabase), the application user may not have these permissions, causing the migration to fail. It is often safer to assume required extensions are pre-installed or to document this requirement clearly for deployment.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa181275e7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f451ab527c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| defer pool.Close() | ||
|
|
||
| if err := database.Migrate(ctx, pool, "migrations"); err != nil { |
There was a problem hiding this comment.
Resolve migration directory independent of current working dir
Hard-coding "migrations" here makes kelompok migrate depend on the process working directory, so the command fails with read migrations dir: ... no such file or directory when the binary is run outside the repo root (for example from an installed path or CI job with a different cwd). Because this is the default CLI migration path, it breaks a common execution context even when DB config is otherwise correct; resolve migrations from a configurable absolute path or from embedded assets instead of a relative literal.
Useful? React with 👍 / 👎.
Summary
.envsupport, pgxpool database helpers, and a SQL migration runner.Notes
.env.examplecontains placeholder credentials only. Real database credentials remain local secrets.Validation
make testgo test ./...go run ./cmd/kelompok helpgit diff --checkRefs #2