You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: sync user/company to sandbox before creating test API key
When a test/sandbox API key is created the request carries the
Access-Console-Sandbox header, which causes SetupFleetbaseSession to
switch the default database connection to 'sandbox'. The subsequent
INSERT into api_credentials on the sandbox DB references user_uuid and
company_uuid values that come from the production session. Because those
rows do not necessarily exist in the sandbox database the foreign key
constraint api_credentials_user_uuid_foreign (and the companion
company_uuid constraint) fires and the insert fails with SQLSTATE[23000]
1452.
Fix: override createRecord() in ApiCredentialController to detect the
sandbox header and, before delegating to the generic create path, mirror
the current user, company, and company_user pivot row from production
into the sandbox DB using an on-demand upsert (the same pattern used by
the sandbox:sync Artisan command). Foreign key checks are temporarily
disabled during the upsert to avoid ordering issues, then re-enabled
before the api_credentials insert proceeds.
0 commit comments