Last active
August 29, 2015 13:57
-
-
Save QuingKhaos/9421004 to your computer and use it in GitHub Desktop.
Sylius migrations class for PR #986
This file contains 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
<?php | |
/* | |
* Copyright (c) 2014 Patrik Karisch | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is furnished | |
* to do so, subject to the following conditions: | |
* | |
* The above copyright notice and this permission notice shall be included in all | |
* copies or substantial portions of the Software. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
* THE SOFTWARE. | |
*/ | |
namespace Application\Migrations; | |
use Doctrine\DBAL\Migrations\AbstractMigration; | |
use Doctrine\DBAL\Schema\Schema; | |
/** | |
* Migrations for PR #986 | |
* | |
* @author Patrik Karisch <patrik.karisch@abimus.com> | |
*/ | |
class VersionYYYYMMDDHHMMSS extends AbstractMigration | |
{ | |
public function up(Schema $schema) | |
{ | |
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql", "Migration can only be executed safely on 'mysql'."); | |
$this->addSql("ALTER TABLE sylius_inventory_unit DROP FOREIGN KEY FK_4A2769868D9F6D38"); | |
$this->addSql("DROP INDEX IDX_4A2769868D9F6D38 ON sylius_inventory_unit"); | |
$this->addSql("ALTER TABLE sylius_inventory_unit ADD order_item_id INT NOT NULL AFTER order_id"); | |
$this->addSql("UPDATE sylius_inventory_unit AS u " . | |
"INNER JOIN (SELECT id, order_id, variant_id FROM sylius_order_item) AS i " . | |
"ON u.order_id = i.order_id AND u.stockable_id = i.variant_id " . | |
"SET u.order_item_id = i.id" | |
); | |
$this->addSql("ALTER TABLE sylius_inventory_unit ADD CONSTRAINT FK_4A276986E415FB15 FOREIGN KEY (order_item_id) REFERENCES sylius_order_item (id)"); | |
$this->addSql("CREATE INDEX IDX_4A276986E415FB15 ON sylius_inventory_unit (order_item_id)"); | |
$this->addSql("ALTER TABLE sylius_inventory_unit DROP order_id"); | |
} | |
public function down(Schema $schema) | |
{ | |
$this->throwIrreversibleMigrationException("How dare you to migrate down to an unknown development state?"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment