Skip to content

Scaffold Go API and database foundation#9

Merged
wauputr4 merged 4 commits intomainfrom
codex/db-foundation
May 10, 2026
Merged

Scaffold Go API and database foundation#9
wauputr4 merged 4 commits intomainfrom
codex/db-foundation

Conversation

@wauputr4
Copy link
Copy Markdown
Contributor

Summary

  • Add the initial Go module, API entrypoint, CLI entrypoint, and lightweight Makefile shortcuts.
  • Add PostgreSQL configuration loading, .env support, pgxpool database helpers, and a SQL migration runner.
  • Add the first CRM-oriented migration for organizations, source records, claims, members, posts, impact reports, events, donor reporting, files, and audit logs.
  • Add health/readiness endpoints and development documentation.

Notes

  • .env.example contains placeholder credentials only. Real database credentials remain local secrets.
  • The live development database migration was already run once successfully from the local machine.

Validation

  • make test
  • go test ./...
  • go run ./cmd/kelompok help
  • git diff --check

Refs #2

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/database/database.go Outdated
Comment on lines +21 to +25
config.MaxConns = 5
config.MinConns = 0
config.MaxConnLifetime = 30 * time.Minute
config.MaxConnIdleTime = 5 * time.Minute
config.HealthCheckPeriod = time.Minute
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The database connection pool settings are hardcoded. While these values are reasonable for a starting point, they should be made configurable via environment variables to allow for proper tuning in different environments (e.g., production vs. development).

Comment on lines +35 to +39
return &http.Server{
Addr: s.config.APIAddr,
Handler: s.Handler(),
ReadHeaderTimeout: 5 * time.Second,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread migrations/000001_init.sql Outdated
@@ -0,0 +1,242 @@
CREATE EXTENSION IF NOT EXISTS pgcrypto;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread internal/cli/cli.go Outdated
Comment thread internal/config/dotenv.go Outdated
@wauputr4
Copy link
Copy Markdown
Contributor Author

@codex review

@wauputr4 wauputr4 marked this pull request as ready for review May 10, 2026 02:26
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread .env.example Outdated
Comment thread internal/database/migrate.go Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread internal/cli/cli.go Outdated
}
defer pool.Close()

if err := database.Migrate(ctx, pool, "migrations"); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@wauputr4 wauputr4 merged commit bffd9c3 into main May 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant