A tool kit of enhancements to Laravel's migrations.
- Nomadic Schema - Associate data with each migration. Maybe you want to save the date and time the migration was run, how long it ran for, or specific data with regards to nature of the migration itself.
- More to come...
Local/project installation:
composer require-dev chrishalbert/laravel-nomadic
or manually add it to the require-dev section of your composer file.
{
"require" : {
"chrishalbert/laravel-nomadic": "*"
}
}
- Use Case: A developer wants to track the migration's runtime.
- Use Case: A developer wants to know exactly when a migration started or ended.
- Use Case: A developer deletes records from a table. To rollback this migration, the down() function would include hardcoded values. While this could work for some simple applications, any randomized or scrubbed database will not necessarily translate across tables.
- Use Case: A developer inserts new records into a table. To rollback this migration, the down() function would need to query the exact records that were inserted. If the developer's database is a lean version of production, the query may not be accurate.
- Use Case: A developer updates records in table. Similarly, to rollback, the down() function would need to know the exact values of the records prior to updating. This could differ for randomized data.
- First, you will need to add the field(s) to your migration table - this is on you to do :)
- Next, you will integrate into your application.
php artisan vendor:publish // Installs the nomadic.php config
Open up the nomadic.php and add the fields in the schema array
return [
// Just some examples below - these would be the additional columns in your migration table.
'schema' => [
'flag',
'author',
'runTime',
'migrationInfo'
],
];
Add the Service Provider to the config/app.php
'providers' => [
/**
* Custom Providers...
*/
ChrisHalbert\LaravelNomadic\NomadicServiceProvider::class,
]
Verify the configurations are complete.
php artisan make:migration VerifyNomadicInstalled
In your migration, you should now see that your migration extends NomadicMigration
.
As noted above in your new migration's comments:
/**
* @return void
*/
public function up()
{
// Use $this->setProperty($migrationColumn, $insertedIds);
// The $migrationColumn MUST be added to the configs/nomadic.php
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// And now you can $insertedIds = $this->getProperty($migrationColumn) and delete
}
Submit feature requests or bugs to laravel-nomadic Issues.
I know that there are some good ideas out there!