2016-09-22 17 views
1

Laravel 5.3を使用する方法パーティションを実装できますか。以下は、移行で追加しようとしているmysqlテーブル構造です。以下はlaravelデータベースの移行でパーティションを実装する方法

CREATE TABLE `settings` (
    `id` INT(10) unsigned NOT NULL AUTO_INCREMENT, 
    `client_id` INT(11) NOT NULL, 
    `key` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL, 
    `value` TEXT COLLATE utf8_unicode_ci NOT NULL, 
    `created_at` TIMESTAMP NULL DEFAULT NULL, 
    `updated_at` TIMESTAMP NULL DEFAULT NULL, 
    PRIMARY KEY `settings_id_primary` (`client_id`, `id`), 
    UNIQUE KEY `settings_key_unique` (`client_id`, `key`), 
    KEY `settings_id_key` (`id`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci PARTITION BY KEY (`client_id`) PARTITIONS 50; 

私がこれまで試したものですが、これは列だけに&キーを追加しています。

Schema::create('settings', function(Blueprint $table) { 
     $table->integer('id'); // I can't use increments, because throwing an error when I try to add primary key below 
     $table->integer('client_id'); 
     $table->string('key'); 
     $table->text('value'); 
     $table->timestamps(); 

     $table->primary(['client_id', 'id']); 
     $table->unique(['client_id', 'key']); 
    }); 

どのようにパーティションを作成できますか?移行がパーティションをサポートしていない場合移行でSQLクエリ全体をダンプして実行できる方法はありますか?

+1

、のようないいえ、パーティションがある場合は、この使用してLaravelスキーマビルダー –

答えて

3

私は

 Schema::create('settings', function(Blueprint $table) { 
     $table-> increments('id'); 
     $table->integer('client_id')->primary(); 
     $table->string('key'); 
     $table->text('value'); 
     $table->timestamps(); 

     $table->unique(['client_id', 'key']); 
     });   

または

 Schema::create('settings', function(Blueprint $table) { 
     $table-> increments('id'); 
     $table->integer('client_id'); 
     $table->string('key'); 
     $table->text('value'); 
     $table->timestamps(); 

     $table->primary('client_id'); 
     $table->unique(['client_id', 'key']); 
     });   

、それはあなたに助けだと思う​​私は、私はパーティションの解決策を見つけることができない、どこでも検索。
しかし、移行中にダウン機能

DB::unprepared() 

アップの移行ファイルの機能への準備ができていない以下の

私の提案の使用は、パーティションを使用してSQLクエリを実行します。

DB::unprepared('create table....') 
+0

を行う方法はありませんか? –

+0

準備ができていないDBまたは生のDBを使用してください。それはおそらくあなたに役立つでしょう。 –

+0

更新をありがとう、 'DB :: unprepared'を使用します –

関連する問題