SonataClassificationBundle
SonataClassificationBundle copied to clipboard
Upgrade migration from 4.x to 5.x
Upgrade Migration
I just did this so I thought to add this somewhere. (MariaDB 10.7) Is this use full?
I had 4 contexts, default, item, sonata_category and sonata_collection. First I needed to change the contexts to their numerical value in same order as they appeared in my instance. They are going to point to context id. Then I copied the contexts table to new one and change the id to AUTO_INCREMENT. After these I could generate new migration to fix everything.
$this->addSql('SET FOREIGN_KEY_CHECKS = 0');
$this->addSql('alter table classification__category drop foreign key FK_43629B36E25D857E');
$this->addSql('UPDATE classification__category SET context = 1 WHERE context="default"');
$this->addSql('UPDATE classification__category SET context = 2 WHERE context="item"');
$this->addSql('UPDATE classification__category SET context = 3 WHERE context="sonata_category"');
$this->addSql('UPDATE classification__category SET context = 4 WHERE context="sonata_collection"');
$this->addSql('UPDATE classification__collection SET context = 1 WHERE context="default"');
$this->addSql('UPDATE classification__collection SET context = 2 WHERE context="item"');
$this->addSql('UPDATE classification__collection SET context = 3 WHERE context="sonata_category"');
$this->addSql('UPDATE classification__collection SET context = 4 WHERE context="sonata_collection"');
$this->addSql('UPDATE classification__tag SET context = 1 WHERE context="default"');
$this->addSql('UPDATE classification__tag SET context = 2 WHERE context="item"');
$this->addSql('UPDATE classification__tag SET context = 3 WHERE context="sonata_category"');
$this->addSql('UPDATE classification__tag SET context = 4 WHERE context="sonata_collection"');
$this->addSql('CREATE TABLE classification__context_new LIKE classification__context');
$this->addSql('ALTER TABLE classification__context_new CHANGE id id INT AUTO_INCREMENT NOT NULL');
$this->addSql('Insert into classification__context_new (name,enabled,created_at,updated_at) SELECT name,enabled,created_at,updated_at from classification__context');
$this->addSql('RENAME table classification__context TO cc_old, classification__context_new TO classification__context');
$this->addSql('DROP table cc_old');
$this->addSql('SET FOREIGN_KEY_CHECKS = 1');
This belongs to ClassificationBundle, not here. Can someone transfer it or should I make new one?
Fixed with #901. context id should be a string, Docs were wrong.