laravel-migration maintained by patrickquijano
Description
This Laravel package provides extended functionalities by overriding core Laravel migration classes.
Author
Last update
2024/11/06 17:09
(dev-dependabot/composer/composer-77f992f351)
License
Downloads
10
Laravel Migration
This Laravel package provides enhanced functionality for managing database migrations. It extends the core Blueprint class and Schema facade to streamline your migration experience.
Features
- Standardized Time Precision: Ensures all time-related database types (like
datetimeandtimestamp) utilize a precision of 6 by default (instead of the default 0). - Automatic Morph Indexing: Automatically adds indexes to all columns created using morph relationships (
morphTo,morphMany, etc.) for improved performance in queries.
Installation
composer require patrickquijano/laravel-migration
Usage
To leverage this package in your existing migrations, simply rename the following classes:
- Replace
Illuminate\Database\Schema\BlueprintwithLaravelMigration\Database\Schema\Blueprint - Replace
Illuminate\Support\Facades\SchemawithLaravelMigration\Support\Facades\Schema
Example (Before):
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamp('email_verified_at')->nullable();
// ...
});
}
Example (After):
use LaravelMigration\Database\Schema\Blueprint;
use LaravelMigration\Support\Facades\Schema;
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamp('email_verified_at')->nullable();
// ...
});
}
Publish Stub Files (Optional)
For convenience, you can publish stub files with the updated imports for your future migrations:
php artisan vendor:publish --tag=laravel-migration-stubs
This will create new stub files within your stubs directory, reflecting the package's classes.
Benefits
- Improved Code Consistency: Enforces a standardized time precision for temporal database types.
- Enhanced Performance: Automatic indexing on morph relationships leads to faster queries.
- Streamlined Development: Stub file publishing simplifies migration creation with pre-configured imports.
We encourage you to utilize this package to streamline your Laravel migration development and ensure optimal database performance.