I'm using MySQL. The documentation doesn't say anything on the matter.
Let me know if there's anything else I can clarify. Thank you for your time.
I'm using MySQL. The documentation doesn't say anything on the matter.
Let me know if there's anything else I can clarify. Thank you for your time.
Laravel does not control table locks during schema changes. This is controlled by the database itself.
For MySQL < 5.6, a read lock will be held on the table for the duration of the schema change, and then a quick exclusive lock will be used to finalize the change.
For MySQL >= 5.6, using InnoDB, most schema changes can be made with only the need for a quick exclusive lock at the beginning of the changes and a quick one at the end of the changes.
You can read this answer for a little more information, or you can check out the MySQL docs.
It's now possible with Laravel 9 by using the command :
php artisan migrate --isolated
https://laravel.com/docs/10.x/migrations#running-migrations
Isolating Migration Execution If you are deploying your application across multiple servers and running migrations as part of your deployment process, you likely do not want two servers attempting to migrate the database at the same time. To avoid this, you may use the isolated option when invoking the migrate command.
When the isolated option is provided, Laravel will acquire an atomic lock using your application's cache driver before attempting to run your migrations. All other attempts to run the migrate command while that lock is held will not execute; however, the command will still exit with a successful exit status code:
php artisan migrate --isolated
I can't affirm that migration will not lock the affected tables. But, reading the Illuminate\Database\Console\Migrations\MigrationCommand.php class code, I do not see anything that talks about lock tables when a migration command occour.
I know that when you work with transactions (eg DB::beginTransactions(), DB::commit() and DB::rollback()) the lock/unlock occours.