Skip to content

fix(sandbox): copy only the columns the sandbox tables have - #404

Merged
roncodes merged 1 commit into
release/v0.6.73from
fix/sandbox-account-copy-columns
Oct 15, 2026
Merged

roncodes merged 1 commit into
release/v0.6.73from
fix/sandbox-account-copy-columns

Conversation

@roncodes

Copy link
Copy Markdown
Member

Incident

Fleetbase Cloud sandbox ("test mode") 500s. This PR fixes the fleetops part: creating a driver or contact with a flb_test_ key returns HTTP 500. The GET /v1/* 500s and the console 500s are fixed in fleetbase/billing#41, fleetbase/internals#58 and the registry-bridge PR.

Root cause

ProfileAccountManager::copyAccountToSandbox() (from #378) copies the live companies and users rows into the sandbox database with every live column. Extensions that set sandbox-migrations: false add columns that exist only in live. Billing's 2026_01_17_000001_add_resource_units_to_companies adds companies.resource_units and resource_units_updated_at, so on Cloud the upsert fails:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'resource_units' in 'field list' (Connection: sandbox, SQL: update `companies` set ... `resource_units` = 0 ...)
  ProfileAccountManager.php:408 ← :368 attachToCompany ← :180 createManagedAccount ← :150 resolveForProfile ← Api/v1/DriverController.php:1025

Reproduction (local fleetbase-dev stack)

  • POST /v1/drivers with a local test key returns 500 with the error above.
  • Calling copyAccountToSandbox() in-process against the real MySQL fleetbase_sandbox:
    • original class: 1054 Unknown column 'resource_units'
    • this branch: copied, sandbox user rows = 1

Fix

Before the upsert, reduce each copied row to the columns the sandbox table actually has (Schema::connection('sandbox')->getColumnListing()). The id column is still dropped as before.

Tests

  • New test test key requests copy only the columns the sandbox tables have: live companies and users get extra live-only columns that the sandbox lacks. On main it fails with table companies has no column named resource_units; on this branch it passes.
  • scripts/pest-runner.php server/tests/Unit/Support/ProfileAccountManagerTest.php: 14 passed. Before the fix: 13 passed and the new test failed.
  • scripts/pest-file-runner.php (full suite, PHP 8.4): exit 0 across all 513 files.
  • Coverage of ProfileAccountManager.php on this test file: no uncovered statements.
  • php-cs-fixer dry run on both files: clean.

Deploy note

No migration. Takes effect when fleetops is bumped in the fleetbase repo's Cloud deploy.

🤖 Generated with Claude Code

copyAccountToSandbox() copied every live companies/users column into the
sandbox. Extensions that skip sandbox migrations (billing adds
companies.resource_units and resource_units_updated_at) leave columns that
exist only in live, so creating a driver or contact with a test API key
failed with 1054 Unknown column 'resource_units' (HTTP 500).

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4a4ce41) to head (2d3d47a).

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #404   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity     13585     13586    +1     
===========================================
  Files            634       634           
  Lines          49308     49311    +3     
===========================================
+ Hits           49308     49311    +3     
Flag Coverage Δ
backend 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@roncodes roncodes mentioned this pull request Oct 15, 2026
@roncodes
roncodes changed the base branch from main to release/v0.6.73 October 15, 2026 06:58
@roncodes
roncodes merged commit 28424b4 into release/v0.6.73 Oct 15, 2026
11 checks passed
@roncodes
roncodes deleted the fix/sandbox-account-copy-columns branch October 15, 2026 07:02
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.

1 participant