container = $container; } /** * @param Schema $schema */ public function up(Schema $schema) { $entryTable = $schema->getTable($this->getTable('entry')); $this->skipIf($entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.'); switch ($this->connection->getDatabasePlatform()->getName()) { case 'mysql': $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url (255), given_url (255), user_id);'; break; case 'postgresql': $sql = 'CREATE INDEX ' . $this->indexGivenUrl . ' ON ' . $this->getTable('entry') . ' (url, given_url, user_id);'; break; } $this->addSql($sql); } /** * @param Schema $schema */ public function down(Schema $schema) { $entryTable = $schema->getTable($this->getTable('entry')); $this->skipIf(false === $entryTable->hasIndex($this->indexGivenUrl), 'It seems that you already played this migration.'); $entryTable->dropIndex($this->indexGivenUrl); } private function getTable($tableName) { return $this->container->getParameter('database_table_prefix') . $tableName; } }