Skip to content

fix(dev): match local Postgres to 18 with pre-migrate version gate, seed missing Anthropic server key - #7848

Open
Official-Krish wants to merge 1 commit into
ParadevAI:mainfrom
Official-Krish:fix/local-postgres-18-and-env-seed
Open

Official-Krish wants to merge 1 commit into
ParadevAI:mainfrom
Official-Krish:fix/local-postgres-18-and-env-seed

Conversation

@Official-Krish

@Official-Krish Official-Krish commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7803

What & why

Fresh-checkout ./.superset/setup.local.sh ends with Failed steps: Validate .env, and before that bun run db:migrate fails outright against the local Docker Postgres. Two independent gaps:

  1. Local Postgres (17) vs. production (18). Migrations 0122 and 0125 rename named NOT NULL constraints (webhook_events_swap_*_not_null, automation_events_swap_*_not_null). Those only exist in pg_constraint on PG 18+; on 17 RENAME CONSTRAINT fails, the whole migrate run rolls back, and the local DB ends up empty.
  2. Unseedable required env key. SERVER_ANTHROPIC_API_KEY is required by 5 env schemas (packages/trpc, apps/api, apps/web, apps/admin, apps/marketing), but .env.local.example only had ANTHROPIC_API_KEY. Since step_seed_env_placeholders seeds from the example, no re-run could ever satisfy validation.

Changes

  • docker-compose.yml — image: postgres:17 → postgres:18; data mount moved to /var/lib/postgresql (the 18 image relocated PGDATA to a versioned subdir and won't start with the old /data mount — confirmed against the official image docs). No other version pins exist in the repo.
  • .superset/setup.local.sh (local_migrate) — fail-fast gate before db:migrate: reads SHOW server_version_num via compose exec and aborts below 180000 with a message pointing at teardown.local.sh + re-setup, instead of a rolled-back empty database.
  • .env.local.example — added SERVER_ANTHROPIC_API_KEY=sk-ant-fake-local-dev next to the existing fake Anthropic key.
  • Deliberately untouched: packages/db/drizzle/0122 + 0125 already ran in production, so per AGENTS.md they stay as-is; the fix is local-parity plus the version gate.

How I tested it

  • bash -n + docker compose config clean.
  • Spun a scratch PG 18.6 stack from the edited compose file: booted healthy in ~4s on the new mount, version gate passes (180006).
  • Ran the real bun run db:migrate against it: migrations applied successfully, 50 public tables, journal hashes recorded. Scratch stack torn down.
  • Ran a full ./.superset/setup.local.sh on this checkout: stack healthy, migrations applied, dev account seeded — then reproduced the .env validation failure, applied the example fix, and re-ran validation standalone → green.

Heads-up for reviewers / local devs

  • Existing volumes hold PG 17 data, which PG 18 cannot read. Run ./.superset/teardown.local.sh (already down -vs) and re-run setup. This wipes local dev data — seeding (db:seed-dev) restores the dev account.
  • .env files created from the old example lack the new key; re-running setup seeds it automatically, or append SERVER_ANTHROPIC_API_KEY=sk-ant-fake-local-dev manually.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

Summary by cubic

Fixes #7803: fresh-checkout ./.superset/setup.local.sh failed in two independent places — db:migrate errored against local Postgres 17 (production runs 18, and migrations rename constraints that only exist on PG 18+), and env validation could never pass because required SERVER_ANTHROPIC_API_KEY was missing from the example env. Local Postgres now matches 18, migrations fail fast when the version is below 18, and the example env seeds the missing key.

Migration

  • Existing volumes hold PG 17 data that PG 18 can't read — run ./.superset/teardown.local.sh and re-run setup (wipes local dev data; db:seed-dev restores the dev account).
  • Existing .env files need SERVER_ANTHROPIC_API_KEY=sk-ant-fake-local-dev added, or re-run setup to seed it.

Written for commit 520ad3e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Local Development
    • The local database now runs PostgreSQL 18. Setup checks the database version before applying migrations and stops with an error if the version is unsupported or cannot be verified.
  • Configuration
    • The example environment settings now include a placeholder for the server-side Anthropic API key.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 86ccccfc-4321-45c7-85c7-b4093497011b

📥 Commits

Reviewing files that changed from the base of the PR and between 1167f4b and 520ad3e.

📒 Files selected for processing (3)
  • .env.local.example
  • .superset/setup.local.sh
  • docker-compose.yml

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Local setup now provides a server Anthropic API key placeholder, uses PostgreSQL 18 in Docker Compose, and checks the database server version before running migrations.

Changes

Local API Key Configuration

Layer / File(s) Summary
Server API key placeholder
.env.local.example
Adds a fake local-development value for SERVER_ANTHROPIC_API_KEY.

Local PostgreSQL Migration Setup

Layer / File(s) Summary
PostgreSQL version and migration check
docker-compose.yml, .superset/setup.local.sh
The Compose service uses postgres:18 and mounts the data volume at /var/lib/postgresql. Before migrations, local_migrate rejects nonnumeric server versions and versions below 180000.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: saddlepaddle

Merge Risk: ⚪ Minimal · up to 520ad

Local setup can proceed with PostgreSQL 18 after existing PostgreSQL 17 volumes are removed. No actionable issue remains in the supplied evidence.

Architecture Summary

Architecture risk: 🔵 Low · up to 520ad

The change affects 1 system.

Changed systems: docker-compose.yml

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — docker-compose.yml (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in docker-compose.yml: The postgres image changes from postgres:17 to postgres:18, and the data volume mount moves from /var/lib/postgresql/data to /var/lib/postgresql; the environment, port mapping, and volume name are unchanged.
  • observed — Modified behavior in .env.local.example: Added SERVER_ANTHROPIC_API_KEY with a fake local-development key value.
  • observed — Modified behavior in .superset/setup.local.sh: local_migrate now queries the Compose Postgres container for server_version_num and rejects nonnumeric results or versions below 180000, reporting the detected version and returning failure before migrations run.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The .env.local.example change adds SERVER_ANTHROPIC_API_KEY. Issue [#7803] concerns PostgreSQL local setup and migrations. The environment-key change has no demonstrated connection to that issue a… Remove the unrelated SERVER_ANTHROPIC_API_KEY change from this pull request, or provide a directly linked issue that requires this environment configuration change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title uses conventional commit format and clearly summarizes the PostgreSQL 18 migration fix and missing Anthropic server key.
Description check ✅ Passed The description includes the required What & why, How I tested it, and Checklist sections. It explains the causes, changes, migration impact, testing, and checklist status.
Linked Issues check ✅ Passed The PR implements the coding requirements in issue [#7803]. docker-compose.yml uses postgres:18 and mounts superset_db_data at /var/lib/postgresql. .superset/setup.local.sh checks `server_ve…
Full details: Out of Scope Changes check

Explanation

The .env.local.example change adds SERVER_ANTHROPIC_API_KEY. Issue [#7803] concerns PostgreSQL local setup and migrations. The environment-key change has no demonstrated connection to that issue and is outside its coding scope.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

Local DB migration fails on PostgreSQL 17 at migration 0122 due to missing NOT NULL constraints

1 participant