fixed bug
This commit is contained in:
parent
892f8f2aad
commit
ae01ba64b2
@ -4,6 +4,8 @@ namespace catcher\generate\factory;
|
|||||||
use catcher\CatchAdmin;
|
use catcher\CatchAdmin;
|
||||||
use catcher\exceptions\FailedException;
|
use catcher\exceptions\FailedException;
|
||||||
use JaguarJack\MigrateGenerator\MigrateGenerator;
|
use JaguarJack\MigrateGenerator\MigrateGenerator;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\helper\Str;
|
||||||
|
|
||||||
|
|
||||||
class Migration extends Factory
|
class Migration extends Factory
|
||||||
@ -22,7 +24,9 @@ class Migration extends Factory
|
|||||||
|
|
||||||
$tables = $migrateGenerator->getDatabase()->getAllTables($tableName);
|
$tables = $migrateGenerator->getDatabase()->getAllTables($tableName);
|
||||||
|
|
||||||
$file = $migrationPath . date('YmdHis') . '_'. $tableName . '.php';
|
$version = date('YmdHis');
|
||||||
|
|
||||||
|
$file = $migrationPath . $version . '_'. $tableName . '.php';
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
if ($table->getName() == $tableName) {
|
if ($table->getName() == $tableName) {
|
||||||
@ -30,6 +34,16 @@ class Migration extends Factory
|
|||||||
if (!file_exists($file)) {
|
if (!file_exists($file)) {
|
||||||
throw new FailedException('migration generate failed');
|
throw new FailedException('migration generate failed');
|
||||||
}
|
}
|
||||||
|
$model = new class extends \think\Model {
|
||||||
|
protected $name = 'migrations';
|
||||||
|
};
|
||||||
|
|
||||||
|
$model->insert([
|
||||||
|
'version' => $version,
|
||||||
|
'migration_name' => Str::camel(ucfirst($tableName)),
|
||||||
|
'start_time' => date('Y-m-d H:i:s'),
|
||||||
|
'end_time' => date('Y-m-d H:i:s')
|
||||||
|
]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class SQL extends Factory
|
|||||||
$sql['type'],
|
$sql['type'],
|
||||||
$sql['length'] ? sprintf('(%s)', $sql['length']) : '',
|
$sql['length'] ? sprintf('(%s)', $sql['length']) : '',
|
||||||
$sql['unsigned'] ? 'unsigned' : '',
|
$sql['unsigned'] ? 'unsigned' : '',
|
||||||
$sql['default'] ?? '',
|
'default ' . $sql['default'],
|
||||||
$sql['nullable'] ? 'not null' : '',
|
$sql['nullable'] ? 'not null' : '',
|
||||||
$sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : ''
|
$sql['comment'] ? sprintf('comment \'%s\'', $sql['comment']) : ''
|
||||||
]) . ','. PHP_EOL;
|
]) . ','. PHP_EOL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user