container = $container; } /** * @return ContainerInterface */ public function getContainer() { return $this->container; } /** * @param string $name * @return string */ protected function getTableName($name) { return getenv('DATABASE_PREFIX') . $name; } /** * @return string * @throws \Doctrine\DBAL\DBALException */ protected function getPlatform() { return $this->connection->getDatabasePlatform()->getName(); } /** * Call me like this: * $schema = $this->getClassMetaData(User::class); * * @param string $entityName * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata */ protected function getClassMetaData($entityName) { $em = $this->getContainer()->get('doctrine')->getManager(); return $em->getClassMetadata($entityName); } /** * we do it via addSql instead of $schema->getTable($users)->dropIndex() * otherwise the commands will be executed as last ones. * * @param string $indexName * @param string $tableName * @throws \Doctrine\DBAL\DBALException */ protected function addSqlDropIndex($indexName, $tableName) { $dropSql = 'DROP INDEX ' . $indexName; if ($this->getPlatform() === 'mysql') { $dropSql .= ' ON ' . $tableName; } $this->addSql($dropSql); } }