/**
  * {@inheritdoc}
  */
 public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null)
 {
     if (!$constraintName) {
         $constraintName = $this->nameGenerator->generateForeignKeyConstraintName($this->getName(), $localColumnNames);
     }
     return parent::addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options, $constraintName);
 }
 /**
  * {@inheritdoc}
  */
 protected function checkColumnName($tableName, $columnName, Migration $migration)
 {
     parent::checkColumnName($tableName, $columnName, $migration);
     if (strlen($columnName) > $this->nameGenerator->getMaxIdentifierSize()) {
         throw new InvalidNameException(sprintf('Max column name length is %s. Please correct "%s:%s" column in "%s" migration', $this->nameGenerator->getMaxIdentifierSize(), $tableName, $columnName, get_class($migration)));
     }
 }
 public function testWrongColumnNameQuery()
 {
     $migration = new WrongColumnNameMigration();
     $migrations = [$migration];
     $this->setExpectedException('Oro\\Bundle\\MigrationBundle\\Exception\\InvalidNameException', sprintf('Max column name length is %s. Please correct "%s:%s" column in "%s" migration', $this->nameGenerator->getMaxIdentifierSize(), 'wrong_table', 'extra_long_column_bigger_30_chars', get_class($migration)));
     $this->executor->executeUp($migrations);
 }
 public function testWrongColumnNameQuery()
 {
     $migration = new WrongColumnNameMigration();
     $migrations = [new MigrationState($migration)];
     $this->setExpectedException('\\RuntimeException', 'Failed migrations: Oro\\Bundle\\MigrationBundle\\Tests\\Unit\\Fixture\\TestPackage\\WrongColumnNameMigration.');
     $this->executor->executeUp($migrations);
     $this->assertEquals('> Oro\\Bundle\\MigrationBundle\\Tests\\Unit\\Fixture\\TestPackage\\WrongColumnNameMigration', $this->logger->getMessages()[0]);
     $this->assertEquals(sprintf('  ERROR: Max column name length is %s. Please correct "%s:%s" column in "%s" migration', $this->nameGenerator->getMaxIdentifierSize(), 'wrong_table', 'extra_long_column_bigger_30_chars', get_class($migration)), $this->logger->getMessages()[1]);
 }
Exemple #5
0
 /**
  * Create a foreign key constraint without check of table and columns existence.
  * This method can be helpful when you need to create a constraint for renamed table or column
  *
  * @param Schema      $schema
  * @param QueryBag    $queries
  * @param string      $tableName
  * @param string      $foreignTable
  * @param string[]    $localColumnNames
  * @param string[]    $foreignColumnNames
  * @param array       $options
  * @param string|null $constraintName
  */
 public function addForeignKeyConstraint(Schema $schema, QueryBag $queries, $tableName, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null)
 {
     if (!$constraintName) {
         $constraintName = $this->nameGenerator->generateForeignKeyConstraintName($tableName, $localColumnNames);
     }
     $constraint = new ForeignKeyConstraint($localColumnNames, $foreignTable, $foreignColumnNames, $constraintName, $options);
     $diff = new TableDiff($tableName);
     $diff->addedForeignKeys = [$constraintName => $constraint];
     $renameQuery = new SqlMigrationQuery($this->platform->getAlterTableSQL($diff));
     $queries->addQuery($renameQuery);
 }
 /**
  * @dataProvider emptyTableNameProvider
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage A table name must not be empty.
  */
 public function testGenerateIdentifierNameWithEmptyTableName($tableNames)
 {
     $generator = new DbIdentifierNameGenerator();
     $generator->generateIdentifierName($tableNames, ['test'], 'test');
 }