Mysql adapter: Changing the STORED status
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4.5k
- Forks
- 884
- PR merge metrics
- No merged PRs in 30d
Description
I encountered an error when using the literal type to change columns.
use Phinx\Db\Adapter\MysqlAdapter;
use Phinx\Util\Literal;
class ContactsGenerated2 extends Phinx\Migration\AbstractMigration
{
public function change()
{
$this->execute('SET unique_checks=0; SET foreign_key_checks=0;');
$this->table('t_contacts', [
'id' => false,
'primary_key' => ['c_uid'],
'engine' => 'InnoDB',
'encoding' => 'utf8mb4',
'collation' => 'utf8mb4_0900_ai_ci',
'row_format' => 'DYNAMIC',
])
->changeColumn('c_fn', Literal::from("varchar(255) COLLATE utf8mb4_unicode_ci GENERATED ALWAYS AS (`c_json`->>'$.fn') VIRTUAL"), [
'null' => true,
])
->update();
$this->execute('SET unique_checks=1; SET foreign_key_checks=1;');
}
}
As long as I change only the json path c_json->>'$.to.something.else', all works well, but changing VIRTUAL to STORED or vice-versa fails with
PDOException: SQLSTATE[HY000]: General error: 3106 'Changing the STORED status' is not supported for generated columns. in /srv/varwwwhtml/glued-skeleton/vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:194...
I think that when the STORED status is changed, the changed column needs to get dropped and recreated.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the MysqlAdapter changeColumn path and the failure reported at src/Phinx/Db/Adapter/PdoAdapter.php:194. Reproduce the migration with a generated column, comparing JSON-path changes with STORED and VIRTUAL changes. Done means changing the generated column's STORED status succeeds rather than raising MySQL error 3106.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100