fix(命令): 忽略备份表以避免在生成方案时包含它们

This commit is contained in:
augushong
2026-01-09 21:37:21 +08:00
parent 0522e2f9c3
commit 4f689d9881

View File

@@ -32,9 +32,15 @@ class Make extends Command
$allTables = Db::getTables();
// 过滤掉忽略的表
$config = Config::get('scheme.ignore_tables', []);
$prefix = Config::get('database.connections.mysql.prefix');
$connection = Config::get('database.default', 'mysql');
$prefix = Config::get('database.connections.' . $connection . '.prefix', '');
$backupPrefix = Config::get('scheme.backup_prefix', 'backup');
foreach ($allTables as $t) {
if ($this->isBackupTable($t, $prefix, $backupPrefix)) {
continue;
}
// 如果有前缀,去除前缀后再判断
$shortName = $t;
if ($prefix && str_starts_with($t, $prefix)) {
@@ -70,4 +76,15 @@ class Make extends Command
}
}
}
protected function isBackupTable(string $tableName, string $prefix, string $backupPrefix): bool
{
$basePrefix = $prefix . $backupPrefix;
if ($basePrefix === '') {
return false;
}
$pattern = '/^' . preg_quote($basePrefix, '/') . '_?\\d{14}(?:_.*)?$/';
return preg_match($pattern, $tableName) === 1;
}
}