Skip to content

Commit

Permalink
Fixed generation of PK
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AdalbertMemSQL committed Jan 2, 2024
1 parent 578ae05 commit cfd93ce
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/Schema/Blueprint/InlinesIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public function toSql(Connection $connection, Grammar $grammar)
$indexStatementKeys = [];

foreach ($this->commands as $command) {
if ($command->shouldBeSkipped) {
continue;
}

$method = 'compile'.ucfirst($command->name);
$isIndex = $this->isIndexCommand($command);

Expand Down
31 changes: 23 additions & 8 deletions tests/Hybrid/CreateTable/IncrementWithoutPrimaryKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;

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

$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
);
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key (`id`, `uuid`))'
);
} else {
$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
);
}
}

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

$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
);
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key (`id`, `uuid`))'
);
} else {
$this->assertCreateStatement(
$blueprint,
'create table `test` (`id` bigint unsigned not null auto_increment, `uuid` char(36) not null, primary key `test_id_uuid_primary`(`id`, `uuid`))'
);
}
}
}
46 changes: 34 additions & 12 deletions tests/Hybrid/CreateTable/MiscCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SingleStore\Laravel\Tests\Hybrid\CreateTable;

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

$this->assertCreateStatement(
$blueprint,
'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`))'
);
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
} else {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
}
}

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

$this->assertCreateStatement(
$blueprint,
'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`))'
);
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
} else {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
}
}

/** @test */
Expand Down Expand Up @@ -68,10 +83,17 @@ public function discussion_53()
$table->timestamps();
});

$this->assertCreateStatement(
$blueprint,
'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`))'
);
if (version_compare(Application::VERSION, '10.38.0', '>=')) {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
} else {
$this->assertCreateStatement(
$blueprint,
'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`))'
);
}
}

/** @test */
Expand Down

0 comments on commit cfd93ce

Please sign in to comment.