PHP code example of brokenice / laravel-mysql-partition
1. Go to this page and download the library: Download brokenice/laravel-mysql-partition library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brokenice / laravel-mysql-partition example snippets
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Brokenice\LaravelMysqlPartition\Models\Partition;
use Brokenice\LaravelMysqlPartition\Schema\Schema;
class CreatePartitionedTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('partitioned', static function (Blueprint $table) {
$table->bigInteger('id');
$table->string('name');
$table->date('date');
$table->timestamps();
$table->primary(['id','date']);
});
// Force autoincrement of one field in composite primary key
Schema::forceAutoIncrement('partitioned', 'id');
// Make partition by LIST
Schema::partitionByList('partitioned', 'id',
[
new Partition('server_east', Partition::LIST_TYPE, [1,43,65,12,56,73]),
new Partition('server_west', Partition::LIST_TYPE, [534,6422,196,956,22])
]
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('partitioned');
}
}
namespace App;
use Illuminate\Database\Eloquent\Model;
class Partitioned extends Model
{
protected $table = 'partitioned';
}
Psy Shell v0.9.9 (PHP 7.3.6 — cli) by Justin Hileman
>>> use App\Models\Partitioned;
>>> Partitioned::partition('name')->first();
Psy Shell v0.9.9 (PHP 7.3.6 — cli) by Justin Hileman
>>> use App\Models\Partitioned;
>>> Partitioned::partitions(['name', 'name1'])->first();