From 284c4639df5d98c6912bbe2c70c7dd11048c541f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 15 Oct 2024 13:50:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=A4=87=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/extend/PhinxExtend.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugin/think-library/src/extend/PhinxExtend.php b/plugin/think-library/src/extend/PhinxExtend.php index 9534849b1..fad065644 100644 --- a/plugin/think-library/src/extend/PhinxExtend.php +++ b/plugin/think-library/src/extend/PhinxExtend.php @@ -113,7 +113,7 @@ class PhinxExtend // 生成索引规则 $short = substr(md5($table->getName()), 0, 9); foreach ($indexs as $field) { - if (!$table->hasIndex($field)) { + if (empty($isExists) || !$table->hasIndex($field)) { $table->addIndex($field, ['name' => "i{$short}_{$field}"]); } } @@ -332,19 +332,18 @@ CODE; */ private static function nextFile(string $class): string { - [$fname, $versions, $startVersion] = [Str::snake($class), [], 20009999999999]; - ToolsExtend::findFilesArray(syspath('database/migrations'), function (SplFileInfo $info) use ($class, $fname, &$versions) { + [$snake, $items] = [Str::snake($class), [20010000000000]]; + ToolsExtend::findFilesArray(syspath('database/migrations'), function (SplFileInfo $info) use ($snake, &$items) { $bname = pathinfo($info->getBasename(), PATHINFO_FILENAME); - $versions[] = $version = intval(substr($bname, 0, 14)); - if ($fname === substr($bname, 15) && unlink($name = $info->getRealPath())) { - if (is_dir($dataPath = dirname($name) . DIRECTORY_SEPARATOR . $version)) { + $items[] = $version = intval(substr($bname, 0, 14)); + if ($snake === substr($bname, 15) && unlink($info->getRealPath())) { + if (is_dir($dataPath = $info->getPath() . DIRECTORY_SEPARATOR . $version)) { ToolsExtend::removeEmptyDirectory($dataPath); } } }, null, true, 1); // 计算下一个版本号 - $version = min(empty($versions) ? $startVersion : min($versions) - 1, $startVersion); - return "{$version}_{$fname}.php"; + return sprintf("%s_{$snake}.php", min($items) - 1); } } \ No newline at end of file