From 2a6888bb31ddc8454b84c8bc5c1ce9ef5df9cc33 Mon Sep 17 00:00:00 2001 From: denghy Date: Tue, 29 Jan 2019 18:03:01 +0800 Subject: [PATCH] virtual_order_cards --- ...9_create_real_added_order_cards_tables.php | 23 ++++++++++++++++- ...0946_create_virtual_order_cards_tables.php | 24 +++++++++++++++++- ...9_01_24_175246_create_flow_pool_tables.php | 25 ++++++------------- .../src/Database/PostgresSchemaGrammar.php | 18 +++++++++++++ 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php b/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php index e8ef04cf..5e4bdc06 100644 --- a/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php +++ b/database/migrations/2018_12_24_164459_create_real_added_order_cards_tables.php @@ -19,7 +19,28 @@ class CreateRealAddedOrderCardsTables extends Migration return; } - DB::unprepared(File::get(__DIR__ . '/create_real_added_order_cards_table.pgsql')); + Schema::create('real_added_order_cards_table_partition', function (Blueprint $table) { + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('counts')->unsigned()->default(0)->comment('数量'); + $table->timestamps(); + + $table->unique(['sim', 'order_id']); + + $table->comment("RD续费及增值包订单关联卡"); + + $table->partition('type', 'list'); + $table->addPartition('real_added_order_renewal_cards', 'list', 1); + $table->addPartition('real_added_order_renewal_package_cards', 'list', 2); + $table->addPartition('real_added_order_flows_package_cards', 'list', 3); + $table->addPartition('real_added_order_optional_package_cards', 'list', 4); + $table->addPartition('real_added_order_additional_package_cards', 'list', 5); + }); + + // DB::unprepared(File::get(__DIR__ . '/create_real_added_order_cards_table.pgsql')); } /** diff --git a/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php b/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php index a6fc9ab9..2682056f 100644 --- a/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php +++ b/database/migrations/2018_12_31_170946_create_virtual_order_cards_tables.php @@ -20,7 +20,29 @@ class CreateVirtualOrderCardsTables extends Migration } DB::unprepared(File::get(__DIR__ . '/create_virtaul_order_cards_func.pgsql')); - DB::unprepared(File::get(__DIR__ . '/create_virtual_order_cards_table.pgsql')); + // DB::unprepared(File::get(__DIR__ . '/create_virtual_order_cards_table.pgsql')); + + Schema::create('virtual_order_cards_partition', function (Blueprint $table) { + $table->increments('id')->comment('自增ID'); + $table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型(0:基础套餐 1:套餐续费 2:续费包 3:加油包 4:可选包 5:附加包)'); + $table->bigInteger('sim')->unsigned()->default(0)->comment('sim号'); + $table->integer('order_id')->unsigned()->default(0)->comment('订单ID'); + $table->integer('company_id')->unsigned()->default(0)->comment('企业ID'); + $table->integer('package_id')->unsigned()->default(0)->comment('套餐ID'); + $table->integer('counts')->unsigned()->default(0)->comment('数量'); + $table->timestamps(); + + $table->unique(['sim', 'order_id', 'deleted_at']); + + $table->comment("RD续费及增值包订单关联卡"); + + $table->partition('type', 'list'); + + $table->addPartition('virtual_order_cards', 'list', 0); + $table->addPartition('virtual_order_renewal_cards', 'list', 1); + $table->addPartition('virtual_order_renewal_package_cards', 'list', 2); + $table->addPartition('virtual_order_flows_package_cards', 'list', 3); + }); } /** diff --git a/database/migrations/2019_01_24_175246_create_flow_pool_tables.php b/database/migrations/2019_01_24_175246_create_flow_pool_tables.php index 0d910526..ba302788 100644 --- a/database/migrations/2019_01_24_175246_create_flow_pool_tables.php +++ b/database/migrations/2019_01_24_175246_create_flow_pool_tables.php @@ -13,22 +13,6 @@ class CreateFlowPoolTables extends Migration */ 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'); @@ -89,13 +73,17 @@ class CreateFlowPoolTables extends Migration if (!Schema::hasTable('virtual_card_flows')) { Schema::create('virtual_card_flows', function (Blueprint $table) { + $table->increments('id')->comment('订单ID'); $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'); + $table->index('month'); + $table->index('pool_id'); + + $table->partition('month', 'list'); }); } } @@ -108,5 +96,8 @@ class CreateFlowPoolTables extends Migration public function down() { Schema::dropIfExists('virtual_card_flows'); + Schema::dropIfExists('virtual_flow_pool_settings'); + Schema::dropIfExists('virtual_flow_pools'); + Schema::dropIfExists('real_flow_pools'); } } diff --git a/vendor/dipper/foundation/src/Database/PostgresSchemaGrammar.php b/vendor/dipper/foundation/src/Database/PostgresSchemaGrammar.php index 9dd1a342..1f9cd618 100644 --- a/vendor/dipper/foundation/src/Database/PostgresSchemaGrammar.php +++ b/vendor/dipper/foundation/src/Database/PostgresSchemaGrammar.php @@ -156,4 +156,22 @@ class PostgresSchemaGrammar extends Grammar return $value; } + + /** + * Get the SQL for an auto-increment column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifyIncrement(Blueprint $blueprint, Fluent $column) + { + if (in_array($column->type, $this->serials) && $column->autoIncrement) { + if ($blueprint->partition && $blueprint->partition['column'] !== $column->name) { + return ''; + } + + return ' primary key'; + } + } }