
Realistic Demo Data That Ages: Shift Dates Every Night Instead of Reseeding
How we keep realistic demo data in a public demo club by generating it once, recording every row in a ledger, and moving its dates forward by whole days each night instead of reseeding.
Realistic demo data has to look like it was made this morning. A demo club with last month's bookings and a league that ended in August looks abandoned. Our public demo club used to solve that by wiping its activity every night and generating it again. Since 19 October 2026 it ages instead. Every row is made once and recorded in a ledger. Each night the rebuild moves the row's dates forward by the whole days since the last run, so a booking at today + 3 at 18:00 is still at today + 3 at 18:00 tomorrow.
This post covers how that works, the two things that broke on the way, and the tests that prove a night of aging changes dates and nothing else.
The starting point
SportyPlus is club-management software for sports clubs; the demo is a tennis and padel club. Prospects want to see it the way a member does, so there is a demo club anyone can open. One click signs a visitor in as a shared demo member, who can book courts, join the league and buy in the shop. What visitors do is cleared overnight.
Two apps share the demo club's data. A Laravel API serves the member app and keeps its own
database. The newer platform keeps another one. The nightly job, demo:rebuild, runs in
the API at 03:30 Central European time, writes to both databases, and refuses to run unless the club is
flagged as the demo.
The first version, merged on 5 October 2026, made the fixed parts once: six courts, eighty
generated members on a reserved @demo.invalid domain, and the shared member. It then
regenerated the activity every night, with bookings for the two weeks either side of today
from a seed that changed daily:
mt_srand((int) $today->format('Ymd'));
The seed kept the club the same all day and different every day. Over the next days the regeneration grew to cover a league with two cycles, match-finder ads and a family for the shared member.
What we did
Dead end one: the wipe has to know what it owns
Regenerating means deleting first, and the delete has to tell its own rows from everything else. The first production run after the league was added failed with this:
1451 Cannot delete or update a parent row: ... tournaments_league_id_foreign
... delete from `leagues` where `id` in (931, 932, 1202, 1204)
The wipe took every league at the demo club, but the club still had leagues from before the demo existed, and tournaments pointed at them. It also took every result recorded at the club. The command runs inside a database transaction, so the failed run rolled back and nothing needed cleaning up. The fix scoped the wipe to the league's two cycles by name. That held, but "by name" is a guess about ownership, and every new kind of generated data needed another guess.
Every one of those deletes is a plain query-builder delete, never an Eloquent model delete,
and that rule survived every version. In our code, deleting a Reservation model refunds
the player's club wallet or their card and
notifies the players. A cleanup job that goes through model events runs your business logic
on fake data.
Make it once, then only move it
The rewrite stops regenerating. On its first run it does one last wipe of whatever the old regeneration left. Then it generates the bookings, the league and the ads once and records every row. Every later run removes what visitors made and shifts the dates of everything it owns. Nothing it owns is deleted or inserted again.
That needs two things to be remembered between runs. One table holds the anchor day, the day the dates were last set for. The other is a ledger of every generated row:
Schema::create('demo_rows', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('club_id')->index();
// `reservations`, or `new.match_classifieds` for Sporty's tables
$table->string('row_table', 64);
$table->unsignedBigInteger('row_id');
$table->unique(['row_table', 'row_id']);
});
The app never writes to the ledger. The migration's own comment gives the reason: "nothing about the row itself (who plays, who owns it) can be trusted for that". A visitor's booking can have a generated member as a partner. A generated booking can have a visitor added to it. Only the ledger knows which rows the rebuild made.
So a visitor's row is simply anything at the demo club that the ledger does not list:
$generated = $ledger->ids('reservations')->flip();
$visitorBookings = DB::table('reservations')->whereIn('court_id', $courtIds)->pluck('id')
->reject(fn ($id) => $generated->has($id))->values();
The same rule covers the rest. Players a visitor added to a generated booking come off it, and a generated booking a visitor cancelled is restored. A result entered on a generated game is deleted, the game goes back to unplayed, and the league table is recalculated. Visitor rows go before anything shifts, so a generated booking never moves onto a slot a visitor holds.
Shift by calendar days, in the club's time zone
The number of days comes from the anchor, counted between two plain dates, not in hours:
// Whole days, counted on the calendar: both ends are plain dates.
$days = $anchor ? (int) round($anchor->diffInDays(CarbonImmutable::parse($today->toDateString()))) : 0;
Both apps store times in UTC, and that is where the obvious version goes wrong. Adding 3 × 24 hours to a UTC timestamp across the end of summer time turns an 18:00 booking into a 17:00 one. So every datetime goes to the club's time zone, moves by calendar days there, and comes back:
$values[$column] = CarbonImmutable::parse($row->{$column}, 'UTC')->setTimezone($timezone)
->addDays($days)->setTimezone('UTC')->format('Y-m-d H:i:s');
A date column has no time of day and is just moved by the same days. The shift covers
bookings, games, results, the league cycles, ad timestamps, events with their tickets'
check-ins and seat holds, and a tournament. The tournament stays frozen with its quarter
finals played and one semi-final done. The league's spring cycle stays finished and the
autumn one stays in progress, with the same results.
Content the admin pages need: made once, found by a stable key
The same release filled the demo club's admin lists: news, pages, a gallery, sponsors, coaches, a season ticket, work orders and a school programme. These rows don't go in the ledger. Each one is found again by a stable key, such as a slug, a fixed title or a SKU, and one helper either inserts it or moves its dates:
if (! $row) {
return $this->new->table($table)->insertGetId($values + ($clubColumn ? [$clubColumn => $this->club->new_id] : []));
}
if ($softDeletes && $row->deleted_at !== null) {
$this->new->table($table)->where('id', $row->id)->update(['deleted_at' => null]);
}
DemoLedger::shift($this->new, $table, [$row->id], $times, $this->days, $this->timezone, $dates);
A news post published three days ago is always three days old, and a post someone deletes in the CMS comes back as itself the next night.
Dead end two: a key someone else could rewrite
Two days after aging went live, we found the shared member's My family screen listing
18 children called Mia and 18 called Leo. The family is made once like everything else: a
partner and two children. The children are
managed accounts with no email, so the rebuild
found them through the link from the legacy user to the platform account, users.new_id.
A different nightly job, which links legacy users to platform accounts by email, ran at 01:00 UTC. It picked users to link with this:
whereNull('new_id')->orWhere('new_id', 0)
new_id is a UUID string. MySQL compared it with the integer 0 numerically, and a UUID
that starts with a letter casts to 0, so almost every user was selected every night. For a
user with no email, where('email', null) became email IS NULL and matched the first
such platform row, which belonged to a deleted account. So every night the children's link
was overwritten, the rebuild could not find them, and it made two more. A read-only check
on production found 34 demo children pointing at that deleted account. It also found 29
real users with no email, mostly managed children at real clubs.
The fix compares new_id with the string '0', skips users with no email, and never links
to a deleted account. The rebuild now finds each child from the side it controls: its own
guardian link, then the platform account's back-reference to the legacy user. It also
repairs a drifted link and soft-deletes the copies earlier nights made. The rule we took
from it: the key you use to find your own rows must be one that only you write. The
ledger follows that rule, and the family lookup did not.
How we checked it
The aging test runs the whole rebuild against a fixed Tuesday, 20 October 2026, chosen so that the shifts cross the end of daylight saving time on 25 October and a weekend:
$later = app(RebuildDemoClub::class)($this->today->addDays(3));
expect($later['days_shifted'])->toBe(3)
->and(demoRowCounts($this->demo))->toBe($counts)
->and(demoDates($this->demo))->toBe(shiftedDemoDates($dates, 3))
According to the pull request, demoRowCounts covers 40 tables at the demo club and
demoDates 16 kinds of date, each read as wall-clock time in the club's zone. The test
asserts three things in order:
- A second run on the same day changes no count and no date.
- Three days later every count is the same, every date is exactly three calendar days later at the same local time, and each booking sits on the same court, the same number of days from today, at the same hours.
- Ten days after the start, the same holds for ten days.
A second test plays a visitor. It books with a generated member as partner and pays in test mode, joins a generated booking, enters a league result, signs up for the tournament and posts ads. It checks that all of that is gone after one night and that the generated rows survive, shifted. A third covers chat: conversations with a demo account are removed, and one between two real accounts is not. The duplicate-children fix added a test that recreates production's state, with the children moved onto the deleted account and an extra copy. It fails on the old rebuild and passes on the new one.
Each demo test does a full rebuild, about 30 seconds locally, which is slow for a unit test and cheap for what it proves.
Results
- Aging was merged and deployed on 19 October 2026. After the first run, the nightly rebuild inserts and deletes none of its own rows. It only updates dates and removes what visitors made, so the database doesn't grow with the demo's history.
- The ownership guesses are gone. What the rebuild may delete is decided by one ledger lookup, not by a name match per table.
- The duplicate-children fix was deployed on 21 October. The first rebuild after it cleaned up the copies. The app store screenshots we capture from the demo had shown the children repeated, and they were re-captured the next day with one partner and two children.
We don't have a performance number to offer. The gains are in correctness, and the tests above are the evidence.
What you can reuse
- Age demo data instead of regenerating it. Store an anchor day, and each run move every owned date by the whole days since. Relative structure, like "finished last cycle, current cycle in progress", survives for free.
- Keep a ledger of generated rows in a table the app never writes. Anything not in it is a visitor's, whoever it involves, which is easier than reading ownership off the row.
- Shift in local time, then convert back. Add calendar days in the venue's time zone, not 24-hour multiples in UTC, or every evening slot drifts an hour twice a year.
- Test the shift across a DST boundary. Run the job twice on one day and assert nothing changes, then run it N days later and assert row counts are equal and every date moved by exactly N days.
- Clean up with plain queries. Model deletes run refunds, notifications and integrations. That logic is meant for real data, not for your demo.
- Never compare a string ID column with an integer in MySQL.
'a1b2…' = 0is true.
The court booking features the demo shows are the same ones a real club runs. We just keep the dates fresh. Our previous engineering post covered optimizing this website with Claude Code.
You can see the result yourself: try the demo club, book a court as the demo member, and check again tomorrow. Your booking will be gone, and everything else will have moved one day.
English
Hrvatski
Slovenščina
Српски
Македонски
Deutsch
Português (BR)
Italiano
Español
Français
Slovenčina
Ελληνικά
Čeština
Dansk
Eesti
Polski
Magyar
Български
Română
Shqip