feat(db): add golang-migrate SQL migrations and wire docker-compose runner#4
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 upondocker compose up; retries on failureUsage:
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