Repository navigation
[8.x] SqlServer schema fixes - #32957
joelharkes wants to merge 5 commits into
Conversation
- fix hasTable and hasColumn uses schema or uses user default schema (just like sql would) - fix dropping default constraints only on table in right schema.
|
Contribution guide says styleCI will be automatically fixed, is that true if not how can i fix it? |
|
@joelharkes only on this repo, not on forks. It'll be automatically fixed when it's merged. |
|
@staudenmeir your review on this would be appreciated :) |
|
@joelharkes Thx for this PR. |
|
If this is a bug fix PR, it should probably target 6.x, not 8.x. |
|
@GrahamCampbell it does also slightly change behavior. say: user default schema: before: $schema->hasTable('users') === true;
$schema->hasTable('dbo.users') === false;
$schema->hasTable('test.users') === false; now: $schema->hasTable('users') === false;
$schema->hasTable('dbo.users') === true;
$schema->hasTable('test.users') === false; It might be unexpected change so probably better to take it along a new bumped version. also in this case hasTable() and hasColumn() will only check tables within this schema |
|
What exactly are the breaking changes here? How likely are the to effect the average Laravel application using SQL Server? |
|
After this PR: Before: you can consider it as a bug or change of behaviour. in Sql server its possible to have same table names in different schema's so |
|
The second time I ran the command it worked fine. |
| $connection->insert($sql, $values); | ||
|
|
||
| if ($connection->getConfig('odbc') === true) { | ||
| $id = $this->processInsertGetIdForOdbc($connection); |
There was a problem hiding this comment.
This method is now no longer needed? This doesn't break anything?
There was a problem hiding this comment.
Yea i'm pretty sure my solution will work for ODBC too but i havent tested it.
There was a problem hiding this comment.
Is there someone who can test this?
| on obj.schema_id = schem.schema_id | ||
| where obj.type = 'U' | ||
| and obj.name = ? | ||
| and schem.name = "; // schema concatenated by builder. |
There was a problem hiding this comment.
What does this comment mean? Where does this happen?
There was a problem hiding this comment.
In the processor. found not better way todo this since if default schema should be used parameter is not possble (needs to user sql method)
There was a problem hiding this comment.
if no schema is provided SCHEMA_NAME() constant/sql server method is used, this cannot be parameterized.
would be nice if this compile method could just return a string + array of bindings but that is not how the interface is setup.
There was a problem hiding this comment.
Where in the processor? What file and line number? Please be VERY specific and detailed.
| } | ||
| if(!$table instanceof Blueprint){ | ||
| // fix infinite loop when $tablePrefix = 'schema.'; | ||
| return $this->wrapValue($table); |
There was a problem hiding this comment.
Why would there be an infinite loop?
There was a problem hiding this comment.
I had infinte loop while unit testing.
every time it concatenates the schema. prefix
and then in wrapSegment() it splits on the dot. if it has 2 or more segments it will call wrapTable() method and thus the loop starts over again. => you can test by removing this line and running docker compose
There was a problem hiding this comment.
example exception my tests threw before adding this part:
Error : Maximum function nesting level of '256' reached, aborting!
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:173
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:38
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:216
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\SqlServerGrammar.php:891
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:99
E:\git\laravel-framework\src\Illuminate\Collections\Collection.php:656
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:101
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:65
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:230
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:39
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:216
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\SqlServerGrammar.php:891
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:99
E:\git\laravel-framework\src\Illuminate\Collections\Collection.php:656
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:101
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:65
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:230
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:39
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:216
E:\git\laravel-framework\src\Illuminate\Database\Schema\Grammars\SqlServerGrammar.php:891
E:\git\laravel-framework\src\Illuminate\Database\Grammar.php:99
There was a problem hiding this comment.
current setup does not allow x. prefix it will fall in wrapSegments() funciton thinking the first part is the table second part is column. the first table part will 'again' be prefixed and thus the loop.
There was a problem hiding this comment.
I still have no idea what we are talking about to be honest. It feels like we are hacking around some deeper issue. Please try explain why this happens very clearly with a walk through of the code with screenshots.
| public function parseSchemaAndTable($table){ | ||
| $parts = explode(".", $table); | ||
| if(count($parts) == 1){ | ||
| return [null, $parts[0]]; // expect dbo as default schema as it is in sql server |
There was a problem hiding this comment.
What does this comment mean? "dbo" appears nowhere near this code.
There was a problem hiding this comment.
yes sorry, comment should be removed. it is outdated from older code where it depended on dbo as default schema
|
Thanks for all your feedback guys i will update the PR shortly, anything else i should be checking? |
|
Can you make sure the tests run when |
|
Thx a lot @joelharkes for this PR |
|
i would disadvise against it, or is it ok if I add the following at the end of i will not be able to integrate in your existing setup:
also it would slow down your process. the sql server tests are relatively slow. are you ok with that? |
|
Why do we need the extra compose file? |
|
It doesn't matter if that test script is slow. It's purpose is to test everything. Most of the time it won't be run, just the standard phpunit run. We need that test script to genuinely test everything. |
|
@GrahamCampbell couldnt put test in same docker-compose file because the same i can try to make it work and hack my tests to depend on alternative env variables if preferred? I also preferred my setup so i could easily run also the tests in docker-compose and not need a separate test.sh script for this. what do you think? |
|
I Have an addtional issue: Happens when:
How to solve:
problem: Would need to build sqlserver specific login in the RelationShip class. to chunk by 2000 results when id column is a string. How to best solve this? |
|
I'm not sure we should worry about working around that at the moment. It's a SQL Server limitation apparently. |
Can you update the tests to avoid that? It definitely can be done. |
| if ($table instanceof Blueprint && $table->temporary) { | ||
| $this->setTablePrefix('#'); | ||
| } | ||
| if(!$table instanceof Blueprint){ |
There was a problem hiding this comment.
Remove double space here after $table
|
Haven't heard from PR submitter in a couple weeks. Closing pending inactivity. Anyone can feel free to pick this up if they want and resubmit. |

Fixes #32883 #31229
summary
Run sql server based unit integration tests (only docker required), can be added to CI easily:
open questions: