Skip to content

Commit f1ec4ef

Browse files
authored
Merge pull request #997 from cakephp/docs/5x-improvements
Docs: Improve documentation for 5.x release
2 parents dee5b42 + 7ea6311 commit f1ec4ef

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

docs/en/index.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Migrations
33

44
Migrations is a plugin that lets you track changes to your database schema over
55
time as PHP code that accompanies your application. This lets you ensure each
6-
environment your application runs in can has the appropriate schema by applying
6+
environment your application runs in has the appropriate schema by applying
77
migrations.
88

99
Instead of writing schema modifications in SQL, this plugin allows you to
@@ -468,8 +468,8 @@ for use in unit tests), you can use the ``--generate-only`` flag:
468468
469469
bin/cake bake migration_snapshot Initial --generate-only
470470
471-
This will create the migration file but will not add an entry to the phinxlog
472-
table, allowing you to move the file to a different location without causing
471+
This will create the migration file but will not add an entry to the migrations
472+
tracking table, allowing you to move the file to a different location without causing
473473
"MISSING" status issues.
474474

475475
The same logic will be applied implicitly if you wish to bake a snapshot for a
@@ -603,15 +603,15 @@ Cleaning up missing migrations
603603
-------------------------------
604604

605605
Sometimes migration files may be deleted from the filesystem but still exist
606-
in the phinxlog table. These migrations will be marked as **MISSING** in the
607-
status output. You can remove these entries from the phinxlog table using the
606+
in the migrations tracking table. These migrations will be marked as **MISSING** in the
607+
status output. You can remove these entries from the tracking table using the
608608
``--cleanup`` option:
609609

610610
.. code-block:: bash
611611
612612
bin/cake migrations status --cleanup
613613
614-
This will remove all migration entries from the phinxlog table that no longer
614+
This will remove all migration entries from the tracking table that no longer
615615
have corresponding migration files in the filesystem.
616616

617617
Marking a migration as migrated

docs/en/writing-migrations.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,72 @@ configuration key for the time being.
599599

600600
To 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+
602668
Table Partitioning
603669
------------------
604670

0 commit comments

Comments
 (0)