Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Dec 5, 2025

Improved Atlas Migration Management for Supabase Integration

This PR enhances our database migration workflow by improving how we handle the Supabase baseline schema:

  • Added comprehensive documentation in atlas/README.md explaining the migration system, baseline schema, and extension management
  • Created a new dump-fresh-baseline.sh script that properly captures a fresh Supabase project schema
  • Replaced the dynamic schema dumping with a pre-generated baseline file (supabase-baseline-schema.sql)
  • Added extension verification to ensure our assumptions about Supabase's pre-installed extensions match reality
  • Documented the differences between local CLI and hosted Supabase environments
  • Removed the now-obsolete dump-realtime-schema NX task
  • Updated related scripts to use the new baseline file location

This approach is more reliable as it:

  1. Explicitly documents which extensions are pre-installed vs. which need to be created
  2. Handles differences between local CLI and hosted Supabase environments
  3. Provides a clear process for regenerating the baseline when Supabase CLI versions change

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

⚠️ No Changeset found

Latest commit: 9ee0fa1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2025

View your CI Pipeline Execution ↗ for commit 9ee0fa1

Command Status Duration Result
nx run core:pgtap ✅ Succeeded <1s View ↗
nx affected -t verify-exports --base=origin/mai... ✅ Succeeded 4s View ↗
nx affected -t build --configuration=production... ✅ Succeeded 30s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 36s View ↗
nx run client:e2e ✅ Succeeded 1m 9s View ↗
nx run edge-worker:test:integration ✅ Succeeded 3m 45s View ↗
nx run cli:e2e ✅ Succeeded 5s View ↗
nx run edge-worker:e2e ✅ Succeeded 46s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-05 23:04:38 UTC

Comment on lines +101 to +105
sed -i 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql

# Strip date-specific partitions (they change daily, we don't reference them)
# e.g., messages_2025_12_04, messages_2025_12_05, etc.
sed -i '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
Copy link
Contributor

Choose a reason for hiding this comment

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

The sed -i command has portability issues between Linux and macOS. On macOS, sed -i requires a backup extension argument (e.g., sed -i ''), while Linux uses sed -i directly. This will cause the script to fail on macOS with the error: "invalid command code" due to the set -euo pipefail at line 14.

Fix:

# Use a cross-platform approach
sed 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql > supabase-baseline-schema.sql.tmp
mv supabase-baseline-schema.sql.tmp supabase-baseline-schema.sql

sed '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql > supabase-baseline-schema.sql.tmp
mv supabase-baseline-schema.sql.tmp supabase-baseline-schema.sql

Or detect the OS:

if [[ "$OSTYPE" == "darwin"* ]]; then
  sed -i '' 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql
  sed -i '' '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
else
  sed -i 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql
  sed -i '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
fi
Suggested change
sed -i 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql
# Strip date-specific partitions (they change daily, we don't reference them)
# e.g., messages_2025_12_04, messages_2025_12_05, etc.
sed -i '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
# Strip VERSION strings that change with every dump
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql
else
sed -i 's/ VERSION "[^"]*"//g' supabase-baseline-schema.sql
fi
# Strip date-specific partitions (they change daily, we don't reference them)
# e.g., messages_2025_12_04, messages_2025_12_05, etc.
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
else
sed -i '/messages_20[0-9]\{2\}_[0-9]\{2\}_[0-9]\{2\}/d' supabase-baseline-schema.sql
fi

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jumski jumski force-pushed the 12-05-refactor_atlas_baseline_to_use_fresh_hosted_supabase_schema branch from 6797882 to 9ee0fa1 Compare December 5, 2025 22:53
|-----------|---------|-------------|-------|
| pgmq | v1.5.1 | 1.5.1 | pgflow dependency (not in Supabase image) |
| pg_cron | v1.6.4 | 1.6 | Scheduled jobs (v1.6.3+ for PG17) |
| pg_net | v0.7.1 | 0.20.2 | HTTP requests from SQL |
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation mismatch: The table shows pg_net Git Tag as v0.7.1, but the Dockerfile (line 43) checks out v0.20.2. This inconsistency will confuse developers about which version is actually installed.

Fix:

| pg_net | v0.20.2 | 0.20.2 | HTTP requests from SQL |
Suggested change
| pg_net | v0.7.1 | 0.20.2 | HTTP requests from SQL |
| pg_net | v0.20.2 | 0.20.2 | HTTP requests from SQL |

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +95 to +96
atlas schema inspect \
--schema realtime,vault \
Copy link
Contributor

Choose a reason for hiding this comment

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

Critical bug: The script only inspects realtime,vault schemas, but the committed baseline file includes the pgsodium schema (lines 1-2 and 7-8 of supabase-baseline-schema.sql). When this script is run, it will regenerate a baseline missing the pgsodium schema, causing Atlas migration diffs to incorrectly try to drop/recreate pgsodium.

Fix:

atlas schema inspect \
  --schema realtime,vault,pgsodium \
Suggested change
atlas schema inspect \
--schema realtime,vault \
atlas schema inspect \
--schema realtime,vault,pgsodium \

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

🔍 Preview Deployment: Website

Deployment successful!

🔗 Preview URL: https://pr-507.pgflow.pages.dev

📝 Details:

  • Branch: 12-05-refactor_atlas_baseline_to_use_fresh_hosted_supabase_schema
  • Commit: 3c613511e69bb89a09855790191d3f36be1c82db
  • View Logs

_Last updated: _

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