Skip to content

feat(db): add Atlas declarative schema, Postgres 18, and sqlc queries#157

Open
yiningsoong wants to merge 7 commits into
mainfrom
feat/135-decide-on-tooling-stack-pgx-sqlc-migration-tool
Open

feat(db): add Atlas declarative schema, Postgres 18, and sqlc queries#157
yiningsoong wants to merge 7 commits into
mainfrom
feat/135-decide-on-tooling-stack-pgx-sqlc-migration-tool

Conversation

@yiningsoong
Copy link
Copy Markdown
Contributor

@yiningsoong yiningsoong commented May 5, 2026

🚀 Summary

Set up the database tooling stack: Atlas for declarative schema migrations, sqlc for type-safe query generation, and Postgres 18 for local development.
Contributors run make tools to install everything and make migrate to apply migrations.

✏️ Changes

  • Added server/schema.hcl as the declarative schema source of truth (Atlas HCL)
  • Added initial migration and seed data (apps: SDT, PG)
  • Added sqlc config and generated query code for ListApps and GetAppByCode
  • Upgraded Docker Postgres from 17 to 18
  • Added TW_DATABASE_SSL_MODE env var for Atlas (lib/pq requires explicit sslmode)
  • Added Makefile targets: migrate-diff, migrate, db-reset
  • Pinned Atlas v1.1.0 in make tools (official binary install)
  • Deferred pgx pool initialization (no queries in handlers yet)
  • Updated CONTRIBUTING.md with database workflow documentation

🧪 Test Plan

  • make tools installs Atlas v1.1.0 and golangci-lint
  • docker compose up -d starts Postgres 18 container
  • make db-reset drops/recreates DB and applies migrations
  • make sqlc regenerates Go code without errors
  • make migrate-diff generates a no-diff when schema matches migrations

@yiningsoong yiningsoong force-pushed the feat/135-decide-on-tooling-stack-pgx-sqlc-migration-tool branch from 3d8a427 to c585715 Compare May 6, 2026 02:54
Comment thread docker-compose.yaml
@@ -0,0 +1,14 @@
services:
postgres:
image: postgres:17
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we check if AWS supports Postgres version 18? IIRC, v18 has built in UUIDv7 function.

Comment thread server/cmd/tw/main.go Outdated

func run(ctx context.Context, cfg *config.Config) error {
h, err := handler.New(cfg)
pool, err := pgxpool.New(ctx, cfg.DatabaseURL)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: Since we don't have any queries yet, can we defer the initialisation of pgx until we have our first query?

Comment thread docker-compose.yaml
services:
postgres:
image: postgres:17
environment:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shall we add container_name: tw-postgres above environment?

Comment thread docker-compose.yaml Outdated
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: teacher_workspace
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
POSTGRES_DB: teacher_workspace
POSTGRES_DB: tw OR tw-dev

Comment thread docs/database.md Outdated

```bash
# sqlc: generates Go code from SQL queries
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can explore go tool to setup sqlc and atlas. I think we can pin the tools to specific version and contributors no need to manually install tools.

@YimingIsCOLD YimingIsCOLD marked this pull request as draft May 12, 2026 08:56
@yiningsoong yiningsoong force-pushed the feat/135-decide-on-tooling-stack-pgx-sqlc-migration-tool branch from c585715 to 3a88b31 Compare May 19, 2026 00:06
@yiningsoong yiningsoong marked this pull request as ready for review May 20, 2026 10:27
@yiningsoong yiningsoong changed the title feat(db): wire pgx pool with sqlc and Atlas tooling feat(db): add Atlas declarative schema, Postgres 18, and sqlc queries May 20, 2026
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.

2 participants