|
|
@@ -20,7 +20,7 @@ use UCore\ModelCore;
|
|
|
* 2. 特殊时间字段自动识别为Carbon类型
|
|
|
* 3. 支持自定义Casts类型,自动识别并使用正确的类型
|
|
|
* 4. 自动维护模型$attrlist属性包含所有字段
|
|
|
- * 5. 在模块的Databases/createsql目录下为每个表生成创建SQL文件(不包含自增属性)
|
|
|
+ * 5. 在模块的Databases/createsql目录下为每个表生成创建SQL文件(不包含当前自增值,但保留字段的自增属性)
|
|
|
* 6. 支持指定单一模块进行处理,提高效率
|
|
|
*
|
|
|
* 使用说明:
|
|
|
@@ -29,7 +29,7 @@ use UCore\ModelCore;
|
|
|
* - fillable字段标记:在模型文件中添加 attrlist start 和 attrlist end 注释块
|
|
|
* 2. 对于使用自定义Cast类的字段,会自动识别并使用Cast类作为类型
|
|
|
* 3. 可以通过指定模块名称参数,只处理特定模块的模型
|
|
|
- * 4. 生成的SQL文件中不包含AUTO_INCREMENT属性,便于在不同环境中使用
|
|
|
+ * 4. 生成的SQL文件中不包含当前AUTO_INCREMENT值,但保留字段的自增属性,便于在不同环境中使用
|
|
|
*
|
|
|
* @package UCore\Commands
|
|
|
*
|
|
|
@@ -55,7 +55,7 @@ class GenerateModelAnnotation extends Command
|
|
|
*
|
|
|
* @var string
|
|
|
*/
|
|
|
- protected $description = '生成模型property注释和表创建SQL文件(不含自增属性),支持自定义Casts类型,可指定单一模块处理';
|
|
|
+ protected $description = '生成模型property注释和表创建SQL文件(不含当前自增值,但保留字段自增属性),支持自定义Casts类型,可指定单一模块处理';
|
|
|
|
|
|
private $fillable = [];
|
|
|
|
|
|
@@ -588,11 +588,11 @@ class GenerateModelAnnotation extends Command
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取表的创建SQL语句,并移除自增属性
|
|
|
+ * 获取表的创建SQL语句,并移除表的当前自增值
|
|
|
*
|
|
|
* @param string $tableName 表名
|
|
|
* @param \Illuminate\Database\Connection $connection 数据库连接
|
|
|
- * @return string 创建表的SQL语句(不包含自增属性)
|
|
|
+ * @return string 创建表的SQL语句(不包含当前自增值,但保留字段的自增属性)
|
|
|
*/
|
|
|
protected function getCreateTableSQL($tableName, $connection)
|
|
|
{
|
|
|
@@ -601,13 +601,10 @@ class GenerateModelAnnotation extends Command
|
|
|
if (!empty($result) && isset($result[0]->{'Create Table'})) {
|
|
|
$createTableSQL = $result[0]->{'Create Table'};
|
|
|
|
|
|
- // 移除 AUTO_INCREMENT=xxx 部分
|
|
|
+ // 只移除表的当前自增值 AUTO_INCREMENT=xxx 部分,保留字段的自增属性
|
|
|
$createTableSQL = preg_replace('/\s+AUTO_INCREMENT=\d+/', '', $createTableSQL);
|
|
|
|
|
|
- // 移除字段定义中的 AUTO_INCREMENT 属性
|
|
|
- $createTableSQL = preg_replace('/\s+AUTO_INCREMENT/', '', $createTableSQL);
|
|
|
-
|
|
|
- $this->debug("已移除自增属性: " . ($createTableSQL !== $result[0]->{'Create Table'} ? "是" : "否"));
|
|
|
+ $this->debug("已移除表的当前自增值: " . ($createTableSQL !== $result[0]->{'Create Table'} ? "是" : "否"));
|
|
|
|
|
|
return $createTableSQL;
|
|
|
}
|