Skip to content

feat: schedule sandbox:sync to run hourly#204

Merged
roncodes merged 1 commit intodev-v1.6.41from
feat/schedule-sandbox-sync
Apr 21, 2026
Merged

feat: schedule sandbox:sync to run hourly#204
roncodes merged 1 commit intodev-v1.6.41from
feat/schedule-sandbox-sync

Conversation

@roncodes
Copy link
Copy Markdown
Member

Summary

Registers the sandbox:sync Artisan command in the CoreServiceProvider scheduler so that production users and companies are periodically mirrored into the sandbox database automatically.

Motivation

The sandbox database must contain matching users and companies rows for any sandbox operation that references those tables via foreign keys. Previously the only way to populate these rows was to run php artisan sandbox:sync manually, 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.php

$schedule->command('sandbox:sync')
    ->hourly()
    ->name('sandbox-sync')
    ->withoutOverlapping();

Why hourly?

Concern Reasoning
Freshness New production users/companies appear in sandbox within at most 60 minutes — acceptable for a development/testing environment.
DB load sandbox:sync only performs updateOrInsert upserts on a small set of rows (users, companies, api_credentials). Running it every hour is negligible overhead.
Safety 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.

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.
@roncodes roncodes changed the base branch from main to dev-v1.6.41 April 21, 2026 07:00
@roncodes roncodes merged commit 81bef54 into dev-v1.6.41 Apr 21, 2026
3 checks passed
@roncodes roncodes deleted the feat/schedule-sandbox-sync branch April 21, 2026 07:00
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