From 55aa11972305458b7b60e926138e0c5f0d7ecba3 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 18:15:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=84=9A=E6=9C=AC=E6=98=AF=E5=90=A6=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/extend/PhinxExtend.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/think-library/src/extend/PhinxExtend.php b/plugin/think-library/src/extend/PhinxExtend.php index fad065644..8efe87589 100644 --- a/plugin/think-library/src/extend/PhinxExtend.php +++ b/plugin/think-library/src/extend/PhinxExtend.php @@ -88,16 +88,19 @@ class PhinxExtend * @param \Phinx\Db\Table $table * @param array $fields 字段配置 * @param array $indexs 索引配置 + * @param boolean $force 强制更新 * @return \Phinx\Db\Table */ - public static function upgrade(Table $table, array $fields, array $indexs = []): Table + public static function upgrade(Table $table, array $fields, array $indexs = [], bool $force = false): Table { [$_exists, $_fields] = [[], array_column($fields, 0)]; if ($isExists = $table->exists()) { + // 数据表存在且不强制时退出操作 + if (empty($force)) return $table; foreach ($table->getColumns() as $column) { $_exists[] = $name = $column->getName(); if (!in_array($name, $_fields)) { - // @todo 暂时不删除字段 + // @todo 为保证数据安全暂不删字段 // $table->removeColumn($name); // $table->hasIndex($name) || $table->removeIndex($name); }