Created
April 26, 2018 10:35
-
-
Save zeromodule/55d4ed93512ddd4bab3804589802a6de to your computer and use it in GitHub Desktop.
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 | |
namespace Application\Migrations; | |
use Doctrine\DBAL\Migrations\AbstractMigration; | |
use Doctrine\DBAL\Schema\Schema; | |
use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Class Version20170925134807 | |
* @package Application\Migrations | |
*/ | |
class Version20170925134807 extends AbstractMigration implements ContainerAwareInterface | |
{ | |
/** | |
* @var ContainerInterface|null | |
*/ | |
private $container; | |
/** | |
* @param ContainerInterface|null $container | |
*/ | |
public function setContainer(ContainerInterface $container = null) | |
{ | |
$this->container = $container; | |
} | |
/** | |
* @param Schema $schema | |
*/ | |
public function up(Schema $schema): void | |
{ | |
$this->skipIf($this->container->getParameter('kernel.environment') === 'test', 'В тестовом окружении orm-схема некорректна для данной миграции'); | |
$this->addSql(' | |
CREATE TABLE IF NOT EXISTS tariff_scale ( | |
id UUID PRIMARY KEY | |
) | |
'); | |
$this->addSql(' | |
CREATE TABLE IF NOT EXISTS tariff_scale_item ( | |
id UUID PRIMARY KEY, | |
tariff_scale_id UUID NOT NULL, | |
from_route_stop_id UUID NOT NULL, | |
to_route_stop_id UUID NOT NULL, | |
price INTEGER NOT NULL, | |
distance NUMERIC(5,1) NOT NULl, | |
CONSTRAINT fk_tsi_scale FOREIGN KEY (tariff_scale_id) REFERENCES tariff_scale (id), | |
CONSTRAINT fk_tsi_from_route_stop FOREIGN KEY (from_route_stop_id) REFERENCES route_stop (id), | |
CONSTRAINT fk_tsi_to_route_stop FOREIGN KEY (to_route_stop_id) REFERENCES route_stop (id) | |
) | |
'); | |
$this->addSql('CREATE INDEX IF NOT EXISTS idx_tsi_scale ON tariff_scale_item (tariff_scale_id)'); | |
$this->addSql('CREATE INDEX IF NOT EXISTS idx_tsi_from_route_stop_id ON tariff_scale_item (from_route_stop_id)'); | |
$this->addSql('CREATE INDEX IF NOT EXISTS idx_tsi_to_route_stop_id ON tariff_scale_item (to_route_stop_id)'); | |
$this->addSql("ALTER TABLE route ADD COLUMN IF NOT EXISTS type VARCHAR(255) DEFAULT 'intercity'"); | |
$this->addSql('ALTER TABLE route ADD COLUMN IF NOT EXISTS tariff_scale_id UUID DEFAULT NULL'); | |
$this->addSql('CREATE INDEX IF NOT EXISTS idx_route_tariff_scale ON route (tariff_scale_id)'); | |
$this->addSql('ALTER TABLE route DROP CONSTRAINT IF EXISTS fk_route_tariff_scale'); | |
$this->addSql(' | |
ALTER TABLE route ADD CONSTRAINT fk_route_tariff_scale | |
FOREIGN KEY (tariff_scale_id) REFERENCES tariff_scale (id) | |
'); | |
$this->addSql('ALTER TABLE route_stop ADD COLUMN IF NOT EXISTS min_interval SMALLINT DEFAULT NULL'); | |
$this->addSql('ALTER TABLE route_stop ADD COLUMN IF NOT EXISTS max_interval SMALLINT DEFAULT NULL'); | |
} | |
/** | |
* @param Schema $schema | |
*/ | |
public function down(Schema $schema): void | |
{ | |
$this->addSql('ALTER TABLE route_stop DROP COLUMN IF EXISTS min_interval'); | |
$this->addSql('ALTER TABLE route_stop DROP COLUMN IF EXISTS max_interval'); | |
$this->addSql('ALTER TABLE route DROP CONSTRAINT IF EXISTS fk_route_tariff_scale'); | |
$this->addSql('ALTER TABLE route DROP COLUMN IF EXISTS tariff_scale_id'); | |
$this->addSql('ALTER TABLE route DROP COLUMN IF EXISTS type'); | |
$this->addSql('DROP TABLE IF EXISTS tariff_scale_item'); | |
$this->addSql('DROP TABLE IF EXISTS tariff_scale'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment