Fix hasTable() returning stale results when mixing API and execute()#982
Merged
Fix hasTable() returning stale results when mixing API and execute()#982
Conversation
When a table was created via the API (e.g. $this->table()->create()) and then dropped via execute() (raw SQL), hasTable() would incorrectly return true because it checked an internal cache before querying the database. This fix limits the cache usage to dry-run mode only, where it's necessary to track what tables "would" exist. In normal mode, hasTable() now always queries the database to ensure accurate results. Also fixes SqlserverAdapter to pass the table name without schema prefix to the dialect, which was a latent bug hidden by the cache.
bb2a48f to
d9dfd8c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hasTable()returning stale results when mixing API calls with raw SQL viaexecute()$this->table()->create()) and dropped viaexecute(),hasTable()would incorrectly returntruedue to an internal cacheProblem
The
$createdTablescache was being checked first inhasTable(), returningtruewithout querying the database.Solution
Only use the cache in dry-run mode. In normal execution, always query the database for accurate results.
Note:
There was also a 2nd issue in code.
The issue was a latent bug in SqlserverAdapter - it was passing the full nschema.ntable to dialect->hasTable() instead of just ntable. The cache was hiding this bug before.