Tagging migration files #34426
Replies: 1 comment
-
Just to expand on the initial idea. I don’t know if you’ve ever encountered this scenario, but sometimes we need to work with multiple teams on a single project; sometimes even multiple projects, all relying on a single database. In some cases, the project starts to evolve differently across various fronts. For example, a base migration used throughout the project might need new fields for Team 1, while Team 2 is testing the possibility of changing the type of a specific field. Later on, Team 1 is ready to deploy their modifications to production database, but Team 2 still needs to complete other processes before they can release their changes. It’s a chaotic scenario, believe me, I know. However, it would be even more chaotic without flexible control over which migrations make sense to use in the ongoing process. I developed a change to the Eloquent commands, to add the ability to filter my migrations based on tags and thanks to this I can manage parts of the database that should or should not be migrated. Code Example:Artisan Command:
On the MigrateCommand: $this->migrator->setOutput($this->output)
->run($this->getMigrationPaths(), [
'filter-tags' => $this->option('filter-tags'),
...
]); On the Migrator.php: /**
* Run "up" a migration instance.
*
* ...
* @param array $filterTags
* @return void
*/
protected function runUp($file, $batch, $pretend, array $filterTags = [])
{
...
// When filter tags are used, only the migrations with these tags are fully
// processed. Untagged or differently tagged migrations are ignored by the
// migration running process.
if ($filterTags && !array_intersect($filterTags, $migration->tags ?? [])) {
$this->write(TwoColumnDetail::class, $name, '<fg=yellow;options=bold>filtering</>');
return;
} Obviously, it’s not a silver bullet, but just an additional tool to help us achieve greater productivity and control. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When testing we almost always need only a subset of tables to test a single feature and not the entire database, and migrations are slow especially for bigger databases.
So isn't it a good idea to be able to tag the migration classes and when migrating by artisan
Artisan::call('migrate --tag=auth')
only run migrations with special tags.So recreating the entire db schema for each and every test is slow.
Suggestion:
Maybe not the perfect idea but better than nothing.
Beta Was this translation helpful? Give feedback.
All reactions