-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Schema cache fixes #14073
Conversation
brandonkelly
commented
Apr 27, 2017
Q | A |
---|---|
Is bugfix? | yes |
New feature? | no |
Breaks BC? | no |
Tests pass? | yes |
Fixed issues | #14072 |
tests/framework/db/CommandTest.php
Outdated
|
||
$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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://travis-ci.org/yiisoft/yii2/jobs/226569561#L325
I think some tests is better to mark skipped for some particular DBMS (like https://github.com/yiisoft/yii2/blob/master/tests/framework/db/CommandTest.php#L561)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: 237af91
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
tests/framework/db/CommandTest.php
Outdated
|
||
$db->createCommand()->addColumn($tableName, 'value', 'integer')->execute(); | ||
$newSchema = $db->getSchema()->getTableSchema($tableName); | ||
$this->assertNotEquals($initialSchema, $newSchema); | ||
|
||
if ($this->driverName === 'sqlite') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
Line 152 in 533da62
return $this->_tables[$name] = $this->loadTableSchema($realName); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Merged. Thank you! |