@@ -599,6 +599,72 @@ configuration key for the time being.
599599
600600To view available column types and options, see :ref: `adding-columns ` for details.
601601
602+ MySQL ALTER TABLE Options
603+ -------------------------
604+
605+ .. versionadded :: 5.0.0
606+ ``ALGORITHM `` and ``LOCK `` options were added in 5.0.0.
607+
608+ When modifying tables in MySQL, you can control how the ALTER TABLE operation is
609+ performed using the ``algorithm `` and ``lock `` options. This is useful for performing
610+ zero-downtime schema changes on large tables in production environments.
611+
612+ .. code-block :: php
613+
614+ <?php
615+
616+ use Migrations\BaseMigration;
617+
618+ class AddIndexToLargeTable extends BaseMigration
619+ {
620+ public function up(): void
621+ {
622+ $table = $this->table('large_table');
623+ $table->addIndex(['status'], [
624+ 'name' => 'idx_status',
625+ ]);
626+ $table->update([
627+ 'algorithm' => 'INPLACE',
628+ 'lock' => 'NONE',
629+ ]);
630+ }
631+ }
632+
633+ Available ``algorithm `` values:
634+
635+ ============ ===========
636+ Algorithm Description
637+ ============ ===========
638+ DEFAULT Let MySQL choose the algorithm (default behavior)
639+ INPLACE Modify the table in place without copying data (when possible)
640+ COPY Create a copy of the table with the changes (legacy method)
641+ INSTANT Only modify metadata, no table rebuild (MySQL 8.0+, limited operations)
642+ ============ ===========
643+
644+ Available ``lock `` values:
645+
646+ ========= ===========
647+ Lock Description
648+ ========= ===========
649+ DEFAULT Use minimal locking for the algorithm (default behavior)
650+ NONE Allow concurrent reads and writes during the operation
651+ SHARED Allow concurrent reads but block writes
652+ EXCLUSIVE Block all reads and writes during the operation
653+ ========= ===========
654+
655+ .. note ::
656+
657+ Not all operations support all algorithm/lock combinations. MySQL will raise
658+ an error if the requested combination is not possible for the operation.
659+ The ``INSTANT `` algorithm is only available in MySQL 8.0+ and only for specific
660+ operations like adding columns at the end of a table.
661+
662+ .. warning ::
663+
664+ Using ``ALGORITHM=INPLACE, LOCK=NONE `` does not guarantee zero-downtime for
665+ all operations. Some operations may still require a table copy or exclusive lock.
666+ Always test schema changes on a staging environment first.
667+
602668Table Partitioning
603669------------------
604670
0 commit comments