3 namespace Application\Migrations
;
5 use Doctrine\DBAL\Migrations\AbstractMigration
;
6 use Doctrine\DBAL\Schema\Schema
;
7 use Symfony\Component\DependencyInjection\ContainerAwareInterface
;
8 use Symfony\Component\DependencyInjection\ContainerInterface
;
10 class Version20160410190541
extends AbstractMigration
implements ContainerAwareInterface
13 * @var ContainerInterface
17 public function setContainer(ContainerInterface
$container = null)
19 $this->container
= $container;
22 private function getTable($tableName)
24 return $this->container
->getParameter('database_table_prefix').$tableName;
27 private function hasColumn($tableName, $columnName)
29 switch ($this->connection
->getDatabasePlatform()->getName()) {
31 $rows = $this->connection
->executeQuery('pragma table_info('.$tableName.')')->fetchAll();
32 foreach ($rows as $column) {
33 if (strcasecmp($column['name'], $columnName) === 0) {
40 $rows = $this->connection
->executeQuery('SHOW COLUMNS FROM '.$tableName)->fetchAll();
41 foreach ($rows as $column) {
42 if (strcasecmp($column['Field'], $columnName) === 0) {
49 $sql = sprintf("SELECT count(*)
50 FROM information_schema.columns
51 WHERE table_schema = 'public' AND table_name = '%s' AND column_name = '%s'",
55 $result = $this->connection
->executeQuery($sql)->fetch();
57 return $result['count'] > 0;
62 * @param Schema $schema
64 public function up(Schema
$schema)
66 $this->skipIf($this->hasColumn($this->getTable('entry'), 'uuid'), 'It seems that you already played this migration.');
68 if ($this->connection
->getDatabasePlatform()->getName() == 'postgresql') {
69 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid UUID DEFAULT NULL');
71 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" ADD uuid LONGTEXT DEFAULT NULL');
74 $this->addSql('INSERT INTO "'.$this->getTable('craue_config_setting')."\" (name, value, section) VALUES ('share_public', '1', 'entry')");
78 * @param Schema $schema
80 public function down(Schema
$schema)
82 $this->skipIf($this->connection
->getDatabasePlatform()->getName() != 'sqlite', 'This down migration can\'t be executed on SQLite databases, because SQLite don\'t support DROP COLUMN.');
84 $this->addSql('ALTER TABLE "'.$this->getTable('entry').'" DROP uuid');
85 $this->addSql('DELETE FROM "'.$this->getTable('craue_config_setting')."\" WHERE name = 'share_public'");