-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fix column modifying on columnstore tables #88
Merged
AdalbertMemSQL
merged 13 commits into
singlestore-labs:main
from
hafezdivandari:fix-column-modfiying
Jul 24, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2d6377f
fix column modifying on columnstore tables
hafezdivandari 2b46fec
fix tests
hafezdivandari 9777d8a
test for lower Laravel versions with Doctrine DBAL
hafezdivandari 406c6be
doctrine/dbal required for testing
hafezdivandari 12ce39b
force native schema operations
hafezdivandari ee302ad
fix doctrine dependency on lower PHP
hafezdivandari 79bcb9f
revert doctrine
hafezdivandari 509b578
fix tests
hafezdivandari 21f40a4
fix tests
hafezdivandari ebd21e1
revert changes on composer.json
hafezdivandari 9dc247c
remove redundant setup/teardown
hafezdivandari e84580e
fix lower L10 tests
hafezdivandari 7544048
fix tests
hafezdivandari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace SingleStore\Laravel\Tests\Hybrid; | ||
|
||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\Schema; | ||
use SingleStore\Laravel\Schema\Blueprint; | ||
use SingleStore\Laravel\Schema\Builder; | ||
use SingleStore\Laravel\Tests\BaseTest; | ||
|
||
class ChangeColumnTest extends BaseTest | ||
{ | ||
use HybridTestHelpers; | ||
|
||
/** @test */ | ||
public function change_column_on_rowstore_table() | ||
{ | ||
if (version_compare(Application::VERSION, '10.0', '<')) { | ||
$this->markTestSkipped('requires higher laravel version'); | ||
} | ||
|
||
if ($this->runHybridIntegrations()) { | ||
$cached = $this->mockDatabaseConnection; | ||
|
||
$this->mockDatabaseConnection = false; | ||
|
||
if (method_exists(Builder::class, 'useNativeSchemaOperationsIfPossible')) { | ||
Schema::useNativeSchemaOperationsIfPossible(); | ||
} | ||
|
||
$this->createTable(function (Blueprint $table) { | ||
$table->rowstore(); | ||
$table->id(); | ||
$table->string('data'); | ||
}); | ||
|
||
Schema::table('test', function (Blueprint $table) { | ||
$table->text('data')->nullable()->change(); | ||
}); | ||
|
||
$this->assertEquals(['id', 'data'], Schema::getColumnListing('test')); | ||
|
||
if (version_compare(Application::VERSION, '10.30', '>=')) { | ||
$this->assertEquals('text', Schema::getColumnType('test', 'data')); | ||
} | ||
|
||
$this->mockDatabaseConnection = $cached; | ||
} | ||
|
||
$blueprint = new Blueprint('test'); | ||
$blueprint->text('data')->nullable()->change(); | ||
|
||
$connection = $this->getConnection(); | ||
$connection->shouldReceive('getDatabaseName')->andReturn('database'); | ||
$connection->shouldReceive('scalar') | ||
->with("select exists (select 1 from information_schema.tables where table_schema = 'database' and table_name = 'test' and storage_type = 'COLUMNSTORE') as is_columnstore") | ||
->andReturn(0); | ||
$connection->shouldReceive('usingNativeSchemaOperations')->andReturn(true); | ||
$statements = $blueprint->toSql($connection, $this->getGrammar()); | ||
|
||
$this->assertCount(1, $statements); | ||
$this->assertEquals('alter table `test` modify `data` text null', $statements[0]); | ||
} | ||
|
||
/** @test */ | ||
public function change_column_of_columnstore_table() | ||
{ | ||
if (version_compare(Application::VERSION, '11.15', '<')) { | ||
$this->markTestSkipped('requires higher laravel version'); | ||
} | ||
|
||
if ($this->runHybridIntegrations()) { | ||
$cached = $this->mockDatabaseConnection; | ||
|
||
$this->mockDatabaseConnection = false; | ||
|
||
$this->createTable(function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('data'); | ||
}); | ||
|
||
Schema::table('test', function (Blueprint $table) { | ||
$table->text('data')->nullable()->change(); | ||
}); | ||
|
||
$this->assertEquals(['id', 'data'], Schema::getColumnListing('test')); | ||
$this->assertEquals('text', Schema::getColumnType('test', 'data')); | ||
|
||
$this->mockDatabaseConnection = $cached; | ||
} | ||
|
||
$blueprint = new Blueprint('test'); | ||
$blueprint->text('data')->nullable()->change(); | ||
|
||
$connection = $this->getConnection(); | ||
$connection->shouldReceive('getDatabaseName')->andReturn('database'); | ||
$connection->shouldReceive('scalar') | ||
->with("select exists (select 1 from information_schema.tables where table_schema = 'database' and table_name = 'test' and storage_type = 'COLUMNSTORE') as is_columnstore") | ||
->andReturn(1); | ||
|
||
$statements = $blueprint->toSql($connection, $this->getGrammar()); | ||
|
||
$this->assertCount(4, $statements); | ||
$this->assertEquals([ | ||
'alter table `test` add `__temp__data` text null after `data`', | ||
'update `test` set `__temp__data` = `data`', | ||
'alter table `test` drop `data`', | ||
'alter table `test` change `__temp__data` `data`', | ||
], $statements); | ||
} | ||
} |
Oops, something went wrong.
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.
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.
What is the reason, why this is not supported for older versions of Laravel?
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.
Older Laravel versions don't support native column modifying, you may check:
Laravel was using
doctrine/dbal
before this version and I'm quit sure that it is going to be a problem for your package as Doctrine DBAL doesn't support Singlestore. But you may add tests to see if it fallbacks to MySQL correctly or not.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.
in the latest commit 9777d8a I removed this and added test to see if it works with lower Laravel version + Doctrine DBAL
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.
Thanks!
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.
OK the tests shows that we can't use doctrine: