feat: schedule sandbox:sync to run hourly#204
Merged
roncodes merged 1 commit intodev-v1.6.41from Apr 21, 2026
Merged
Conversation
Registers the sandbox:sync Artisan command in the CoreServiceProvider scheduler so that production users and companies are periodically mirrored into the sandbox database without any manual intervention. Hourly cadence is chosen as a sensible default: - New users/companies created in production become available in sandbox within at most one hour, keeping the sandbox reasonably fresh. - The command is lightweight (upserts only; no heavy data transforms) so running it every hour does not impose meaningful DB load. - withoutOverlapping() ensures a long-running sync cannot queue up multiple concurrent instances if the scheduler fires while a previous run is still in progress. This complements the on-demand sync added to ApiCredentialController (which handles the immediate FK-constraint case at key-creation time) by ensuring the sandbox stays broadly consistent with production over time for all other sandbox operations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Registers the
sandbox:syncArtisan command in theCoreServiceProviderscheduler so that production users and companies are periodically mirrored into the sandbox database automatically.Motivation
The sandbox database must contain matching
usersandcompaniesrows for any sandbox operation that references those tables via foreign keys. Previously the only way to populate these rows was to runphp artisan sandbox:syncmanually, which meant a freshly provisioned instance (or any user who had never triggered a sync) would hit FK constraint errors.PR #203 added an on-demand sync inside
ApiCredentialController::createRecord()to fix the immediate test-key creation failure. This PR adds the complementary scheduled sync so the sandbox stays broadly consistent with production over time — covering all other sandbox operations beyond API key creation.Change
File:
src/Providers/CoreServiceProvider.phpWhy hourly?
sandbox:synconly performsupdateOrInsertupserts on a small set of rows (users,companies,api_credentials). Running it every hour is negligible overhead.withoutOverlapping()prevents concurrent runs if a sync takes longer than expected.A daily cadence would leave the sandbox stale for too long; anything more frequent than hourly (e.g. every 15 min) would be unnecessary given the lightweight on-demand sync already in place for the FK-critical path.