优化数据库迁移生成,支持decimal。

This commit is contained in:
2022-09-06 10:37:26 +08:00
parent b1b98c1e3a
commit 5d949d2b3d
3 changed files with 53 additions and 32 deletions

View File

@@ -135,7 +135,17 @@ class Migrate extends Command
$column_item['type'] = $type_info[0];
$length = substr($type_info[1], 0, strpos($type_info[1], ')'));
$column_item['options']['limit'] = $length;
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;
}
if (strpos($type, 'unsigned') !== false) {
// 无符号
@@ -183,6 +193,17 @@ class Migrate extends Command
if (isset($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}'";
}
}
}

View File

@@ -28,7 +28,7 @@ class {$class_name} extends Migrator
{
$table = $this->table('{$table}')
->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 name="table_keys_uni" id="vo"}->addIndex('{$vo}',['unique'=>true])
{/volist}