Ignore SQLite indexes with reserved names

These are internal, automatically-created and shouldn't be considered part of
the schema. They cannot be recreated because of their reserved names.
parent ced12abf
...@@ -93,18 +93,21 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -93,18 +93,21 @@ class SqliteSchemaManager extends AbstractSchemaManager
// fetch regular indexes // fetch regular indexes
foreach($tableIndexes AS $tableIndex) { foreach($tableIndexes AS $tableIndex) {
$keyName = $tableIndex['name']; // Ignore indexes with reserved names, e.g. autoindexes
$idx = array(); if (strpos($tableIndex['name'], 'sqlite_') !== 0) {
$idx['key_name'] = $keyName; $keyName = $tableIndex['name'];
$idx['primary'] = false; $idx = array();
$idx['non_unique'] = $tableIndex['unique']?false:true; $idx['key_name'] = $keyName;
$idx['primary'] = false;
$stmt = $this->_conn->executeQuery( "PRAGMA INDEX_INFO ( '{$keyName}' )" ); $idx['non_unique'] = $tableIndex['unique']?false:true;
$indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt = $this->_conn->executeQuery( "PRAGMA INDEX_INFO ( '{$keyName}' )" );
foreach ( $indexArray as $indexColumnRow ) { $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$idx['column_name'] = $indexColumnRow['name'];
$indexBuffer[] = $idx; foreach ( $indexArray as $indexColumnRow ) {
$idx['column_name'] = $indexColumnRow['name'];
$indexBuffer[] = $idx;
}
} }
} }
......
...@@ -199,7 +199,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -199,7 +199,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertEquals(3, count($tableIndexes)); $this->assertEquals(3, count($tableIndexes));
$this->assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); $this->assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.');
$this->assertEquals(array('id'), array_map('strtolower', $tableIndexes['primary']->getColumns())); $this->assertEquals(array('id', 'other_id'), array_map('strtolower', $tableIndexes['primary']->getColumns()));
$this->assertTrue($tableIndexes['primary']->isUnique()); $this->assertTrue($tableIndexes['primary']->isUnique());
$this->assertTrue($tableIndexes['primary']->isPrimary()); $this->assertTrue($tableIndexes['primary']->isPrimary());
...@@ -505,7 +505,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -505,7 +505,8 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options); $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options);
$table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('id', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id')); $table->addColumn('other_id', 'integer', array('notnull' => true));
$table->setPrimaryKey(array('id', 'other_id'));
$table->addColumn('test', 'string', array('length' => 255)); $table->addColumn('test', 'string', array('length' => 255));
$table->addColumn('foreign_key_test', 'integer'); $table->addColumn('foreign_key_test', 'integer');
return $table; return $table;
......
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