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
I suggest creating a --seed-with-cache flag for the php artisan migrate:fresh command.
Background
When developing seeders for a project, it's easy to add enough models and logic that it starts to take dozens or hundreds of seconds for the seeders to finish. If the reason I am re-seeding is to retry a particular flow that my seeded data sets me up for, it can significantly slow down development to have to wait for the data to return to a base state.
Inserting the data from database dumps can be much faster than that - a few seconds for hundreds of thousands of records. If we were to dump the DB contents immediately after the output of a successful seed call and re-use it on future calls to seed, we could get the same base state of the data with a significant reduction in waiting time.
--seed-with-cache Behavior
When a user calls php artisan migrate:fresh --seed-with-cache, the logic will be different from the standard --seed-using call in the following ways:
It will first drop all tables and data as normal.
Next, it will check a local temp folder (either OS-level temp storage, or one in <workspace_dir>/storage/framework/cache/) for the presence of a dumped database from a previous run of the command.
a. If it exists, restore it and run any newer migrations (equivalent to calling php artisan migrate)
b. If it doesn't exist, run the seeders as normal and upon successful completion, dump the contents of the db to the temp/cache folder for future runs.
Stale versions of the seeded data, where the seeders or database schema have changed, may be dealt with in a couple different ways. The command could show a warning message when the schema of the db dump is missing migrations, with the option to update the cache with --force-seed-cache-update. Another option might be to have the user respond to an input prompt on every run, defaulting to using the cache but offering the option to regenerate the cache if they use the flag like --seed-with-cache=ask.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I suggest creating a
--seed-with-cache
flag for thephp artisan migrate:fresh
command.Background
When developing seeders for a project, it's easy to add enough models and logic that it starts to take dozens or hundreds of seconds for the seeders to finish. If the reason I am re-seeding is to retry a particular flow that my seeded data sets me up for, it can significantly slow down development to have to wait for the data to return to a base state.
Inserting the data from database dumps can be much faster than that - a few seconds for hundreds of thousands of records. If we were to dump the DB contents immediately after the output of a successful seed call and re-use it on future calls to seed, we could get the same base state of the data with a significant reduction in waiting time.
--seed-with-cache
BehaviorWhen a user calls
php artisan migrate:fresh --seed-with-cache
, the logic will be different from the standard--seed
-using call in the following ways:<workspace_dir>/storage/framework/cache/
) for the presence of a dumped database from a previous run of the command.a. If it exists, restore it and run any newer migrations (equivalent to calling
php artisan migrate
)b. If it doesn't exist, run the seeders as normal and upon successful completion, dump the contents of the db to the temp/cache folder for future runs.
Stale versions of the seeded data, where the seeders or database schema have changed, may be dealt with in a couple different ways. The command could show a warning message when the schema of the db dump is missing migrations, with the option to update the cache with
--force-seed-cache-update
. Another option might be to have the user respond to an input prompt on every run, defaulting to using the cache but offering the option to regenerate the cache if they use the flag like--seed-with-cache=ask
.Beta Was this translation helpful? Give feedback.
All reactions