vd
This commit is contained in:
parent
f6eebdbcab
commit
b8d3f1bbcb
@ -139,7 +139,7 @@ if (! function_exists('array_merge_sum')) {
|
|||||||
$array[$key] = isset($array[$key]) ? $array[$key] + $value : $value;
|
$array[$key] = isset($array[$key]) ? $array[$key] + $value : $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,14 +148,34 @@ if (! function_exists('human_filesize')) {
|
|||||||
/**
|
/**
|
||||||
* 文件大小可读性
|
* 文件大小可读性
|
||||||
*
|
*
|
||||||
* @param array $arr1
|
* @param int $int
|
||||||
* @param array $arr2
|
* @param int $decimals
|
||||||
|
* @param array $options
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function human_filesize($bytes, $decimals = 2)
|
function human_filesize($int, $decimals = 2, array $options = [])
|
||||||
{
|
{
|
||||||
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
|
$size = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
$factor = floor((strlen($bytes) - 1) / 3);
|
$factor = floor((strlen($int) - 1) / 3);
|
||||||
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
|
|
||||||
|
$options = array_map('strtoupper', $options);
|
||||||
|
|
||||||
|
if (isset($options['unit']) && array_search($options['unit'], $size) !== false) {
|
||||||
|
for ($i=0; $i < array_search($options['unit'], $size); $i++) {
|
||||||
|
unset($size[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$size = array_values($size);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['min']) && array_search($options['min'], $size) !== false) {
|
||||||
|
$factor = $factor < array_search($options['min'], $size) ? array_search($options['min'], $size) : $factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options['max']) && array_search($options['max'], $size) !== false) {
|
||||||
|
$factor = $factor > array_search($options['max'], $size) ? array_search($options['max'], $size) : $factor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf("%.{$decimals}f", $int / pow(1024, $factor)) . @$size[$factor];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class CreateVirtualPackagesTable extends Migration
|
|||||||
$table->integer('guide_price')->unsigned()->default(0)->comment('指导价格');
|
$table->integer('guide_price')->unsigned()->default(0)->comment('指导价格');
|
||||||
$table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格');
|
$table->integer('renewal_cost_price')->unsigned()->default(0)->comment('续费成本价格');
|
||||||
$table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格');
|
$table->integer('renewal_guide_price')->unsigned()->default(0)->comment('续费指导价格');
|
||||||
$table->integer('flows')->unsigned()->default(0)->comment('套餐流量(M)');
|
$table->integer('flows')->unsigned()->default(0)->comment('套餐流量 单位MB');
|
||||||
$table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)');
|
$table->integer('voices')->unsigned()->default(0)->comment('套餐语音(分钟)');
|
||||||
$table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)');
|
$table->integer('messages')->unsigned()->default(0)->comment('套餐短信(条)');
|
||||||
$table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务(0:无 1:有)');
|
$table->tinyInteger('has_messages')->unsigned()->default(255)->comment('是否开通短信服务(0:无 1:有)');
|
||||||
|
@ -13,6 +13,10 @@ class CreateStatsExportsTable extends Migration
|
|||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
|
if (Schema::hasTable('exports')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Schema::create('exports', function (Blueprint $table) {
|
Schema::create('exports', function (Blueprint $table) {
|
||||||
$table->increments('id')->comment('自增ID');
|
$table->increments('id')->comment('自增ID');
|
||||||
$table->string('sn', 32)->default('')->comment('命令编号');
|
$table->string('sn', 32)->default('')->comment('命令编号');
|
||||||
|
@ -0,0 +1,112 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateFlowPoolTables extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
if (!Schema::hasTable('virtual_card_flows')) {
|
||||||
|
Schema::create('virtual_card_flows', function (Blueprint $table) {
|
||||||
|
$table->integer('pool_id')->unsigned()->default(0)->comment('流量池ID');
|
||||||
|
$table->bigInteger('sim')->unsigned()->default(0)->comment('SIM号');
|
||||||
|
$table->integer('month')->unsigned()->default(0)->comment('月份');
|
||||||
|
$table->integer('kilobyte')->unsigned()->default(0)->comment('使用流量 单位KB');
|
||||||
|
$table->comment('VD卡流量使用情况');
|
||||||
|
|
||||||
|
$table->primary('month');
|
||||||
|
|
||||||
|
$table->partition('month', 'list');
|
||||||
|
$table->addPartition('virtual_card_flows_201801', 'list', [201801]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
if (!Schema::hasTable('real_flow_pools')) {
|
||||||
|
Schema::create('real_flow_pools', function (Blueprint $table) {
|
||||||
|
$table->increments('id')->comment('自增ID');
|
||||||
|
$table->string('sn', 32)->default('')->comment('编号');
|
||||||
|
$table->integer('relation_id')->unsigned()->default(0)->comment('关联ID 1级流量池关联集团 2级流量池关联企业');
|
||||||
|
$table->string('name', 32)->unsigned()->default(0)->comment('名称');
|
||||||
|
$table->integer('flows')->default(255)->comment('流量值 -1不限流量 单位MB');
|
||||||
|
$table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)');
|
||||||
|
$table->tinyInteger('level')->unsigned()->default(0)->comment('等级 0:未知 1:一级流量池 2:二级流量池');
|
||||||
|
$table->tinyInteger('shared')->unsigned()->default(0)->comment('共享类型 0:未知 1同流量横向共享 2基础流量纵向共享 3纵向共享');
|
||||||
|
$table->text('package_ids')->nullable()->comment('包含套餐');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
|
||||||
|
$table->unique(['sn', 'deleted_at']);
|
||||||
|
|
||||||
|
$table->comment('RD流量池');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Schema::hasTable('virtual_flow_pools')) {
|
||||||
|
Schema::create('virtual_flow_pools', function (Blueprint $table) {
|
||||||
|
$table->increments('id')->comment('自增ID');
|
||||||
|
$table->string('sn', 32)->default('')->comment('编号');
|
||||||
|
$table->integer('company_id')->unsigned()->default(0)->comment('关联企业ID');
|
||||||
|
$table->string('name', 32)->unsigned()->default(0)->comment('名称');
|
||||||
|
$table->integer('flows')->default(255)->comment('流量值 -1不限流量 单位MB');
|
||||||
|
$table->tinyInteger('carrier_operator')->unsigned()->default(255)->comment('运营商(0:联通 1:移动 2:电信)');
|
||||||
|
$table->tinyInteger('shared')->unsigned()->default(0)->comment('共享类型 0:未知 1纵向共享 2横向共享');
|
||||||
|
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
|
||||||
|
$table->text('package_ids')->nullable()->comment('包含套餐');
|
||||||
|
$table->text('real_pool_ids')->nullable()->comment('RD流量池ID');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
|
||||||
|
$table->unique(['sn', 'deleted_at']);
|
||||||
|
|
||||||
|
$table->comment('VD流量池');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Schema::hasTable('virtual_flow_pool_settings')) {
|
||||||
|
Schema::create('virtual_flow_pools', function (Blueprint $table) {
|
||||||
|
$table->increments('id')->comment('自增ID');
|
||||||
|
$table->integer('pool_id')->unsigned()->default(0)->comment('流量池ID');
|
||||||
|
$table->text('minimum_settings')->nullable()->comment('套餐保底配置');
|
||||||
|
$table->integer('first_month_price')->unsigned()->default(0)->comment('首月单价');
|
||||||
|
$table->integer('other_month_price')->unsigned()->default(0)->comment('次月单价');
|
||||||
|
$table->timestamp('start_at');
|
||||||
|
$table->timestamp('end_at');
|
||||||
|
$table->softDeletes();
|
||||||
|
|
||||||
|
$table->index('pool_id');
|
||||||
|
|
||||||
|
$table->comment('流量池定价');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Schema::hasTable('virtual_card_flows')) {
|
||||||
|
Schema::create('virtual_card_flows', function (Blueprint $table) {
|
||||||
|
$table->integer('pool_id')->unsigned()->default(0)->comment('流量池ID');
|
||||||
|
$table->bigInteger('sim')->unsigned()->default(0)->comment('SIM号');
|
||||||
|
$table->integer('month')->unsigned()->default(0)->comment('月份');
|
||||||
|
$table->integer('kilobyte')->unsigned()->default(0)->comment('使用流量 单位KB');
|
||||||
|
$table->comment('VD卡流量使用情况');
|
||||||
|
|
||||||
|
$table->primary('sim');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('virtual_card_flows');
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||||
|
|
||||||
|
echo human_filesize(20*pow(1024, 0), 2) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 1), 2) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 2), 2) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 3), 2) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 4), 2) . PHP_EOL;
|
||||||
|
|
||||||
|
echo PHP_EOL;
|
||||||
|
|
||||||
|
echo human_filesize(20*pow(1024, 0), 2, ['unit' => 'KB', 'min' => 'MB', 'max' => 'GB']) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 1), 2, ['unit' => 'KB', 'min' => 'MB', 'max' => 'GB']) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 2), 2, ['unit' => 'KB', 'min' => 'MB', 'max' => 'GB']) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 3), 2, ['unit' => 'KB', 'min' => 'MB', 'max' => 'GB']) . PHP_EOL;
|
||||||
|
echo human_filesize(20*pow(1024, 4), 2, ['unit' => 'KB', 'min' => 'MB', 'max' => 'GB']) . PHP_EOL;
|
||||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -14,6 +14,7 @@ return array(
|
|||||||
'CreateBlocsTable' => $baseDir . '/database/migrations/2018_12_24_164210_create_blocs_table.php',
|
'CreateBlocsTable' => $baseDir . '/database/migrations/2018_12_24_164210_create_blocs_table.php',
|
||||||
'CreateCardsTable' => $baseDir . '/database/migrations/2018_12_24_164218_create_cards_table.php',
|
'CreateCardsTable' => $baseDir . '/database/migrations/2018_12_24_164218_create_cards_table.php',
|
||||||
'CreateFailedJobsTable' => $baseDir . '/database/migrations/0000_00_00_000000_create_failed_jobs_table.php',
|
'CreateFailedJobsTable' => $baseDir . '/database/migrations/0000_00_00_000000_create_failed_jobs_table.php',
|
||||||
|
'CreateFlowPoolTables' => $baseDir . '/database/migrations/2019_01_24_175246_create_flow_pool_tables.php',
|
||||||
'CreateJobsTable' => $baseDir . '/database/migrations/0000_00_00_000000_create_jobs_table.php',
|
'CreateJobsTable' => $baseDir . '/database/migrations/0000_00_00_000000_create_jobs_table.php',
|
||||||
'CreateRealAddedOrderCardsTables' => $baseDir . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php',
|
'CreateRealAddedOrderCardsTables' => $baseDir . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php',
|
||||||
'CreateRealAddedOrdersTable' => $baseDir . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php',
|
'CreateRealAddedOrdersTable' => $baseDir . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php',
|
||||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -733,6 +733,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
|
|||||||
'CreateBlocsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164210_create_blocs_table.php',
|
'CreateBlocsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164210_create_blocs_table.php',
|
||||||
'CreateCardsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164218_create_cards_table.php',
|
'CreateCardsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164218_create_cards_table.php',
|
||||||
'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/0000_00_00_000000_create_failed_jobs_table.php',
|
'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/0000_00_00_000000_create_failed_jobs_table.php',
|
||||||
|
'CreateFlowPoolTables' => __DIR__ . '/../..' . '/database/migrations/2019_01_24_175246_create_flow_pool_tables.php',
|
||||||
'CreateJobsTable' => __DIR__ . '/../..' . '/database/migrations/0000_00_00_000000_create_jobs_table.php',
|
'CreateJobsTable' => __DIR__ . '/../..' . '/database/migrations/0000_00_00_000000_create_jobs_table.php',
|
||||||
'CreateRealAddedOrderCardsTables' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php',
|
'CreateRealAddedOrderCardsTables' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php',
|
||||||
'CreateRealAddedOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php',
|
'CreateRealAddedOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_24_164457_create_real_added_orders_table.php',
|
||||||
|
@ -29,7 +29,7 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
$connection->setQueryGrammar(new PostgresGrammar);
|
$connection->setQueryGrammar(new PostgresGrammar);
|
||||||
return $connection;
|
return $connection;
|
||||||
});
|
});
|
||||||
|
|
||||||
DB::extend('mysql', function ($config, $name) {
|
DB::extend('mysql', function ($config, $name) {
|
||||||
$factory = new ConnectionFactory($this->app);
|
$factory = new ConnectionFactory($this->app);
|
||||||
$connection = $factory->make($config, $name);
|
$connection = $factory->make($config, $name);
|
||||||
@ -45,7 +45,9 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
QueryBuilder::macro('createNotExist', $this->macroCreateNotExist());
|
QueryBuilder::macro('createNotExist', $this->macroCreateNotExist());
|
||||||
QueryBuilder::macro('updateBatch', $this->macroUpdateBatch());
|
QueryBuilder::macro('updateBatch', $this->macroUpdateBatch());
|
||||||
SchemaBlueprint::macro('comment', $this->macroSchemaComment());
|
SchemaBlueprint::macro('comment', $this->macroSchemaComment());
|
||||||
|
SchemaBlueprint::macro('partition', $this->macroSchemaPartition());
|
||||||
SchemaBlueprint::macro('setIncrement', $this->macroSchemaSetIncrement());
|
SchemaBlueprint::macro('setIncrement', $this->macroSchemaSetIncrement());
|
||||||
|
SchemaBlueprint::macro('addPartition', $this->macroSchemaAddPartition());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,17 +61,17 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
ksort($value);
|
ksort($value);
|
||||||
|
|
||||||
$values[$key] = $value;
|
$values[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->connection->affectingStatement(
|
return $this->connection->affectingStatement(
|
||||||
$this->grammar->compileReplace($this, $values),
|
$this->grammar->compileReplace($this, $values),
|
||||||
$this->cleanBindings(Arr::flatten($values, 1))
|
$this->cleanBindings(Arr::flatten($values, 1))
|
||||||
@ -88,17 +90,17 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
ksort($value);
|
ksort($value);
|
||||||
|
|
||||||
$values[$key] = $value;
|
$values[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->connection->affectingStatement(
|
return $this->connection->affectingStatement(
|
||||||
$this->grammar->compileInsertUpdate($this, $values),
|
$this->grammar->compileInsertUpdate($this, $values),
|
||||||
$this->cleanBindings(Arr::flatten($values, 1))
|
$this->cleanBindings(Arr::flatten($values, 1))
|
||||||
@ -146,21 +148,21 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($where)) {
|
if (empty($where)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
} else {
|
} else {
|
||||||
foreach ($values as $key => $value) {
|
foreach ($values as $key => $value) {
|
||||||
ksort($value);
|
ksort($value);
|
||||||
|
|
||||||
$values[$key] = $value;
|
$values[$key] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->connection->affectingStatement(
|
return $this->connection->affectingStatement(
|
||||||
$this->grammar->compileCreateNotExist($this, $values, $where),
|
$this->grammar->compileCreateNotExist($this, $values, $where),
|
||||||
$this->cleanBindings(Arr::flatten($values, 1))
|
$this->cleanBindings(Arr::flatten($values, 1))
|
||||||
@ -181,7 +183,7 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
} else {
|
} else {
|
||||||
@ -210,7 +212,7 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
if (empty($values)) {
|
if (empty($values)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
} else {
|
} else {
|
||||||
@ -249,4 +251,31 @@ class DatabaseServiceProvider extends ServiceProvider
|
|||||||
return $this->addCommand('setIncrement', compact('number'));
|
return $this->addCommand('setIncrement', compact('number'));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分区表
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function macroSchemaPartition()
|
||||||
|
{
|
||||||
|
return function ($column, $type) {
|
||||||
|
$this->partition = [
|
||||||
|
'type' => $type,
|
||||||
|
'column' => $column,
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加分区
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function macroSchemaAddPartition()
|
||||||
|
{
|
||||||
|
return function ($table, $type, array $conditions) {
|
||||||
|
return $this->addCommand('addPartition', compact('table', 'type', 'conditions'));
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class MySqlGrammar extends Grammar
|
|||||||
// simply makes creating the SQL easier for us since we can utilize the same
|
// simply makes creating the SQL easier for us since we can utilize the same
|
||||||
// basic routine regardless of an amount of records given to us to insert.
|
// basic routine regardless of an amount of records given to us to insert.
|
||||||
$table = $this->wrapTable($query->from);
|
$table = $this->wrapTable($query->from);
|
||||||
|
|
||||||
if (!is_array(reset($values))) {
|
if (!is_array(reset($values))) {
|
||||||
$values = [$values];
|
$values = [$values];
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,18 @@ class PostgresSchemaGrammar extends Grammar
|
|||||||
{
|
{
|
||||||
$sql = [];
|
$sql = [];
|
||||||
|
|
||||||
|
$partition = '';
|
||||||
|
|
||||||
|
if ($blueprint->partition) {
|
||||||
|
$partition = sprintf('partition by %s (%s)', $blueprint->partition['type'], $blueprint->partition['column']);
|
||||||
|
}
|
||||||
|
|
||||||
$sql[] = sprintf(
|
$sql[] = sprintf(
|
||||||
'%s table %s (%s)',
|
'%s table %s (%s) %s',
|
||||||
$blueprint->temporary ? 'create temporary' : 'create',
|
$blueprint->temporary ? 'create temporary' : 'create',
|
||||||
$this->wrapTable($blueprint),
|
$this->wrapTable($blueprint),
|
||||||
implode(', ', $this->getColumns($blueprint))
|
implode(', ', $this->getColumns($blueprint)),
|
||||||
|
$partition
|
||||||
);
|
);
|
||||||
|
|
||||||
$comments = collect($blueprint->getAddedColumns())->where('comment', '<>', '')->all();
|
$comments = collect($blueprint->getAddedColumns())->where('comment', '<>', '')->all();
|
||||||
@ -88,10 +95,35 @@ class PostgresSchemaGrammar extends Grammar
|
|||||||
|
|
||||||
if ($column) {
|
if ($column) {
|
||||||
$index = $this->wrap("{$blueprint->getTable()}_{$column->name}_seq");
|
$index = $this->wrap("{$blueprint->getTable()}_{$column->name}_seq");
|
||||||
return sprintf("select setval('%s', %d, true);", $index, $command->number);
|
return sprintf("select setval('%s', %d, true)", $index, $command->number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compile a add partition table command.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Schema\Blueprint $blueprint
|
||||||
|
* @param \Illuminate\Support\Fluent $command
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function compileAddPartition(Blueprint $blueprint, Fluent $command)
|
||||||
|
{
|
||||||
|
if ($command->type === 'list') {
|
||||||
|
$sql = sprintf('IN (%s)', implode(',', array_map([$this, 'wrapString'], $command->conditions)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($command->type === 'range') {
|
||||||
|
$sql = sprintf("FROM ('%s') TO ('%s')", $command->conditions[0], $command->conditions[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
"create table %s partition of %s FOR VALUES %s",
|
||||||
|
$command->table,
|
||||||
|
$this->wrapTable($blueprint),
|
||||||
|
$sql
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of column names into a delimited string.
|
* Convert an array of column names into a delimited string.
|
||||||
*
|
*
|
||||||
@ -108,4 +140,20 @@ class PostgresSchemaGrammar extends Grammar
|
|||||||
return $this->wrap($column);
|
return $this->wrap($column);
|
||||||
}, $columns));
|
}, $columns));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap a single string in keyword identifiers.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function wrapString($value)
|
||||||
|
{
|
||||||
|
if ($value !== '*') {
|
||||||
|
return "'".str_replace("'", "''''", $value)."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user