1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

大量のマイグレーションファイルをドメイン毎にディレクトリ分け

Posted at

はじめに

Laravelにおいて、database/migrationsフォルダは、1テーブルにつき1ファイルが生成されるので、テーブルがどんどん増えてくると管理が難しくなってきますよね。

そこで、ドメイン毎にフォルダ分けすることにしました。
しかしdatabase/migrations下にフォルダを作るだけでは動作しません❌

注意
本番運用開始までは、カラムを追加する際に追加でマイグレーションファイルを作成せず、追記していく前提です

解決策 AppServiceProviderにパスを登録

これだけ!!!

app/Providers/AppServiceProvider.php
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // カスタムマイグレーションパスを登録
        $this->loadMigrationsFrom([
            database_path('migrations/hoge'),
            database_path('migrations/core'),
            database_path('migrations/master'),
            database_path('migrations/huga'),
            database_path('migrations/oreimo'),
        ]);
    }
}

まとめ

本番運用開始まではとても管理しやすくなりました。
稼働後にカラムを追加する際にどうするかも考えておかねば。。。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?