-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The changes from #3392 break indexes with a fixed length #3409
Comments
@leofeyer could you clarify why you're using this syntax for fixed length indices? AFAIK, the support for such indices was only added in dbal/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php Lines 1565 to 1569 in e37fc54
The first argument contains column names, the last contains the lenghts which is sufficient to define the index. |
We have been using it since Doctrine DBAL 2.6, however, you are right about the $table = new Table('test');
$table->addColumn('path', 'text');
$table->addIndex(['path' => 'path(768)'], 'path'); |
@leofeyer it doesn't look like valid usage to me. The first argument of |
Ok, then please tell me how to achieve the following data structure: Because this is exactly what And it cannot be created like this either: $table->addIndex(['path(768)'], 'path', [], ['lengths' => [768]]); So how do I accomplish it? |
@leofeyer does the approach covered in #3409 (comment) work for you? |
No, it does not, because it does not set the correct column name. The column name needs to be Create schema from databaseCREATE TABLE test (path text NULL);
CREATE INDEX path ON test (path(768)); $connection = $this->get('database_connection'); // Symfony DI container
dump($connection->getSchemaManager()->createSchema()->getTable('test')); Create schema manually$table = new Table('test');
$table->addColumn('path', 'text');
$table->addIndex(['path'], 'path', [], ['lengths' => [768]]);
dump($table); And because of this difference, Another possible solutionMaybe |
It should be the opposite. When a table is created from its definition by the DBAL, the SQL looks like: CREATE TABLE index_length (
path TEXT NULL,
INDEX IDX_18E36143B548B0F (path(768))
) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB and the introspection works correctly (the following test passes): public function testIndexLength()
{
$table = new Table('index_length');
$table->addColumn('path', 'text');
$table->addIndex(['path'], null, [], ['lengths' => [768]]);
$this->schemaManager->dropAndCreateTable($table);
$indexes = $this->schemaManager->listTableIndexes('index_length');
self::assertCount(1, $indexes);
$index = array_shift($indexes);
self::assertEquals(['path'], $index->getColumns());
self::assertEquals([768], $index->getOption('lengths'));
} It also passes with your syntax: public function testIndexLength()
{
$this->schemaManager->tryMethod('dropTable', 'index_length');
$this->connection->exec('CREATE TABLE index_length (path text NULL)');
$this->connection->exec('CREATE INDEX path ON index_length (path(768))');
$indexes = $this->schemaManager->listTableIndexes('index_length');
self::assertCount(1, $indexes);
$index = array_shift($indexes);
self::assertEquals(['path'], $index->getColumns());
self::assertEquals([768], $index->getOption('lengths'));
} In both cases, the index is introspected correctly as having one column |
Either way, @beberlei @Ocramius Maybe you can take a look at this issue as well? I have already provided code samples and screenshots in #3409 (comment) and I don't know how to better explain it. It seems we are stuck here. 🙈 |
Ok, will do tomorrow. |
So here is the failing test: public function testUpdatesIndexLength()
{
$this->connection->exec('CREATE TABLE index_length (path text NULL)');
$this->connection->exec('CREATE INDEX path ON index_length (path(333))');
$table = new Table('index_length');
$table->addColumn('path', 'text', ['notnull' => false]);
$table->addIndex(['path'], 'path', [], ['lengths' => [768]]);
$fromSchema = $this->connection->getSchemaManager()->createSchema();
$toSchema = new Schema([$table]);
$diff = $fromSchema->getMigrateToSql($toSchema, $this->connection->getDatabasePlatform());
self::assertContains('ALTER TABLE index_length DROP INDEX path, ADD INDEX path (path(768))', $diff);
} |
Can you please send that in a PR? That would basically restart the issue from a fresh/solid ground 👍 |
Sure, if you tell me in which class the test belongs. |
@leofeyer thank you for the test. I'll figure out first what exactly is broken and then we'll see where the test belongs. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
BC Break Report
Summary
The changes from #3392 break indexes with a fixed length.
Previous behaviour
This added the following index:
Current behavior
The exception seems to occur due to the removal of the following lines in the
Table::_createIndex()
method:The text was updated successfully, but these errors were encountered: