-
Notifications
You must be signed in to change notification settings - Fork 24
Question Regarding Shard Keys #53
-
I have a table defined like this in Laravel
Schema::create('user_mails', function (Blueprint $table) { $table->bigIncrements('id'); $table->unsignedBigInteger('user_id'); $table->string('template_id'); $table->longText('data'); $table->string('response_status_code'); $table->longText('response_message'); $table->timestamps(); });
I want to add a shardkey on the 'user_id' column
So I added this after the timestamps as per the docs
$table->shardKey('user_id');
I get the following error
Incorrect table definition; there can be only one auto column and it must be defined as a key
My Question is, what would the correct way to add these shard keys be? I can do it directly in singlestore using
CREATE TABLE `user_mails` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
`template_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`data` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`response_status_code` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`response_message` longtext COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY (`id`) USING HASH,
SHARD KEY(`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
And this works however I need to map this to a migration file
Would this be the correct solution?
$table->id()->withoutPrimaryKey();
$table->unsignedBigInteger('user_id')->shardKey();
...
$table->primary(['id', 'user_id']);
Beta Was this translation helpful? Give feedback.
All reactions
It seems like the correct answer is something like this:
$table->bigIncrements('id')->withoutPrimaryKey()->index(); $table->unsignedBigInteger('user_id')->shardKey(); $table->string('template_id'); $table->longText('data'); $table->string('response_status_code'); $table->longText('response_message'); $table->timestamps();
Added as a test for future reference:
e6fd63b#diff-f6da6c22d5e74ab81179bda2693633c2fb36619a61c3d97f857875f906c8fa1bR59
Replies: 1 comment
-
It seems like the correct answer is something like this:
$table->bigIncrements('id')->withoutPrimaryKey()->index(); $table->unsignedBigInteger('user_id')->shardKey(); $table->string('template_id'); $table->longText('data'); $table->string('response_status_code'); $table->longText('response_message'); $table->timestamps();
Added as a test for future reference:
e6fd63b#diff-f6da6c22d5e74ab81179bda2693633c2fb36619a61c3d97f857875f906c8fa1bR59
Beta Was this translation helpful? Give feedback.