Laravel : Database Indexing Workflow

Burim Shala
Laravel News
Published in
1 min readDec 19, 2015

While admiring the Laravel flexibility on many architectural patterns and discussing with a friend of mine we ended up on the conclusion that Laravel tries to embrace you into some very Laravel specific patterns, and one of them is Database migrations.

Usually the indexing workflow goes parallel with querying Models, and on Laravel the proper way of altering tables is using migrations. Migrations are really powerful if you want to ship some sort of database versioning and even DevOps sometimes might struggle into migrations. But creating a new migration each time you need to add an index might be a pain in the ass and usually on small projects you might just live with the DB facade.

While on Quora you see like tons of suggestions that you have to apply design even to the smallest part of your code, so using a DB facade will break Single Responsibility Principle very quick.

In order to make your classes testable, those which are responsible for persistence you have to use Repositories.

The rules is really simple, only Application Services can talk to Domain Models and there’s no exception, this way you can create a really good system which provides an awesome separation of concern.

And one of the features you get by doing a proper design, you get also a single class(The repository) which is responsible for persistence and after you’re done with all your queries which are only performed by repository you can built up indexes by having only one or few migration which created previously table structures.

--

--