Conversation
Implements support for MySQL's ALGORITHM and LOCK clauses in ALTER TABLE
operations, enabling zero-downtime schema migrations for compatible operations.
Key additions:
- Class constants for ALGORITHM (DEFAULT, INSTANT, INPLACE, COPY) and LOCK
(DEFAULT, NONE, SHARED, EXCLUSIVE) options to avoid magic strings
- Column class now supports algorithm and lock options via setAlgorithm()/setLock()
- MysqlAdapter validates and applies algorithm/lock clauses to ALTER operations
- Batched operations detect conflicts and throw clear error messages
- Comprehensive test coverage (11 new test cases)
Benefits:
- Near-zero downtime migrations on large tables with ALGORITHM=INSTANT
- Production-friendly migrations with explicit locking control
- Improved performance for compatible schema changes on MySQL 8.0+/MariaDB 10.3+
Usage:
```php
use Migrations\Db\Adapter\MysqlAdapter;
$table->addColumn('status', 'string', [
'null' => true,
'algorithm' => MysqlAdapter::ALGORITHM_INSTANT,
'lock' => MysqlAdapter::LOCK_NONE,
])->update();
```
Closes #2323
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove duplicate algorithm/lock clauses from individual column instructions - Add MySQL restriction validation: ALGORITHM=INSTANT cannot be combined with explicit LOCK modes (LOCK=NONE, LOCK=SHARED, LOCK=EXCLUSIVE) - Update tests to use ALGORITHM=INPLACE with explicit LOCK values instead - Add test for MySQL restriction validation - Remove unused algorithmClause() method - Update documentation to clarify MySQL restrictions Fixes duplicate clause issue where algorithm/lock was being added twice: once in getAddColumnInstructions() and once in executeActionsWithAlgorithmAndLock(). The algorithm/lock clauses should only be applied at the ALTER TABLE statement level, not at individual column instruction level. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
markstory
reviewed
Nov 11, 2025
| $alterTemplate = sprintf('ALTER TABLE %s %%s', $this->quoteTableName($table->getName())); | ||
|
|
||
| // Add algorithm and lock clauses | ||
| $algorithmLockClause = ''; |
Member
There was a problem hiding this comment.
Won't we be missing lock/algorithm when $adapter->addColumn() and changeColumn() are used because of where this logic is?
Member
Author
There was a problem hiding this comment.
I added a commit. Please check if that makes more sense now.
jamisonbryant
added a commit
that referenced
this pull request
Mar 23, 2026
Extend the ALGORITHM and LOCK clause support added in PR #955 for Column operations to also cover Index operations. This allows addIndex to pass algorithm and lock options through the fluent API on MySQL. Changes: - Add algorithm/lock properties, getters/setters to Index class - Wire algorithm/lock through getAddIndexInstructions in MysqlAdapter - Handle FULLTEXT indexes which use post-steps (inline the clause) - Add 9 tests mirroring the Column algorithm/lock test coverage
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for MySQL's
ALGORITHMandLOCKclauses inALTER TABLEoperations, enabling zero-downtime schema migrations for compatible operations on MySQL 8.0+ and MariaDB 10.3+.Why This Is Useful
Production Impact:
ALGORITHM=INSTANTallows adding nullable columns, dropping columns, and other compatible operations without copying the entire tableLOCK=NONEto ensure migrations don't block concurrent reads/writesReal-world scenario:
Implementation
Class Constants (No Magic Strings)
Key Features
Important MySQL Restriction
LOCK=NONE,LOCK=SHARED,LOCK=EXCLUSIVE) due to MySQL limitations. Use either:ALGORITHM=INSTANTalone (recommended)ALGORITHM=INSTANTwithLOCK=DEFAULTALGORITHM=INPLACEwith any LOCK optionUsage Examples
Single operation:
Batched operations:
Changes
algorithmandlockproperties with getters/settersCompatibility