[5.5] Better temporary tables support #22110
Merged
+71
−0
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.
Proposal
Currently we have true temporary tables support for MySQL, PostgreSQL and SQLite. They're using the same
CREATE TEMPORARY TABLE
syntax based on SQL-92 standard although none of them follow it strictly - they're just vendor implementations. SQL Server temporary tables can be manually created by prefixing them with a single number sign#
for local temporary tables and a double number sign##
for global temporary tables - so presently we could be using the existing$table->setTablePrefix()
method to create temporary tables in SQL Server.Though it does support temporary tables, using
$table->temporary();
will be a no-op command when using SQL Server. I'm proposing that we start matching the developer expectation by creating temporary tables as requested. Since SQL Server have support for both local and global temporary tables and all other databases have support for local temporary tables only, it seems reasonable to follow their behavior.Implementation
We'll be just overloading
Illuminate\Database\Schema\Grammars\SqlServerGrammar->wrapTable()
method to honor the$table->temporary
option and call theSqlServerGrammar->setTablePrefix()
method to prefix the table with a single number sign. It's being changed here because any method that create/modify/drop the table would need the prefixed table name.Changes
I'm targeting this to 5.5 because it's an unsupported feature for SQL Server users - Laravel would allow you to use
$table->temporary();
no matter what but it will be a no-op command. Implementing this in 5.5 would just match the usage expectation for those who were using it albeit being unsupported. I can however quickly promote it to 5.6 if prompted.Code
Illuminate\Database\Schema\Grammars\SqlServerGrammar
wrapTable()
method overloading to prefix the table name.Tests
4 new tests and 8 new assertions
Illuminate\Tests\Database\DatabaseMySqlSchemaGrammarTest
Illuminate\Tests\Database\DatabasePostgresSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSQLiteSchemaGrammarTest
Illuminate\Tests\Database\DatabaseSqlServerSchemaGrammarTest
testCreateTemporaryTable()
method.