9 · Atlas Cloud (optional)
Objective — optionally register your schema with Atlas Cloud for versioned, team-visible migration tracking: open the SSH tunnel, build a baseline migration from the staging schema, push it to Atlas Cloud, apply the baseline to staging, and wire up GitHub CI to gate future schema changes.
Background
Section titled “Background”If you have a license, this registers a baseline migration built from your staging database into Atlas Cloud, then gates future schema changes through CI.
Whether to do this page at all:
flowchart LR Tunnel[SSH tunnel to staging DB] --> Baseline[Register baseline migration] Baseline --> Atlas[Atlas Cloud ERD] Change[Future schema change] --> CI[CI migration gate] CI --> Atlas1. Open the SSH tunnel
Section titled “1. Open the SSH tunnel”Tunnel the staging MySQL port to localhost so Atlas can reach it.
-
Open the tunnel and confirm the staging URL is set.
Terminal window ssh -L 3307:127.0.0.1:3306 <staging-alias> -N &ps aux | grep "ssh -L"echo "Staging URL: $ATLAS_STAGING_URL" # if empty, run `direnv allow` in the project root# Expected: the tunnel process is running; $ATLAS_STAGING_URL is non-empty- ✅ The tunnel is up and
$ATLAS_STAGING_URLresolves.
- ✅ The tunnel is up and
2. Create the schema baseline
Section titled “2. Create the schema baseline”Export the live staging schema and generate a baseline migration from it.
-
Inspect, diff, and mark the baseline applied locally.
Terminal window # Backup existing migrations before rebuild (never blind rm)ATLAS_MIG_DIR=packages/ZajModules/Database/Atlas/migrationsif [ -d "$ATLAS_MIG_DIR" ] && [ "$(ls -A "$ATLAS_MIG_DIR" 2>/dev/null)" ]; thenmv "$ATLAS_MIG_DIR" "${ATLAS_MIG_DIR}.bak.$(date +%Y%m%d-%H%M%S)"fimkdir -p "$ATLAS_MIG_DIR"# Export the live staging schemaatlas schema inspect -u "$ATLAS_STAGING_URL" --format '{{ sql . }}' \> packages/ZajModules/Database/Atlas/schema/current.sqlgrep -c "CREATE TABLE" packages/ZajModules/Database/Atlas/schema/current.sql # sanity-check table count# Generate the baseline migrationatlas migrate diff baseline \--dir "file://packages/ZajModules/Database/Atlas/migrations" \--to "file://packages/ZajModules/Database/Atlas/schema/current.sql" \--dev-url "docker://mysql/8/dev"# Mark it applied locally (substitute the generated timestamp)atlas migrate apply \--dir "file://packages/ZajModules/Database/Atlas/migrations" \--url "$ATLAS_LOCAL_URL" \--baseline "YOUR_TIMESTAMP"# Expected: a baseline migration generated and marked applied against the local URL- ✅ A baseline migration is generated from the staging schema and marked applied locally.
3. Push to Atlas Cloud
Section titled “3. Push to Atlas Cloud”Publish the baseline migration directory to Atlas Cloud.
-
Push the migrations directory.
Terminal window atlas migrate push YOUR_PROJECT_NAME \--dir "file://packages/ZajModules/Database/Atlas/migrations" \--dev-url "docker://mysql/8/dev"# Expected: a project URL is returned; the ERD tab shows your tables- ✅ The push returns a URL and the ERD tab shows your tables.
Open the returned URL — the ERD tab should show your tables.
4. Apply the baseline to staging
Section titled “4. Apply the baseline to staging”Register staging against the pushed baseline and confirm it’s synced.
-
Apply the baseline and check status.
Terminal window atlas migrate apply \--dir "file://packages/ZajModules/Database/Atlas/migrations" \--url "$ATLAS_STAGING_URL" \--baseline "YOUR_TIMESTAMP"atlas migrate status \--dir "file://packages/ZajModules/Database/Atlas/migrations" \--url "$ATLAS_STAGING_URL"# expect: Migration Status: OK- ✅
Migration Status: OK— staging is registered and synced.
- ✅
5. Wire up GitHub CI
Section titled “5. Wire up GitHub CI”Gate future schema changes through CI by registering a cloud token and the cloud environments.
-
Copy the token, set the secret, and register the databases.
-
Atlas Cloud → Set Up CI → GitHub → CLI → copy the token (
aci_…). -
Store the secret without putting the token in shell history:
Terminal window printf '%s' 'aci_…' | gh secret set ATLAS_CLOUD_TOKEN --repo OWNER/REPO# Or: gh secret set ATLAS_CLOUD_TOKEN < /path/to/token-file -
Add the cloud environments to
atlas.hcl. -
Register databases:
atlas migrate apply --env cloud-staging --baseline "YOUR_TIMESTAMP".
- ✅ The CI token is stored as
ATLAS_CLOUD_TOKEN, cloud envs are inatlas.hcl, and databases are registered.
-
Checklist
Section titled “Checklist”Do not mark this step done until every box below is checked.
- 🤖 Baseline created — baseline migration created from the staging schema.
- 🤖 Pushed to Atlas Cloud — ERD renders correctly.
- 🤖 Staging synced — staging registered and showing “Synced” (
migrate status: OK). - 🔀 CI configured — GitHub CI token configured (
ATLAS_CLOUD_TOKEN) (👤 copy token from Atlas Cloud).
That closes the optional staging tracks. Continue to Phase 6 · SuperAdmin setup — brand and configure the app on staging.