lastdragon-ru / lara-asp-migrator
The Awesome Set of Packages for Laravel - The Migrator.
Requires
- php: ^8.0|^8.1|^8.2
- ext-intl: *
- ext-json: *
- composer/semver: ^3.2
- doctrine/dbal: ^2.12.0|^3.1.4
- laravel/framework: ^9.0.0|^10.0.0
- lastdragon-ru/lara-asp-core: 4.3.0
- symfony/filesystem: ^5.2.0|^6.0.0
- symfony/finder: ^5.1.0|^6.0.0
Requires (Dev)
- ext-pdo_sqlite: *
- lastdragon-ru/lara-asp-testing: 4.3.0
- mockery/mockery: ^1.4.2
- orchestra/testbench: ^6.9.0|^7.0.0|^8.0.0
- phpunit/phpunit: ^9.5.0|^10.1.0
Suggests
- ext-fileinfo: Required for league/flysystem
This package is auto-updated.
Last update: 2023-06-09 06:17:35 UTC
README
This package is the part of Awesome Set of Packages for Laravel.
This package improves standard laravel migrations to add support for raw SQL files during migration and seeding. So you can easily use your favorite visual tool for database development like MySQL Workbench with Laravel 🥳
⚠️ | The Migrator uses the same mechanism as Squashing Migrations so not all databases are supported, please see Laravel Documentation for more details. |
---|
Installation
composer require lastdragon-ru/lara-asp-migrator
Migrations
To create migration just use the standard command
php artisan lara-asp-migrator:raw-migration MyMigration
It will create the following files in database/migrations
:
2020_11_05_170802_my_migration.php
2020_11_05_170802_my_migration~down.sql
2020_11_05_170802_my_migration~up.sql
Usually, you just need to put your SQL into ~up.sql
and ~down.sql
😇 Note that you still can use standard Laravel migrations, but you should create it manually. Also, migrations can be placed into subdirectories.
Another useful class is RawDataMigration
that specially designed for cases when you want to insert data without altering the table(s). Unlike RawMigration
it will apply migration only if the database is not empty (to fill empty database while fresh installation please use Seeders).
Seeders
The Migrator uses a bit different approach compared to standard and provides a few different types of seeders:
SmartSeeder
- unlike standardSeeder
it is safer and will not run seeder if it is already applied (so it is safe for production 🤩);RawSeeder
- extendsSmartSeeder
and allow you to use SQL.
To create raw seeder just use standard command
php artisan lara-asp-migrator:raw-seeder MySeeder
It will create the following files in database/seeders
(or database/seeds/
):
MySeeder.php
MySeeder.sql
You should place your SQL into *.sql
and then update the model class in the .php
file:
<?php declare(strict_types = 1); namespace Database\Seeders; use LastDragon_ru\LaraASP\Migrator\Seeders\RawSeeder; class MySeeder extends RawSeeder { protected function getTarget(): ?string { // Base class will check that the table has any records and stop seeding // if it is not empty. return Model::class; } }