数据库备注

This commit is contained in:
邓皓元 2018-12-21 16:09:08 +08:00
parent aaaa8f07f6
commit be56116baa
18 changed files with 221 additions and 58 deletions

View File

@ -28,9 +28,10 @@ class CreateAccountsTable extends Migration
$table->index('username');
$table->index('mobile');
});
db_alter('accounts', '平台账号', 100000);
$table->comment('平台账号');
$table->setIncrement(100000);
});
}
/**

View File

@ -18,9 +18,9 @@ class CreateConfigsTable extends Migration
$table->text('value')->nullable()->comment('缓存值');
$table->timestamps();
$table->primary('name');
});
db_alter('configs', '配置表');
$table->comment('配置表');
});
}
/**

View File

@ -29,9 +29,9 @@ class CreateFileTables extends Migration
$table->timestamps();
$table->primary('id');
});
db_alter('files', '文件表');
$table->comment('文件表');
});
// 文件关联表
Schema::create('file_withs', function (Blueprint $table) {
@ -46,9 +46,9 @@ class CreateFileTables extends Migration
$table->index('file_id');
$table->index('account_id');
$table->index(['type', 'type_id']);
});
db_alter('file_withs', '文件关联表');
$table->comment('文件关联表');
});
}
/**

View File

@ -33,9 +33,9 @@ class CreateLogs extends Migration
$table->timestamps();
$table->primary('id');
});
db_alter('logs', '日志表');
$table->comment('日志表');
});
}
/**

View File

@ -28,9 +28,9 @@ class CreatePermissionTables extends Migration
$table->tinyInteger('displayorder')->unsigned()->default(0)->comment('排序');
$table->nestedset();
$table->timestamps();
});
db_alter('permissions', '权限表');
$table->comment('权限表');
});
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
@ -39,25 +39,25 @@ class CreatePermissionTables extends Migration
$table->nestedset();
$table->timestamps();
$table->unique(['name']);
});
db_alter('roles', '角色表');
$table->comment('角色表');
});
Schema::create('account_has_roles', function (Blueprint $table) use ($tableNames) {
$table->unsignedInteger('role_id');
$table->unsignedInteger('account_id');
$table->primary(['role_id', 'account_id']);
});
db_alter('account_has_roles', '账号角色关联表');
$table->comment('账号角色关联表');
});
Schema::create('role_has_permissions', function (Blueprint $table) use ($tableNames) {
$table->unsignedInteger('permission_id');
$table->unsignedInteger('role_id');
$table->primary(['permission_id', 'role_id']);
});
db_alter('role_has_permissions', '角色权限关联表');
$table->comment('角色权限关联表');
});
}
/**

12
composer.lock generated
View File

@ -626,17 +626,17 @@
},
{
"name": "dipper/foundation",
"version": "1.1.8",
"version": "1.1.9",
"source": {
"type": "git",
"url": "ssh://gogs@git.fxft.net:2222/composer/foundation.git",
"reference": "0010bd177e6a367285a6ff3401f265bc80ef32fb"
"reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0"
},
"dist": {
"type": "tar",
"url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.8-30793d.tar",
"reference": "0010bd177e6a367285a6ff3401f265bc80ef32fb",
"shasum": "6839ae4c43c3f38f4fe2ca22a1cc06b75934debd"
"url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.9-51f1b8.tar",
"reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0",
"shasum": "b17959dd9990df31f7e6c3cff53749afe151f670"
},
"require": {
"barryvdh/laravel-cors": "~0.11",
@ -670,7 +670,7 @@
}
],
"description": "The Foundation of the Dipper Architecture project for Lumen",
"time": "2018-12-21T03:15:03+00:00"
"time": "2018-12-21T07:43:51+00:00"
},
{
"name": "dipper/jwt-auth",

View File

@ -20,6 +20,8 @@ class CreateFailedJobsTable extends Migration
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
$table->comment('失败任务表');
});
}

View File

@ -15,7 +15,7 @@ class CreateBaseTables extends Migration
public function up()
{
foreach (app(Dicts::class)->get('tables') as $prefix => $type) {
Schema::create("{$prefix}_companies", function (Blueprint $table) {
Schema::create("{$prefix}_companies", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('企业ID');
$table->string('sn', 32)->comment('企业编号');
$table->string('name', 32)->default('')->comment('企业名称');
@ -28,11 +28,10 @@ class CreateBaseTables extends Migration
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->comment("{$type}企业");
});
db_alter("{$prefix}_companies", "{$type}企业");
Schema::create("{$prefix}_packages", function (Blueprint $table) {
Schema::create("{$prefix}_packages", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('企业ID');
$table->integer('parent_id')->unsigned()->default(0)->comment('父级ID');
$table->string('sn', 20)->comment('套餐编号');
@ -61,11 +60,11 @@ class CreateBaseTables extends Migration
$table->index('parent_id');
$table->index('type');
$table->index('carrier_operator');
$table->comment("{$type}套餐");
});
db_alter("{$prefix}_packages", "{$type}套餐");
Schema::create("{$prefix}_order_cards", function (Blueprint $table) {
Schema::create("{$prefix}_order_cards", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('关联表ID');
$table->bigInteger('sim')->unsigned()->default(0)->comment('sim号');
$table->integer('order_id')->unsigned()->default(0)->comment('订单ID');
@ -76,11 +75,11 @@ class CreateBaseTables extends Migration
$table->unique(['sim', 'order_id']);
$table->unique(['sim', 'deleted_at']);
});
db_alter("{$prefix}_cards", "{$type}订单企业套餐卡关联表");
Schema::create("{$prefix}_added_orders", function (Blueprint $table) {
$table->comment("{$type}订单企业套餐卡关联表");
});
Schema::create("{$prefix}_added_orders", function (Blueprint $table) use ($type) {
$table->increments('id')->comment('订单ID');
$table->string('sn', 32)->comment('订单编号');
$table->tinyInteger('type')->unsigned()->default(0)->comment('订单类型1:套餐续费 2续费包 3:加油包 4:可选包 5:附加包)');
@ -99,9 +98,9 @@ class CreateBaseTables extends Migration
$table->index('type');
$table->index('company_id');
$table->index('order_at');
});
db_alter("{$prefix}_orders", "{$type}增值包订单");
$table->comment("{$type}增值包订单");
});
}
Schema::create("real_orders", function (Blueprint $table) {
@ -127,9 +126,9 @@ class CreateBaseTables extends Migration
$table->index('type');
$table->index('company_id');
$table->index('order_at');
});
db_alter("real_orders", "RD订单");
$table->comment('RD订单');
});
Schema::create("blocs", function (Blueprint $table) {
$table->increments('id')->comment('集团ID');
@ -143,9 +142,9 @@ class CreateBaseTables extends Migration
$table->unique(['sn', 'deleted_at']);
$table->index('name');
$table->index('carrier_operator');
});
db_alter("blocs", "卡源集团");
$table->comment('卡源集团');
});
Schema::create("cards", function (Blueprint $table) {
$table->bigInteger('sim')->unsigned()->default(0)->comment('sim号');
@ -159,10 +158,9 @@ class CreateBaseTables extends Migration
$table->timestamps();
$table->primary('sim');
$table->comment('卡基础信息表');
});
db_alter("cards", "卡基础信息表");
Schema::create("virtual_company_accounts", function (Blueprint $table) {
$table->increments('id')->comment('自增ID');
$table->integer('company_id')->unsigned()->default(0)->comment('企业ID');
@ -176,6 +174,7 @@ class CreateBaseTables extends Migration
$table->softDeletes();
$table->unique(['mobile', 'deleted_at']);
$table->comment('VD企业账号表');
});
Schema::create("virtual_company_addresses", function (Blueprint $table) {
@ -189,6 +188,8 @@ class CreateBaseTables extends Migration
$table->tinyInteger('status')->unsigned()->default(0)->comment('状态 0:正常 1:禁用');
$table->timestamps();
$table->softDeletes();
$table->comment('VD企业收货地址表');
});
Schema::create("virtual_products", function (Blueprint $table) {
@ -204,6 +205,8 @@ class CreateBaseTables extends Migration
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->comment('VD企业定价表');
});
}

View File

@ -26,7 +26,7 @@ class CreateOrderTables extends Migration
foreach ($this->tables as $table_name => $table_comment) {
$table_name = $prefix . '_' . $table_name;
$table_comment = $type . $table_comment;
Schema::create($table_name, function (Blueprint $table) use ($prefix) {
Schema::create($table_name, function (Blueprint $table) use ($prefix, $table_comment) {
$table->integer('order_id')->unsigned()->default(0)->comment('订单ID');
$table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号');
@ -38,9 +38,8 @@ class CreateOrderTables extends Migration
$table->integer('counts')->unsigned()->default(1)->comment('数量');
$table->integer('unit_price')->unsigned()->default(0)->comment('单价');
$table->primary(['order_id', 'sim']);
$table->comment($table_comment);
});
db_alter($table_name, $table_comment);
}
}
}

View File

@ -23,13 +23,12 @@ class CreatePackageTables extends Migration
public function up()
{
foreach ($this->tables as $table_name => $table_comment) {
Schema::create($table_name, function (Blueprint $table) {
Schema::create($table_name, function (Blueprint $table) use ($table_comment) {
$table->integer('package_id')->unsigned()->default(0)->comment('套餐ID');
$table->bigInteger('sim')->unsigned()->default(0)->comment('SIM卡号');
$table->primary(['package_id', 'sim']);
$table->comment($table_comment);
});
db_alter($table_name, $table_comment);
}
}

View File

@ -45,9 +45,8 @@ class CreateVirtualOrdersTable extends Migration
$table->index('type');
$table->index('company_id');
$table->index('order_at');
$table->comment('VD订单');
});
db_alter("virtual_orders", "VD订单");
}
/**

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateTestsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id');
$table->string('sn', 32)->default('')->comment('编号');
$table->softDeletes();
$table->unique(['sn', 'deleted_at']);
$table->comment('测试');
$table->setIncrement(100);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('tests');
}
}

View File

@ -14,6 +14,7 @@ return array(
'CreateFailedJobsTable' => $baseDir . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
'CreateOrderTables' => $baseDir . '/database/migrations/2018_11_27_175146_create_order_tables.php',
'CreatePackageTables' => $baseDir . '/database/migrations/2018_11_27_175152_create_package_tables.php',
'CreateTestsTable' => $baseDir . '/database/migrations/2018_12_21_134548_create_tests_table.php',
'CreateVirtualOrdersTable' => $baseDir . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php',
'DatabaseSeeder' => $baseDir . '/database/seeds/DatabaseSeeder.php',
'DivisionByZeroError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',

View File

@ -717,6 +717,7 @@ class ComposerStaticInite79258a3e34ad3e251999111d9f334d9
'CreateFailedJobsTable' => __DIR__ . '/../..' . '/database/migrations/2018_11_16_190020_create_failed_jobs_table.php',
'CreateOrderTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175146_create_order_tables.php',
'CreatePackageTables' => __DIR__ . '/../..' . '/database/migrations/2018_11_27_175152_create_package_tables.php',
'CreateTestsTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_21_134548_create_tests_table.php',
'CreateVirtualOrdersTable' => __DIR__ . '/../..' . '/database/migrations/2018_12_12_170419_create_virtual_orders_table.php',
'DatabaseSeeder' => __DIR__ . '/../..' . '/database/seeds/DatabaseSeeder.php',
'DivisionByZeroError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',

View File

@ -641,18 +641,18 @@
},
{
"name": "dipper/foundation",
"version": "1.1.8",
"version_normalized": "1.1.8.0",
"version": "1.1.9",
"version_normalized": "1.1.9.0",
"source": {
"type": "git",
"url": "ssh://gogs@git.fxft.net:2222/composer/foundation.git",
"reference": "0010bd177e6a367285a6ff3401f265bc80ef32fb"
"reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0"
},
"dist": {
"type": "tar",
"url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.8-30793d.tar",
"reference": "0010bd177e6a367285a6ff3401f265bc80ef32fb",
"shasum": "6839ae4c43c3f38f4fe2ca22a1cc06b75934debd"
"url": "https://composer.fxft.online/dist/dipper/foundation/dipper-foundation-1.1.9-51f1b8.tar",
"reference": "94efaf5b1e21d1bc4f7bae4fc6c4d3f741b399d0",
"shasum": "b17959dd9990df31f7e6c3cff53749afe151f670"
},
"require": {
"barryvdh/laravel-cors": "~0.11",
@ -667,7 +667,7 @@
"league/flysystem": "~1.0",
"nesbot/carbon": "~1.21"
},
"time": "2018-12-21T03:15:03+00:00",
"time": "2018-12-21T07:43:51+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {

View File

@ -44,6 +44,8 @@ class DatabaseServiceProvider extends ServiceProvider
QueryBuilder::macro('createOrIgnore', $this->macroCreateOrIgnore());
QueryBuilder::macro('createNotExist', $this->macroCreateNotExist());
QueryBuilder::macro('updateBatch', $this->macroUpdateBatch());
SchemaBlueprint::macro('comment', $this->macroSchemaComment());
SchemaBlueprint::macro('setIncrement', $this->macroSchemaSetIncrement());
}
/**
@ -223,4 +225,28 @@ class DatabaseServiceProvider extends ServiceProvider
);
};
}
/**
* 表备注
*
* @return void
*/
public function macroSchemaComment()
{
return function ($comment) {
return $this->addCommand('comment', compact('comment'));
};
}
/**
* 自增开始
*
* @return void
*/
public function macroSchemaSetIncrement()
{
return function ($number) {
return $this->addCommand('setIncrement', compact('number'));
};
}
}

View File

@ -10,5 +10,35 @@ use Illuminate\Database\Schema\Grammars\MySqlGrammar as Grammar;
class MysqlSchemaGrammar extends Grammar
{
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileComment(Blueprint $blueprint, Fluent $command)
{
return sprintf(
"alter table %s comment '%s'",
$this->wrapTable($blueprint),
$command->comment
);
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSetIncrement(Blueprint $blueprint, Fluent $command)
{
return sprintf(
"alter table %s auto_increment %s",
$this->wrapTable($blueprint),
$command->number
);
}
}

View File

@ -10,6 +10,38 @@ use Illuminate\Database\Schema\Grammars\PostgresGrammar as Grammar;
class PostgresSchemaGrammar extends Grammar
{
/**
* Compile a create table command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileCreate(Blueprint $blueprint, Fluent $command)
{
$sql = [];
$sql[] = sprintf(
'%s table %s (%s)',
$blueprint->temporary ? 'create temporary' : 'create',
$this->wrapTable($blueprint),
implode(', ', $this->getColumns($blueprint))
);
$comments = collect($blueprint->getAddedColumns())->where('comment', '<>', '')->all();
foreach ($comments as $comment) {
$sql[] = sprintf(
"comment on column %s.%s is '%s'",
$this->wrapTable($blueprint),
$comment->name,
$comment->comment
);
}
return $sql;
}
/**
* Compile a unique key command.
*
@ -27,6 +59,39 @@ class PostgresSchemaGrammar extends Grammar
);
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileComment(Blueprint $blueprint, Fluent $command)
{
return sprintf(
"comment on table %s is '%s'",
$this->wrapTable($blueprint),
$command->comment
);
}
/**
* Compile a unique key command.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSetIncrement(Blueprint $blueprint, Fluent $command)
{
$column = collect($blueprint->getColumns())->where('autoIncrement', true)->first();
if ($column) {
$index = $this->wrap("{$blueprint->getTable()}_{$column->name}_seq");
return sprintf("select setval('%s', %d, true);", $index, $command->number);
}
}
/**
* Convert an array of column names into a delimited string.
*