Skip to content

Commit cfd93ce

Browse files
Fixed generation of PK
In newer version of Laravel PK is added to CREATE TABLE statement. See https://github.com/laravel/framework/pull/49374/files Our implementation added it from commands and didn't take into account that it is marked as ignored.
1 parent 578ae05 commit cfd93ce

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ public function toSql(Connection $connection, Grammar $grammar)
122122
$indexStatementKeys = [];
123123

124124
foreach ($this->commands as $command) {
125+
if ($command->shouldBeSkipped) {
126+
continue;
127+
}
128+
125129
$method = 'compile'.ucfirst($command->name);
126130
$isIndex = $this->isIndexCommand($command);
127131

tests/Hybrid/CreateTable/IncrementWithoutPrimaryKeyTest.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;
44

5+
use Illuminate\Foundation\Application;
56
use SingleStore\Laravel\Schema\Blueprint;
67
use SingleStore\Laravel\Tests\BaseTest;
78
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
@@ -20,10 +21,17 @@ public function it_adds_a_big_increments_without_primary_key()
2021
$table->primary(['id', 'uuid']);
2122
});
2223

23-
$this->assertCreateStatement(
24-
$blueprint,
25-
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
26-
);
24+
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
25+
$this->assertCreateStatement(
26+
$blueprint,
27+
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key (`id`, `uuid`))'
28+
);
29+
} else {
30+
$this->assertCreateStatement(
31+
$blueprint,
32+
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
33+
);
34+
}
2735
}
2836

2937
/** @test */
@@ -36,9 +44,16 @@ public function it_adds_an_id_without_primary_key()
3644
$table->primary(['id', 'uuid']);
3745
});
3846

39-
$this->assertCreateStatement(
40-
$blueprint,
41-
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
42-
);
47+
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
48+
$this->assertCreateStatement(
49+
$blueprint,
50+
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key (`id`, `uuid`))'
51+
);
52+
} else {
53+
$this->assertCreateStatement(
54+
$blueprint,
55+
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
56+
);
57+
}
4358
}
4459
}

tests/Hybrid/CreateTable/MiscCreateTest.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;
44

5+
use Illuminate\Foundation\Application;
56
use SingleStore\Laravel\Schema\Blueprint;
67
use SingleStore\Laravel\Tests\BaseTest;
78
use SingleStore\Laravel\Tests\Hybrid\HybridTestHelpers;
@@ -20,10 +21,17 @@ public function all_keys_are_added_in_create_columnstore()
2021
$table->index('foo', 'name3', 'hash');
2122
});
2223

23-
$this->assertCreateStatement(
24-
$blueprint,
25-
'create table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `foo` varchar(255) not null, index `name3` using hash(`foo`), primary key `name1`(`primary`), index `name2`(`index`))'
26-
);
24+
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
25+
$this->assertCreateStatement(
26+
$blueprint,
27+
'create table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `foo` varchar(255) not null, index `name3` using hash(`foo`), index `name2`(`index`), primary key (`primary`))'
28+
);
29+
} else {
30+
$this->assertCreateStatement(
31+
$blueprint,
32+
'create table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `foo` varchar(255) not null, index `name3` using hash(`foo`), primary key `name1`(`primary`), index `name2`(`index`))'
33+
);
34+
}
2735
}
2836

2937
/** @test */
@@ -36,10 +44,17 @@ public function all_keys_are_added_in_create_rowstore()
3644
$table->geography('georegion')->spatialIndex('name3');
3745
});
3846

39-
$this->assertCreateStatement(
40-
$blueprint,
41-
'create rowstore table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `georegion` geography not null, primary key `name1`(`primary`), index `name2`(`index`), index `name3`(`georegion`))'
42-
);
47+
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
48+
$this->assertCreateStatement(
49+
$blueprint,
50+
'create rowstore table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `georegion` geography not null, index `name2`(`index`), index `name3`(`georegion`), primary key (`primary`))'
51+
);
52+
} else {
53+
$this->assertCreateStatement(
54+
$blueprint,
55+
'create rowstore table `test` (`primary` varchar(255) not null, `index` varchar(255) not null, `georegion` geography not null, primary key `name1`(`primary`), index `name2`(`index`), index `name3`(`georegion`))'
56+
);
57+
}
4358
}
4459

4560
/** @test */
@@ -68,10 +83,17 @@ public function discussion_53()
6883
$table->timestamps();
6984
});
7085

71-
$this->assertCreateStatement(
72-
$blueprint,
73-
'create table `test` (`id` bigint unsigned not null auto_increment, `user_id` bigint unsigned not null, `template_id` varchar(255) not null, `data` longtext not null, `response_status_code` varchar(255) not null, `response_message` longtext not null, `created_at` timestamp null, `updated_at` timestamp null, index `test_id_index`(`id`), shard key(`user_id`))'
74-
);
86+
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
87+
$this->assertCreateStatement(
88+
$blueprint,
89+
'create table `test` (`id` bigint unsigned not null auto_increment, `user_id` bigint unsigned not null, `template_id` varchar(255) not null, `data` longtext not null, `response_status_code` varchar(255) not null, `response_message` longtext not null, `created_at` timestamp null, `updated_at` timestamp null, index `test_id_index`(`id`), shard key(`user_id`))'
90+
);
91+
} else {
92+
$this->assertCreateStatement(
93+
$blueprint,
94+
'create table `test` (`id` bigint unsigned not null auto_increment, `user_id` bigint unsigned not null, `template_id` varchar(255) not null, `data` longtext not null, `response_status_code` varchar(255) not null, `response_message` longtext not null, `created_at` timestamp null, `updated_at` timestamp null, index `test_id_index`(`id`), shard key(`user_id`))'
95+
);
96+
}
7597
}
7698

7799
/** @test */

0 commit comments

Comments
 (0)