mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 03:22:51 +08:00
优化数据库迁移生成,支持decimal。
This commit is contained in:
@@ -135,7 +135,17 @@ class Migrate extends Command
|
|||||||
$column_item['type'] = $type_info[0];
|
$column_item['type'] = $type_info[0];
|
||||||
|
|
||||||
$length = substr($type_info[1], 0, strpos($type_info[1], ')'));
|
$length = substr($type_info[1], 0, strpos($type_info[1], ')'));
|
||||||
|
|
||||||
|
if (strpos($length, ',') !== false) {
|
||||||
|
|
||||||
|
$length_info = explode(',', $length);
|
||||||
|
|
||||||
|
$column_item['options']['precision'] = $length_info[0];
|
||||||
|
$column_item['options']['scale'] = $length_info[1];
|
||||||
|
} else {
|
||||||
|
|
||||||
$column_item['options']['limit'] = $length;
|
$column_item['options']['limit'] = $length;
|
||||||
|
}
|
||||||
|
|
||||||
if (strpos($type, 'unsigned') !== false) {
|
if (strpos($type, 'unsigned') !== false) {
|
||||||
// 无符号
|
// 无符号
|
||||||
@@ -183,6 +193,17 @@ class Migrate extends Command
|
|||||||
if (isset($type_map[$column_item_set['type']])) {
|
if (isset($type_map[$column_item_set['type']])) {
|
||||||
$column_item_set['type'] = $type_map[$column_item_set['type']];
|
$column_item_set['type'] = $type_map[$column_item_set['type']];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($column_item_set['options'] as $key => $option) {
|
||||||
|
|
||||||
|
if(is_array($option)){
|
||||||
|
|
||||||
|
$column_item_set['options'][$key] = "[".implode(',',$option)."]";
|
||||||
|
|
||||||
|
}else{
|
||||||
|
$column_item_set['options'][$key] = "'{$option}'";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class {$class_name} extends Migrator
|
|||||||
{
|
{
|
||||||
$table = $this->table('{$table}')
|
$table = $this->table('{$table}')
|
||||||
->setComment('{$table_info.TABLE_COMMENT}')
|
->setComment('{$table_info.TABLE_COMMENT}')
|
||||||
{volist name="table_columns" id="column"}->addColumn('{$column.field}', '{$column.type}', [{volist name="column.options" id="option"}'{$key}' => '{$option}', {/volist}])
|
{volist name="table_columns" id="column"}->addColumn('{$column.field}', '{$column.type}', [{volist name="column.options" id="option"}'{$key}' => {$option|raw}, {/volist}])
|
||||||
{/volist}
|
{/volist}
|
||||||
{volist name="table_keys_uni" id="vo"}->addIndex('{$vo}',['unique'=>true])
|
{volist name="table_keys_uni" id="vo"}->addIndex('{$vo}',['unique'=>true])
|
||||||
{/volist}
|
{/volist}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class TestGoods extends Migrator
|
|||||||
->addColumn('store_city', 'string', ['limit' => '100', 'null' => '0', 'default' => '山东省/临沂市', 'comment' => '仓库 {city} (level:city)', ])
|
->addColumn('store_city', 'string', ['limit' => '100', 'null' => '0', 'default' => '山东省/临沂市', 'comment' => '仓库 {city} (level:city)', ])
|
||||||
->addColumn('tag_input', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 (输入) {tag}', ])
|
->addColumn('tag_input', 'string', ['limit' => '100', 'null' => '0', 'comment' => '商品标签 (输入) {tag}', ])
|
||||||
->addColumn('uid', 'string', ['limit' => '100', 'null' => '0', 'comment' => '唯一id', ])
|
->addColumn('uid', 'string', ['limit' => '100', 'null' => '0', 'comment' => '唯一id', ])
|
||||||
->addColumn('price', 'decimal', ['limit' => '10,2', 'null' => '1', 'comment' => '价格',])
|
->addColumn('price', 'decimal', ['precision' => '10', 'scale' => '2', 'null' => '1', 'comment' => '价格', ])
|
||||||
->addColumn('detail', 'text', ['null' => '1', 'comment' => '详情', ])
|
->addColumn('detail', 'text', ['null' => '1', 'comment' => '详情', ])
|
||||||
->addIndex('uid',['unique'=>true])
|
->addIndex('uid',['unique'=>true])
|
||||||
->addIndex('detail',['type'=>'fulltext'])
|
->addIndex('detail',['type'=>'fulltext'])
|
||||||
|
|||||||
Reference in New Issue
Block a user