Skip to content
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

Prep work for enabling support for foreign keys on SQLite #9799

Merged
merged 1 commit into from
Jun 1, 2022
Merged

Prep work for enabling support for foreign keys on SQLite #9799

merged 1 commit into from
Jun 1, 2022

Conversation

morozov
Copy link
Member

@morozov morozov commented May 31, 2022

No description provided.

@@ -857,12 +856,9 @@ public function dropDatabase()
*/
public function getDropDatabaseSQL()
{
$schema = $this->schemaManager->createSchema();

$visitor = new DropSchemaSqlCollector($this->platform);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DropSchemaSqlCollector will be deprecated in favor of another class. It's better if the ORM doesn't depend on such low-level implementation details at all and uses the schema manager for managing schema.

$this->_em->getClassMetadata(CompanyManager::class),
]
);
self::assertCount(4, $sql);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQL that the DBAL uses for managing schema is an implementation detail that may and will change.

@@ -41,6 +42,11 @@ public function tearDown(): void
$sm->dropTable($platform->quoteIdentifier('TREE_INDEX'));
$sm->dropTable($platform->quoteIdentifier('INDEX'));
$sm->dropTable($platform->quoteIdentifier('LIKE'));

if ($platform instanceof PostgreSQLPlatform) {
Copy link
Member Author

@morozov morozov May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with this code is that the test suite ignores the exceptions thrown by the schema tool:

try {
$this->_schemaTool->createSchema(array_map(
function (string $className): ClassMetadata {
return $this->_em->getClassMetadata($className);
},
$models
));
} catch (ToolsException $e) {
}

...and relies on the fact that CreateSchemaSqlCollector creates all tables before all sequences.

Without this change, if each sequence is created after its corresponding table, for each test except for the first, the setUp() will fail to create the first sequence (because it already exists) and thus will not create all three tables.

We could implement a dropSchemaForModels() method similar to createSchemaForModels() and use it instead but on the DBAL versions prior to 3.4 it would use DropSchemaSqlCollector internally which attempts to drop foreign keys before dropping the table, even if it's not necessary, but SQLite doesn't support that. The smallest of all evils, for now, seems to work around it.

@@ -57,6 +57,11 @@ public function testNotInSync(): void

public function testNotInSyncVerbose(): void
{
$schemaManager = $this->createSchemaManager();
if ($schemaManager->tablesExist('cache_login')) {
Copy link
Member Author

@morozov morozov May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a mess. This test will fail if SQLite starts reporting that it supports foreign keys and if some other tests are executed before it (e.g. DDC2943Test). The cache_login table will already exist at this point and won't be part of the diff.

The test currently passes because even by the time when it's executed, the cache_login table already exists, its foreign key is not introspected, so the schema diff always contains a missing foreign key.

The proper solution here would be instead of deleting data from all tables in the functional test teardown, to drop those tables but the hard-coded list of tables is inconsistent with the models, so reworking it requires additional effort.

@morozov morozov marked this pull request as ready for review May 31, 2022 01:59
@morozov morozov requested review from derrabus and greg0ire May 31, 2022 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants