Skip to content

feat(db): add golang-migrate SQL migrations and wire docker-compose runner#4

Merged
PramithaMJ merged 1 commit into
mainfrom
feat/db-migrations
Apr 15, 2026
Merged

feat(db): add golang-migrate SQL migrations and wire docker-compose runner#4
PramithaMJ merged 1 commit into
mainfrom
feat/db-migrations

Conversation

@PramithaMJ
Copy link
Copy Markdown
Member

Introduces db/migrations/ with 6 versioned migration pairs (up + down) that supersede the hand-rolled docs/on-prem/init-db.sql as the authoritative database schema source:

000001_bootstrap — extensions (uuid-ossp, pgcrypto, pg_trgm),
update_updated_at() trigger fn, set_tenant_context()
RLS helper, sf_app role + grants
000002_create_tenants — core tenants table; partial unique index on slug
for non-deleted tenants; trigram index; soft-delete
000003_create_api_keys — SHA-256 key_hash, key_prefix, environment scope,
module_scope array; RLS; partial unique on hash
000004_create_module_configs — module_schemas JSON Schema registry +
module_configs per-tenant JSONB config +
config_history append-only audit log; RLS on
configs and history; booking module schema seed
000005_create_bookings — bookings table with slot_start/slot_end, 5-state
lifecycle CHECK, partial unique anti-double-booking
index, availability/customer/status indices; RLS
000006_create_webhooks — webhooks endpoint registry + webhook_deliveries
dispatcher log with retry state machine; idempotency
unique index on (webhook_id, event_id); RLS

All 12 files applied and rolled back against a live PostgreSQL 17 instance with zero errors (expected GRANT CONNECT DATABASE serviceforge error was test-DB name mismatch, not present against the real serviceforge database).

deploy/docker/docker-compose.dev.yml:
• Added postgres healthcheck so dependent services wait for readiness
• Added migrate service (migrate/migrate:v4.17.1) that mounts db/migrations
read-only and runs migrate up on docker compose up; retries on failure

Usage:
docker compose -f deploy/docker/docker-compose.dev.yml up -d
docker compose -f deploy/docker/docker-compose.dev.yml run --rm migrate down 1

…unner

Introduces db/migrations/ with 6 versioned migration pairs (up + down)
that supersede the hand-rolled docs/on-prem/init-db.sql as the authoritative
database schema source:

  000001_bootstrap      — extensions (uuid-ossp, pgcrypto, pg_trgm),
                          update_updated_at() trigger fn, set_tenant_context()
                          RLS helper, sf_app role + grants
  000002_create_tenants — core tenants table; partial unique index on slug
                          for non-deleted tenants; trigram index; soft-delete
  000003_create_api_keys — SHA-256 key_hash, key_prefix, environment scope,
                           module_scope array; RLS; partial unique on hash
  000004_create_module_configs — module_schemas JSON Schema registry +
                                  module_configs per-tenant JSONB config +
                                  config_history append-only audit log; RLS on
                                  configs and history; booking module schema seed
  000005_create_bookings — bookings table with slot_start/slot_end, 5-state
                           lifecycle CHECK, partial unique anti-double-booking
                           index, availability/customer/status indices; RLS
  000006_create_webhooks — webhooks endpoint registry + webhook_deliveries
                           dispatcher log with retry state machine; idempotency
                           unique index on (webhook_id, event_id); RLS

All 12 files applied and rolled back against a live PostgreSQL 17 instance
with zero errors (expected GRANT CONNECT DATABASE serviceforge error was
test-DB name mismatch, not present against the real serviceforge database).

deploy/docker/docker-compose.dev.yml:
  • Added postgres healthcheck so dependent services wait for readiness
  • Added migrate service (migrate/migrate:v4.17.1) that mounts db/migrations
    read-only and runs `migrate up` on `docker compose up`; retries on failure

Usage:
  docker compose -f deploy/docker/docker-compose.dev.yml up -d
  docker compose -f deploy/docker/docker-compose.dev.yml run --rm migrate down 1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@PramithaMJ PramithaMJ self-assigned this Apr 15, 2026
@PramithaMJ PramithaMJ added the enhancement New feature or request label Apr 15, 2026
@PramithaMJ PramithaMJ merged commit b1a6d55 into main Apr 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant