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

Schema cache fixes #14073

Merged
merged 8 commits into from
May 2, 2017
Merged

Schema cache fixes #14073

merged 8 commits into from
May 2, 2017

Conversation

brandonkelly
Copy link
Contributor

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes
Fixed issues #14072


$db->createCommand()->addColumn($tableName, 'value', 'integer')->execute();
$newSchema = $db->getSchema()->getTableSchema($tableName);
$this->assertNotEquals($initialSchema, $newSchema);

$db->createCommand()->addForeignKey($fkName, $tableName, 'fk', $tableName, 'id')->execute();
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: 237af91

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry if I mislead you by pointing to markTestSkipped() method without futher explanations.
With this method ALL test method will be skipped, and it's not so correct now 'cause addColumn(), for instance, works perfect with sqlite, but also will not be tested.
markTestSkipped() is applicable if we'll split this method to several ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MysteryDragon What do you recommend? Should I split testAutoRefreshTableSchema into multiple tests (which would require re-building the table multiple times), or just skip the FK command + assertion if running SQLite?

Copy link
Contributor

Choose a reason for hiding this comment

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

@brandonkelly IMO the first option is more "theoretically correct", but I would prefer the second one due to simplicity and efficiency. I can imagine some other options, but they also have their disadvantages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MysteryDragon Alright, done: 11c0d4b (skipped the column comment things too, since sqlite doesn’t support that either).


$db->createCommand()->addColumn($tableName, 'value', 'integer')->execute();
$newSchema = $db->getSchema()->getTableSchema($tableName);
$this->assertNotEquals($initialSchema, $newSchema);

if ($this->driverName === 'sqlite') {
Copy link
Contributor

Choose a reason for hiding this comment

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

@brandonkelly I think you mean !== here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doh! Sorry about that.

@@ -537,7 +537,7 @@ public function createTable($table, $columns, $options = null)
{
$sql = $this->db->getQueryBuilder()->createTable($table, $columns, $options);

return $this->setSql($sql);
return $this->setSql($sql)->requireTableSchemaRefresh($table);
Copy link
Member

Choose a reason for hiding this comment

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

If the table is just created, there should be no past cache so it makes no sense to refresh it.

Copy link
Member

Choose a reason for hiding this comment

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

Schema caches also negative results, i.e. a non existing table will cache a null value:

return $this->_tables[$name] = $this->loadTableSchema($realName);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, as demonstrated in #14072

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@samdark Also this PR comes with a couple new test assertions that will demonstrate the issue. If this change is removed, this will fail:

https://github.com/yiisoft/yii2/pull/14073/files#diff-e48002914d2773120698a96387ecabd2R822

Copy link
Member

Choose a reason for hiding this comment

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

👍

@samdark samdark self-assigned this Apr 30, 2017
@samdark samdark merged commit 7b2df55 into yiisoft:master May 2, 2017
@samdark
Copy link
Member

samdark commented May 2, 2017

Merged. Thank you!

@brandonkelly brandonkelly deleted the schema-cache-fixes branch February 11, 2018 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants