From 3ebcabf0fb5af2063ac75cf5d9c4b5b22ce619f2 Mon Sep 17 00:00:00 2001 From: Sam Lee Date: Fri, 3 Jan 2025 16:48:28 +0900 Subject: [PATCH 1/3] Avoid Laravel builtin tables --- src/Laravel/Commands/CleanCommand.php | 20 +++++++++++++++++-- .../GenerateDatabaseSeederCommand.php | 4 ++++ .../Commands/GenerateFactoriesCommand.php | 4 ++++ .../Commands/GenerateFakerSeedersCommand.php | 4 ++++ .../Commands/GenerateMigrationsCommand.php | 4 ++++ .../Commands/GenerateModelsCommand.php | 4 ++++ src/Laravel/Commands/GenerateNovaCommand.php | 4 ++++ .../Commands/GenerateRelationsCommand.php | 4 ++++ .../Commands/GenerateSeedersCommand.php | 4 ++++ src/Xeed.php | 2 ++ 10 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/Laravel/Commands/CleanCommand.php b/src/Laravel/Commands/CleanCommand.php index dd4e99a..f9e3a79 100644 --- a/src/Laravel/Commands/CleanCommand.php +++ b/src/Laravel/Commands/CleanCommand.php @@ -2,6 +2,7 @@ namespace Cable8mm\Xeed\Laravel\Commands; +use Cable8mm\Xeed\Xeed; use Illuminate\Console\Command; use Illuminate\Support\Facades\File; @@ -55,8 +56,23 @@ public function handle() } foreach ($paths as $path) { - array_map(function ($location) { - File::delete($location); + array_map(function ($location) use ($path) { + if ($path === database_path('migrations')) { + $hasLaravelDefaultTable = false; + + foreach (Xeed::LARAVEL_DEFAULT_TABLES as $table) { + if (str_contains($location, '_'.$table.'_')) { + $hasLaravelDefaultTable = true; + break; + } + } + + if (! $hasLaravelDefaultTable) { + File::delete($location); + } + } else { + File::delete($location); + } $this->info($location.' was deleted.'); }, array_filter((array) glob($path.DIRECTORY_SEPARATOR.'*.php'))); diff --git a/src/Laravel/Commands/GenerateDatabaseSeederCommand.php b/src/Laravel/Commands/GenerateDatabaseSeederCommand.php index 3aa8506..0ae3ca3 100644 --- a/src/Laravel/Commands/GenerateDatabaseSeederCommand.php +++ b/src/Laravel/Commands/GenerateDatabaseSeederCommand.php @@ -34,6 +34,10 @@ public function handle(Xeed $xeed) DB::connection()->getPDO() )->attach()->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + try { DatabaseSeederGenerator::make( $tables, diff --git a/src/Laravel/Commands/GenerateFactoriesCommand.php b/src/Laravel/Commands/GenerateFactoriesCommand.php index 44d8144..57d9826 100644 --- a/src/Laravel/Commands/GenerateFactoriesCommand.php +++ b/src/Laravel/Commands/GenerateFactoriesCommand.php @@ -38,6 +38,10 @@ public function handle(Xeed $xeed) ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { FactoryGenerator::make( diff --git a/src/Laravel/Commands/GenerateFakerSeedersCommand.php b/src/Laravel/Commands/GenerateFakerSeedersCommand.php index f94722f..6ffafac 100644 --- a/src/Laravel/Commands/GenerateFakerSeedersCommand.php +++ b/src/Laravel/Commands/GenerateFakerSeedersCommand.php @@ -48,6 +48,10 @@ public function handle(Xeed $xeed) ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { FakerSeederGenerator::make( diff --git a/src/Laravel/Commands/GenerateMigrationsCommand.php b/src/Laravel/Commands/GenerateMigrationsCommand.php index 080c394..b63af00 100644 --- a/src/Laravel/Commands/GenerateMigrationsCommand.php +++ b/src/Laravel/Commands/GenerateMigrationsCommand.php @@ -39,6 +39,10 @@ public function handle(Xeed $xeed) ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { MigrationGenerator::make( diff --git a/src/Laravel/Commands/GenerateModelsCommand.php b/src/Laravel/Commands/GenerateModelsCommand.php index 04407bc..fc14132 100644 --- a/src/Laravel/Commands/GenerateModelsCommand.php +++ b/src/Laravel/Commands/GenerateModelsCommand.php @@ -38,6 +38,10 @@ public function handle(Xeed $xeed) ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { ModelGenerator::make( diff --git a/src/Laravel/Commands/GenerateNovaCommand.php b/src/Laravel/Commands/GenerateNovaCommand.php index 7b640c3..3ee6e5e 100644 --- a/src/Laravel/Commands/GenerateNovaCommand.php +++ b/src/Laravel/Commands/GenerateNovaCommand.php @@ -37,6 +37,10 @@ public function handle(Xeed $xeed) ? Xeed::getInstance()->attach()->getTables() : Xeed::getInstance()->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { NovaResourceGenerator::make( diff --git a/src/Laravel/Commands/GenerateRelationsCommand.php b/src/Laravel/Commands/GenerateRelationsCommand.php index a98ac33..aafde85 100644 --- a/src/Laravel/Commands/GenerateRelationsCommand.php +++ b/src/Laravel/Commands/GenerateRelationsCommand.php @@ -36,6 +36,10 @@ public function handle(Xeed $xeed) $models = $this->option('models') ?? false; $tables = $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { if ($models) { diff --git a/src/Laravel/Commands/GenerateSeedersCommand.php b/src/Laravel/Commands/GenerateSeedersCommand.php index d7c1da6..91b6ca0 100644 --- a/src/Laravel/Commands/GenerateSeedersCommand.php +++ b/src/Laravel/Commands/GenerateSeedersCommand.php @@ -38,6 +38,10 @@ public function handle(Xeed $xeed) ? $xeed->addPdo(DB::connection()->getPDO())->attach()->getTables() : $xeed->addPdo(DB::connection()->getPDO())->attach($table)->getTables(); + $tables = array_filter($tables, function ($table) { + return ! in_array($table, Xeed::LARAVEL_DEFAULT_TABLES); + }); + foreach ($tables as $table) { try { SeederGenerator::make( diff --git a/src/Xeed.php b/src/Xeed.php index 48f54e2..e74b5cd 100644 --- a/src/Xeed.php +++ b/src/Xeed.php @@ -34,6 +34,8 @@ final class Xeed implements ArrayAccess */ public const AVAILABLE_DATABASES = ['mysql', 'sqlite', 'pgsql']; + public const LARAVEL_DEFAULT_TABLES = ['cache', 'cache_locks', 'failed_jobs', 'job_batches', 'jobs', 'migrations', 'password_resets', 'sessions']; + /** * @var array<\Cable8mm\Xeed\Table> Table array. */ From 92389621384c5b09c63b68b73e2c1f6ba6708aa6 Mon Sep 17 00:00:00 2001 From: Sam Lee Date: Fri, 3 Jan 2025 16:49:11 +0900 Subject: [PATCH 2/3] Add `pages-build-deployment` button in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ccda02e..6bfc4e6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![code-style](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/code-style.yml) [![run-tests](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/run-tests.yml) +[![pages-build-deployment](https://github.com/cable8mm/xeed/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/cable8mm/xeed/actions/workflows/pages/pages-build-deployment) [![Packagist Version](https://img.shields.io/packagist/v/cable8mm/xeed)](https://packagist.org/packages/cable8mm/xeed) [![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/cable8mm/xeed/php?logo=PHP&logoColor=white&color=777BB4 )](https://packagist.org/packages/cable8mm/xeed) From 1f40b7b1fbae9ce1832112a99e5d65f0223ccf9e Mon Sep 17 00:00:00 2001 From: Sam Lee Date: Fri, 3 Jan 2025 16:49:29 +0900 Subject: [PATCH 3/3] Fix a bug of `.gitattributes` --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index a94754d..8ad6578 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,7 +3,7 @@ *.md diff=markdown *.php diff=php *.php.test diff=php -/bin/colsone diff=php +/bin/console diff=php /.github export-ignore /dist export-ignore