Commit 204c4c70 authored by Guilherme Blanco's avatar Guilherme Blanco

Segregated support of unique index and unique constraint. Added missing...

Segregated support of unique index and unique constraint. Added missing commits: 400d73c8a1e4f53459a877c8652811ee22c0913b, e91811cb3fe3101d7d8ac95c45f8bc1ba9bd913a, a4ecf053186b11bc31fbff79ef36248500383908, d7d1c397a35735383b34632d3a67bbc3a3371a45, c71b3ae0425e5c039b047825dbf8351a773e6785, 2f9da39ec645b54d08c95649c99d7b87a32bdc72 and 9aa4e79aab0477b4212b01d65de53193d9559e39
parent 655b6bfd
.idea
/.phpunit.result.cache
build/
logs/
......
......@@ -23,6 +23,7 @@ use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
......@@ -1550,15 +1551,30 @@ abstract class AbstractPlatform
$options['indexes'] = [];
$options['primary'] = [];
if (($createFlags&self::CREATE_INDEXES) > 0) {
if (($createFlags & self::CREATE_INDEXES) > 0) {
foreach ($table->getIndexes() as $index) {
/** @var $index Index */
if ($index->isPrimary()) {
$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
} else {
if (! $index->isPrimary()) {
$options['indexes'][$index->getQuotedName($this)] = $index;
continue;
}
$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
}
foreach ($table->getUniqueConstraints() as $uniqueConstraint) {
/** @var UniqueConstraint $uniqueConstraint */
$options['uniqueConstraints'][$uniqueConstraint->getQuotedName($this)] = $uniqueConstraint;
}
}
if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = [];
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
......@@ -1568,6 +1584,7 @@ abstract class AbstractPlatform
foreach ($table->getColumns() as $column) {
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
$columnSql = array_merge($columnSql, $eventArgs->getSql());
......@@ -1593,15 +1610,9 @@ abstract class AbstractPlatform
$columns[$columnData['name']] = $columnData;
}
if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) {
$options['foreignKeys'] = [];
foreach ($table->getForeignKeys() as $fkConstraint) {
$options['foreignKeys'][] = $fkConstraint;
}
}
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
if ($eventArgs->isDefaultPrevented()) {
......@@ -1614,6 +1625,7 @@ abstract class AbstractPlatform
if ($table->hasOption('comment')) {
$sql[] = $this->getCommentOnTableSQL($tableName, $table->getOption('comment'));
}
foreach ($table->getColumns() as $column) {
$comment = $this->getColumnComment($column);
......@@ -2365,25 +2377,33 @@ abstract class AbstractPlatform
* Obtains DBMS specific SQL code portion needed to set a unique
* constraint declaration to be used in statements like CREATE TABLE.
*
* @param string $name The name of the unique constraint.
* @param Index $index The index definition.
* @param string $name The name of the unique constraint.
* @param UniqueConstraint $constraint The unique constraint definition.
*
* @return string DBMS specific SQL code portion needed to set a constraint.
*
* @throws InvalidArgumentException
*/
public function getUniqueConstraintDeclarationSQL($name, Index $index)
public function getUniqueConstraintDeclarationSQL($name, UniqueConstraint $constraint)
{
$columns = $index->getColumns();
$columns = $constraint->getQuotedColumns($this);
$name = new Identifier($name);
if (count($columns) === 0) {
throw new InvalidArgumentException("Incomplete definition. 'columns' required.");
}
return 'CONSTRAINT ' . $name->getQuotedName($this) . ' UNIQUE ('
. $this->getIndexFieldDeclarationListSQL($index)
. ')' . $this->getPartialIndexSQL($index);
$flags = ['UNIQUE'];
if ($constraint->hasFlag('clustered')) {
$flags[] = 'CLUSTERED';
}
$constraintName = $name->getQuotedName($this);
$constraintName = ! empty($constraintName) ? $constraintName . ' ' : '';
$columnListNames = $this->getIndexFieldDeclarationListSQL($columns);
return sprintf('CONSTRAINT %s%s (%s)', $constraintName, implode(' ', $flags), $columnListNames);
}
/**
......@@ -2406,9 +2426,8 @@ abstract class AbstractPlatform
throw new InvalidArgumentException("Incomplete definition. 'columns' required.");
}
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this) . ' ('
. $this->getIndexFieldDeclarationListSQL($index)
. ')' . $this->getPartialIndexSQL($index);
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this)
. ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index);
}
/**
......@@ -3078,10 +3097,30 @@ abstract class AbstractPlatform
return false;
}
/**
* Gets the sequence name prefix based on table information.
*
* @param string $tableName
* @param string|null $schemaName
*
* @return string
*/
public function getSequencePrefix($tableName, $schemaName = null)
{
if ($schemaName === null) {
return $tableName;
}
// Prepend the schema name to the table name if there is one
return ! $this->supportsSchemas() && $this->canEmulateSchemas()
? $schemaName . '__' . $tableName
: $schemaName . '.' . $tableName;
}
/**
* Returns the name of the sequence for a particular identity column in a particular table.
*
* @see usesSequenceEmulatedIdentityColumns
* @see usesSequenceEmulatedIdentityColumns
*
* @param string $tableName The name of the table to return the sequence name for.
* @param string $columnName The name of the identity column in the table to return the sequence name for.
......
......@@ -423,15 +423,15 @@ SQL
$queryFields = $this->getColumnDeclarationListSQL($columns);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
foreach ($options['uniqueConstraints'] as $index => $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($index, $definition);
foreach ($options['uniqueConstraints'] as $name => $definition) {
$queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition);
}
}
// add all indexes
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $index => $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSQL($index, $definition);
foreach ($options['indexes'] as $name => $definition) {
$queryFields .= ', ' . $this->getIndexDeclarationSQL($name, $definition);
}
}
......@@ -761,9 +761,7 @@ SQL
continue;
}
foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) {
$column = $diff->fromTable->getColumn($columnName);
foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName => $column) {
// Check if an autoincrement column was dropped from the primary key.
if (! $column->getAutoincrement() || in_array($columnName, $changedIndex->getColumns(), true)) {
continue;
......
......@@ -380,11 +380,11 @@ class OraclePlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
protected function _getCreateTableSQL($table, array $columns, array $options = [])
protected function _getCreateTableSQL($tableName, array $columns, array $options = [])
{
$indexes = $options['indexes'] ?? [];
$options['indexes'] = [];
$sql = parent::_getCreateTableSQL($table, $columns, $options);
$sql = parent::_getCreateTableSQL($tableName, $columns, $options);
foreach ($columns as $name => $column) {
if (isset($column['sequence'])) {
......@@ -396,12 +396,12 @@ class OraclePlatform extends AbstractPlatform
continue;
}
$sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $table));
$sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $tableName));
}
if (isset($indexes) && ! empty($indexes)) {
foreach ($indexes as $index) {
$sql[] = $this->getCreateIndexSQL($index, $table);
$sql[] = $this->getCreateIndexSQL($index, $tableName);
}
}
......
......@@ -1166,27 +1166,6 @@ SQL
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
}
/**
* {@inheritdoc}
*/
public function getUniqueConstraintDeclarationSQL($name, Index $index)
{
if ($index->isPrimary()) {
throw new InvalidArgumentException(
'Cannot create primary key constraint declarations with getUniqueConstraintDeclarationSQL().'
);
}
if (! $index->isUnique()) {
throw new InvalidArgumentException(
'Can only create unique constraint declarations, no common index declarations with ' .
'getUniqueConstraintDeclarationSQL().'
);
}
return $this->getTableConstraintDeclarationSQL($index, $name);
}
/**
* {@inheritdoc}
*/
......
......@@ -458,18 +458,6 @@ SQL
' FOR ' . $columnName->getQuotedName($this);
}
/**
* {@inheritDoc}
*/
public function getUniqueConstraintDeclarationSQL($name, Index $index)
{
$constraint = parent::getUniqueConstraintDeclarationSQL($name, $index);
$constraint = $this->_appendUniqueConstraintDefinition($constraint, $index);
return $constraint;
}
/**
* {@inheritDoc}
*/
......
......@@ -319,9 +319,9 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritDoc}
*/
protected function _getCreateTableSQL($name, array $columns, array $options = [])
protected function _getCreateTableSQL($tableName, array $columns, array $options = [])
{
$name = str_replace('.', '__', $name);
$tableName = str_replace('.', '__', $tableName);
$queryFields = $this->getColumnDeclarationListSQL($columns);
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) {
......@@ -345,7 +345,7 @@ class SqlitePlatform extends AbstractPlatform
$tableComment = $this->getInlineTableCommentSQL($comment);
}
$query = ['CREATE TABLE ' . $name . ' ' . $tableComment . '(' . $queryFields . ')'];
$query = ['CREATE TABLE ' . $tableName . ' ' . $tableComment . '(' . $queryFields . ')'];
if (isset($options['alter']) && $options['alter'] === true) {
return $query;
......@@ -353,13 +353,13 @@ class SqlitePlatform extends AbstractPlatform
if (isset($options['indexes']) && ! empty($options['indexes'])) {
foreach ($options['indexes'] as $indexDef) {
$query[] = $this->getCreateIndexSQL($indexDef, $name);
$query[] = $this->getCreateIndexSQL($indexDef, $tableName);
}
}
if (isset($options['unique']) && ! empty($options['unique'])) {
foreach ($options['unique'] as $indexDef) {
$query[] = $this->getCreateIndexSQL($indexDef, $name);
$query[] = $this->getCreateIndexSQL($indexDef, $tableName);
}
}
......@@ -394,7 +394,8 @@ class SqlitePlatform extends AbstractPlatform
*/
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed)
{
return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)')
return $fixed
? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length > 0 ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
......@@ -924,7 +925,7 @@ class SqlitePlatform extends AbstractPlatform
if (! $this->onSchemaAlterTable($diff, $tableSql)) {
$dataTable = new Table('__temp__' . $table->getName());
$newTable = new Table($table->getQuotedName($this), $columns, $this->getPrimaryIndexInAlteredTable($diff), $this->getForeignKeysInAlteredTable($diff), 0, $table->getOptions());
$newTable = new Table($table->getQuotedName($this), $columns, $this->getPrimaryIndexInAlteredTable($diff), [], $this->getForeignKeysInAlteredTable($diff), $table->getOptions());
$newTable->addOption('alter', true);
$sql = $this->getPreAlterTableIndexForeignKeySQL($diff);
......
......@@ -48,11 +48,13 @@ abstract class AbstractAsset
$this->_quoted = true;
$name = $this->trimQuotes($name);
}
if (strpos($name, '.') !== false) {
$parts = explode('.', $name);
$this->_namespace = $parts[0];
$name = $parts[1];
}
$this->_name = $name;
}
......
......@@ -269,12 +269,14 @@ abstract class AbstractSchemaManager
{
$columns = $this->listTableColumns($tableName);
$foreignKeys = [];
if ($this->_platform->supportsForeignKeyConstraints()) {
$foreignKeys = $this->listTableForeignKeys($tableName);
}
$indexes = $this->listTableIndexes($tableName);
return new Table($tableName, $columns, $indexes, $foreignKeys);
return new Table($tableName, $columns, $indexes, [], $foreignKeys);
}
/**
......
......@@ -10,7 +10,6 @@ use function array_map;
use function array_search;
use function array_shift;
use function count;
use function is_string;
use function strtolower;
class Index extends AbstractAsset implements Constraint
......@@ -58,6 +57,7 @@ class Index extends AbstractAsset implements Constraint
$isUnique = $isUnique || $isPrimary;
$this->_setName($indexName);
$this->_isUnique = $isUnique;
$this->_isPrimary = $isPrimary;
$this->options = $options;
......@@ -65,24 +65,19 @@ class Index extends AbstractAsset implements Constraint
foreach ($columns as $column) {
$this->_addColumn($column);
}
foreach ($flags as $flag) {
$this->addFlag($flag);
}
}
/**
* @param string $column
*
* @return void
*
* @throws InvalidArgumentException
*/
protected function _addColumn($column)
protected function _addColumn(string $column)
{
if (! is_string($column)) {
throw new InvalidArgumentException('Expecting a string as Index Column');
}
$this->_columns[$column] = new Identifier($column);
}
......
......@@ -21,7 +21,8 @@ class SchemaException extends DBALException
public const SEQUENCE_ALREADY_EXISTS = 80;
public const INDEX_INVALID_NAME = 90;
public const FOREIGNKEY_DOESNT_EXIST = 100;
public const NAMESPACE_ALREADY_EXISTS = 110;
public const CONSTRAINT_DOESNT_EXIST = 110;
public const NAMESPACE_ALREADY_EXISTS = 120;
/**
* @param string $tableName
......@@ -145,6 +146,20 @@ class SchemaException extends DBALException
return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST);
}
/**
* @param string $constraintName
* @param string $table
*
* @return \Doctrine\DBAL\Schema\SchemaException
*/
public static function uniqueConstraintDoesNotExist($constraintName, $table)
{
return new self(
sprintf("There exists no unique constraint with the name '%s' on table '%s'.", $constraintName, $table),
self::CONSTRAINT_DOESNT_EXIST
);
}
/**
* @param string $fkName
* @param string $table
......
This diff is collapsed.
<?php
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function array_keys;
use function array_map;
use function strtolower;
/**
* Class for a unique constraint.
*/
class UniqueConstraint extends AbstractAsset implements Constraint
{
/**
* Asset identifier instances of the column names the unique constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
*/
protected $columns = [];
/**
* Platform specific flags.
* array($flagName => true)
*
* @var true[]
*/
protected $flags = [];
/**
* Platform specific options.
*
* @var mixed[]
*/
private $options = [];
/**
* @param string $indexName
* @param string[] $columns
* @param string[] $flags
* @param mixed[] $options
*/
public function __construct($indexName, array $columns, array $flags = [], array $options = [])
{
$this->_setName($indexName);
$this->options = $options;
foreach ($columns as $column) {
$this->_addColumn($column);
}
foreach ($flags as $flag) {
$this->addFlag($flag);
}
}
/**
* {@inheritdoc}
*/
public function getColumns()
{
return array_keys($this->columns);
}
/**
* {@inheritdoc}
*/
public function getQuotedColumns(AbstractPlatform $platform)
{
$columns = [];
foreach ($this->columns as $column) {
$columns[] = $column->getQuotedName($platform);
}
return $columns;
}
/**
* @return string[]
*/
public function getUnquotedColumns()
{
return array_map([$this, 'trimQuotes'], $this->getColumns());
}
/**
* Returns platform specific flags for unique constraint.
*
* @return string[]
*/
public function getFlags()
{
return array_keys($this->flags);
}
/**
* Adds flag for a unique constraint that translates to platform specific handling.
*
* @param string $flag
*
* @return self
*
* @example $uniqueConstraint->addFlag('CLUSTERED')
*/
public function addFlag($flag)
{
$this->flags[strtolower($flag)] = true;
return $this;
}
/**
* Does this unique constraint have a specific flag?
*
* @param string $flag
*
* @return bool
*/
public function hasFlag($flag)
{
return isset($this->flags[strtolower($flag)]);
}
/**
* Removes a flag.
*
* @param string $flag
*
* @return void
*/
public function removeFlag($flag)
{
unset($this->flags[strtolower($flag)]);
}
/**
* @param string $name
*
* @return bool
*/
public function hasOption($name)
{
return isset($this->options[strtolower($name)]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getOption($name)
{
return $this->options[strtolower($name)];
}
/**
* @return mixed[]
*/
public function getOptions()
{
return $this->options;
}
/**
* @return void
*/
protected function _addColumn(string $column)
{
$this->columns[$column] = new Identifier($column);
}
}
......@@ -19,6 +19,7 @@ use function assert;
use function chmod;
use function exec;
use function file_exists;
use function in_array;
use function posix_geteuid;
use function posix_getpwuid;
use function sprintf;
......@@ -300,7 +301,7 @@ class ExceptionTest extends FunctionalTestCase
}
// mode 0 is considered read-only on Windows
$mode = PHP_OS === 'Linux' ? 0444 : 0000;
$mode = in_array(PHP_OS, ['Linux', 'Darwin']) ? 0444 : 0000;
$filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_' . $mode . '.db');
......
......@@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use function count;
final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends FunctionalTestCase
{
......@@ -60,7 +61,8 @@ final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends FunctionalTestCa
self::assertTrue($validationTable->hasColumn('new_id'));
self::assertTrue($validationTable->getColumn('new_id')->getAutoincrement());
self::assertTrue($validationTable->hasPrimaryKey());
self::assertSame(['new_id'], $validationTable->getPrimaryKeyColumns());
self::assertEquals(1, count($validationTable->getPrimaryKeyColumns()));
self::assertArrayHasKey('new_id', $validationTable->getPrimaryKeyColumns());
}
private function getPlatform() : AbstractPlatform
......
......@@ -46,8 +46,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$primaryKey = $table->getPrimaryKeyColumns();
self::assertCount(2, $primaryKey);
self::assertContains('bar_id', $primaryKey);
self::assertContains('foo_id', $primaryKey);
self::assertArrayHasKey('bar_id', $primaryKey);
self::assertArrayHasKey('foo_id', $primaryKey);
}
public function testDiffTableBug() : void
......
......@@ -980,7 +980,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
*/
protected function getTestTable(string $name, array $options = []) : Table
{
$table = new Table($name, [], [], [], false, $options);
$table = new Table($name, [], [], [], [], $options);
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table->addColumn('id', 'integer', ['notnull' => true]);
$table->setPrimaryKey(['id']);
......@@ -992,7 +992,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
protected function getTestCompositeTable(string $name) : Table
{
$table = new Table($name, [], [], [], false, []);
$table = new Table($name, [], [], [], [], []);
$table->setSchemaConfig($this->schemaManager->createSchemaConfig());
$table->addColumn('id', 'integer', ['notnull' => true]);
$table->addColumn('other_id', 'integer', ['notnull' => true]);
......
......@@ -14,6 +14,7 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\Types\Type;
use PHPUnit\Framework\TestCase;
use function get_class;
......@@ -213,9 +214,9 @@ abstract class AbstractPlatformTestCase extends TestCase
public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() : void
{
$where = 'test IS NULL AND test2 IS NOT NULL';
$indexDef = new Index('name', ['test', 'test2'], false, false, [], ['where' => $where]);
$uniqueIndex = new Index('name', ['test', 'test2'], true, false, [], ['where' => $where]);
$where = 'test IS NULL AND test2 IS NOT NULL';
$indexDef = new Index('name', ['test', 'test2'], false, false, [], ['where' => $where]);
$uniqueConstraint = new UniqueConstraint('name', ['test', 'test2'], [], []);
$expected = ' WHERE ' . $where;
......@@ -225,14 +226,16 @@ abstract class AbstractPlatformTestCase extends TestCase
$actuals[] = $this->platform->getIndexDeclarationSQL('name', $indexDef);
}
$actuals[] = $this->platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex);
$actuals[] = $this->platform->getCreateIndexSQL($indexDef, 'table');
$uniqueConstraintSQL = $this->platform->getUniqueConstraintDeclarationSQL('name', $uniqueConstraint);
$indexSQL = $this->platform->getCreateIndexSQL($indexDef, 'table');
$this->assertStringEndsNotWith($expected, $uniqueConstraintSQL, 'WHERE clause should NOT be present');
foreach ($actuals as $actual) {
if ($this->platform->supportsPartialIndexes()) {
self::assertStringEndsWith($expected, $actual, 'WHERE clause should be present');
self::assertStringEndsWith($expected, $indexSQL, 'WHERE clause should be present');
} else {
self::assertStringEndsNotWith($expected, $actual, 'WHERE clause should NOT be present');
self::assertStringEndsNotWith($expected, $indexSQL, 'WHERE clause should NOT be present');
}
}
}
......@@ -726,11 +729,11 @@ abstract class AbstractPlatformTestCase extends TestCase
*/
public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : void
{
$index = new Index('select', ['foo'], true);
$constraint = new UniqueConstraint('select', ['foo'], [], []);
self::assertSame(
$this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(),
$this->platform->getUniqueConstraintDeclarationSQL('select', $index)
$this->platform->getUniqueConstraintDeclarationSQL('select', $constraint)
);
}
......
......@@ -1388,7 +1388,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string
{
return 'CONSTRAINT [select] UNIQUE (foo) WHERE foo IS NOT NULL';
return 'CONSTRAINT [select] UNIQUE (foo)';
}
/**
......
......@@ -16,6 +16,7 @@ use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\Schema\UniqueConstraint;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type;
use InvalidArgumentException;
......@@ -377,6 +378,7 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
'foo'
)
);
self::assertEquals(
'ALTER TABLE foo ADD PRIMARY KEY (a, b)',
$this->platform->getCreatePrimaryKeySQL(
......@@ -392,12 +394,13 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)',
$this->platform->getUniqueConstraintDeclarationSQL(
'unique_constraint',
new Index(null, ['a', 'b'], true, false, ['clustered'])
new UniqueConstraint(null, ['a', 'b'], ['clustered'])
)
);
self::assertEquals(
'UNIQUE (a, b)',
$this->platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false))
'CONSTRAINT UNIQUE (a, b)',
$this->platform->getUniqueConstraintDeclarationSQL(null, new UniqueConstraint(null, ['a', 'b']))
);
}
......@@ -405,7 +408,7 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
{
$this->expectException(InvalidArgumentException::class);
$this->platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true));
$this->platform->getUniqueConstraintDeclarationSQL('constr', new UniqueConstraint('constr', []));
}
public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() : void
......
......@@ -1295,6 +1295,7 @@ class ComparatorTest extends TestCase
'id_table1' => new Column('id_table1', Type::getType('integer')),
],
[],
[],
[
new ForeignKeyConstraint(['id_table1'], 'table1', ['id'], 'fk_table2_table1'),
]
......@@ -1308,6 +1309,7 @@ class ComparatorTest extends TestCase
'id_table3' => new Column('id_table3', Type::getType('integer')),
],
[],
[],
[
new ForeignKeyConstraint(['id_table3'], 'table3', ['id'], 'fk_table2_table3'),
]
......@@ -1320,6 +1322,7 @@ class ComparatorTest extends TestCase
),
]);
$actual = Comparator::compareSchemas($fromSchema, $toSchema);
self::assertArrayHasKey('table2', $actual->changedTables);
self::assertCount(1, $actual->orphanedForeignKeys);
self::assertEquals('fk_table2_table1', $actual->orphanedForeignKeys[0]->getName());
......
......@@ -26,7 +26,7 @@ class TableTest extends TestCase
public function testGetName() : void
{
$table = new Table('foo', [], [], []);
$table = new Table('foo', [], [], [], []);
self::assertEquals('foo', $table->getName());
}
......@@ -166,7 +166,7 @@ class TableTest extends TestCase
{
$this->expectException(SchemaException::class);
$table = new Table('foo', [], [], []);
$table = new Table('foo', [], [], [], []);
$table->getIndex('unknownIndex');
}
......@@ -180,7 +180,7 @@ class TableTest extends TestCase
new Index('the_primary', ['foo'], true, true),
new Index('other_primary', ['bar'], true, true),
];
$table = new Table('foo', $columns, $indexes, []);
$table = new Table('foo', $columns, $indexes, [], []);
}
public function testAddTwoIndexesWithSameNameThrowsException() : void
......@@ -193,14 +193,14 @@ class TableTest extends TestCase
new Index('an_idx', ['foo'], false, false),
new Index('an_idx', ['bar'], false, false),
];
$table = new Table('foo', $columns, $indexes, []);
$table = new Table('foo', $columns, $indexes, [], []);
}
public function testConstraints() : void
{
$constraint = new ForeignKeyConstraint([], 'foo', []);
$tableA = new Table('foo', [], [], [$constraint]);
$tableA = new Table('foo', [], [], [], [$constraint]);
$constraints = $tableA->getForeignKeys();
self::assertCount(1, $constraints);
......@@ -209,7 +209,7 @@ class TableTest extends TestCase
public function testOptions() : void
{
$table = new Table('foo', [], [], [], false, ['foo' => 'bar']);
$table = new Table('foo', [], [], [], [], ['foo' => 'bar']);
self::assertTrue($table->hasOption('foo'));
self::assertEquals('bar', $table->getOption('foo'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment