diff --git a/.github/workflows/laravel-report-build-test.yml b/.github/workflows/laravel-report-build-test.yml index 97fdb1d..fc72644 100644 --- a/.github/workflows/laravel-report-build-test.yml +++ b/.github/workflows/laravel-report-build-test.yml @@ -16,8 +16,8 @@ jobs: strategy: fail-fast: true matrix: - php: ["8.0", "8.1"] - laravel: ["^9.0"] + php: ["8.2"] + laravel: ["^9.0", "^10.0"] name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/changelog.md b/changelog.md index ed058a3..dda9d41 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,8 @@ +## v5.2.0 + ++ Conditionally publish and load database migration files to prevent conflicts in table names ++ Removed class names from database migrations to prevent conflicts + ## v5.1.0 + Update dependencies to support Laravel 10 diff --git a/config/report.php b/config/report.php index fc24791..9b18177 100644 --- a/config/report.php +++ b/config/report.php @@ -193,4 +193,44 @@ 'link_expiration' => env('REPORT_LINK_EXPIRATION', 6), + /* + |-------------------------------------------------------------------------- + | Load Migrations + |-------------------------------------------------------------------------- + | + | This option controls whether the package will automatically load its + | own database migrations from its 'database/migrations' directory. + | + | When set to true, the package's migrations will be loaded and executed + | during migration commands (e.g., when you run 'php artisan migrate'). + | This is the default behavior, allowing the package to manage its + | database schema requirements seamlessly. + | + | When set to false, the package will not load its own migrations. This + | is useful in scenarios where you have published the package's migrations + | to your application's 'database/migrations' directory—perhaps to modify + | them or to prevent conflicts with existing tables. By disabling the + | automatic loading of the package's migrations, you gain full control + | over when and how these migrations are executed. + | + | Use Cases: + | - **Customizing Migrations:** If you've published and modified the + | package's migration files to suit your application's needs. + | - **Avoiding Conflicts:** If the package's migrations create tables or + | modify schemas that already exist in your database, disabling automatic + | loading prevents errors and data loss. + | - **Renaming Migrations:** If you've renamed the migration files after + | publishing them to avoid filename collisions or to enforce a specific + | migration order. + | + | **Note:** After setting this option to false, ensure that you've published + | the migrations using the package's publish command: + | 'php artisan vendor:publish --tag=report-config' + | and that they are placed in your application's 'database/migrations' directory. + | + | Default: true + | + */ + 'load_migrations' => true, + ]; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000001_create_reports_table.php b/database/migrations/2016_06_01_000001_create_reports_table.php index df53829..462ac80 100644 --- a/database/migrations/2016_06_01_000001_create_reports_table.php +++ b/database/migrations/2016_06_01_000001_create_reports_table.php @@ -4,9 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateReportsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -41,5 +40,4 @@ public function down(): void { Schema::dropIfExists('reports'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000002_create_report_fields_table.php b/database/migrations/2016_06_01_000002_create_report_fields_table.php index 2347e92..211c037 100644 --- a/database/migrations/2016_06_01_000002_create_report_fields_table.php +++ b/database/migrations/2016_06_01_000002_create_report_fields_table.php @@ -4,9 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateReportFieldsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -36,5 +35,4 @@ public function down(): void { Schema::dropIfExists('report_fields'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000003_create_report_selects_table.php b/database/migrations/2016_06_01_000003_create_report_selects_table.php index a670135..11d1c8c 100644 --- a/database/migrations/2016_06_01_000003_create_report_selects_table.php +++ b/database/migrations/2016_06_01_000003_create_report_selects_table.php @@ -4,9 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateReportSelectsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -34,5 +33,4 @@ public function down(): void { Schema::dropIfExists('report_selects'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000004_create_report_joins_table.php b/database/migrations/2016_06_01_000004_create_report_joins_table.php index 32b01ea..786a5e7 100644 --- a/database/migrations/2016_06_01_000004_create_report_joins_table.php +++ b/database/migrations/2016_06_01_000004_create_report_joins_table.php @@ -4,9 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateReportJoinsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -35,5 +34,4 @@ public function down(): void { Schema::dropIfExists('report_joins'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000005_create_report_middleware_table.php b/database/migrations/2016_06_01_000005_create_report_middleware_table.php index 989f340..2837544 100644 --- a/database/migrations/2016_06_01_000005_create_report_middleware_table.php +++ b/database/migrations/2016_06_01_000005_create_report_middleware_table.php @@ -4,9 +4,8 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class CreateReportMiddlewareTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -31,5 +30,4 @@ public function down(): void { Schema::dropIfExists('report_middleware'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000006_create_report_jobs_table.php b/database/migrations/2016_06_01_000006_create_report_jobs_table.php index 00ecd50..eacab6f 100644 --- a/database/migrations/2016_06_01_000006_create_report_jobs_table.php +++ b/database/migrations/2016_06_01_000006_create_report_jobs_table.php @@ -5,9 +5,8 @@ use Illuminate\Support\Facades\Schema; use MBLSolutions\Report\Support\Enums\JobStatus; -class CreateReportJobsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -40,5 +39,4 @@ public function down(): void { Schema::dropIfExists('report_jobs'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2016_06_01_000007_create_scheduled_reports_table.php b/database/migrations/2016_06_01_000007_create_scheduled_reports_table.php index c1a0640..858af40 100644 --- a/database/migrations/2016_06_01_000007_create_scheduled_reports_table.php +++ b/database/migrations/2016_06_01_000007_create_scheduled_reports_table.php @@ -5,9 +5,8 @@ use Illuminate\Support\Facades\Schema; use MBLSolutions\Report\Support\Enums\ReportSchedule; -class CreateScheduledReportsTable extends Migration +return new class extends Migration { - /** * Run the migrations. * @@ -37,5 +36,4 @@ public function down(): void { Schema::dropIfExists('scheduled_reports'); } - -} \ No newline at end of file +}; \ No newline at end of file diff --git a/database/migrations/2021_12_07_154926_add_admin_only_to_reports_table.php b/database/migrations/2021_12_07_154926_add_admin_only_to_reports_table.php index 0867b96..f910de8 100644 --- a/database/migrations/2021_12_07_154926_add_admin_only_to_reports_table.php +++ b/database/migrations/2021_12_07_154926_add_admin_only_to_reports_table.php @@ -4,7 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddAdminOnlyToReportsTable extends Migration +return new class extends Migration { /** * Run the migrations. @@ -29,4 +29,4 @@ public function down() $table->dropColumn('admin_only'); }); } -} +}; diff --git a/readme.md b/readme.md index 5ff981f..2555b4e 100644 --- a/readme.md +++ b/readme.md @@ -18,6 +18,12 @@ Copy the package config to your local config. php artisan vendor:publish --tag=report-config ``` +Copy the package database migrations. + +```bash +php artisan vendor:publish --tag=report-migrations +``` + Laravel Report comes with its own database migrations, once the package has been installed run the migrations. diff --git a/src/ReportServiceProvider.php b/src/ReportServiceProvider.php index 3823ea2..72efb60 100644 --- a/src/ReportServiceProvider.php +++ b/src/ReportServiceProvider.php @@ -22,6 +22,11 @@ public function boot() __DIR__ . '/../config/report.php' => config_path('report.php'), ], 'report-config'); + // Publish MBL Solutions report database migrations + $this->publishes([ + __DIR__.'/../database/migrations' => database_path('migrations'), + ], 'report-migrations'); + if ($this->app->runningInConsole()) { $this->commands([ DispatchScheduledReportsCommand::class @@ -36,7 +41,9 @@ public function boot() */ public function register() { - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + if (config('report.load_migrations', true)) { + $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + } } } \ No newline at end of file diff --git a/tests/LaravelTestCase.php b/tests/LaravelTestCase.php index 27ee1b5..a526b90 100644 --- a/tests/LaravelTestCase.php +++ b/tests/LaravelTestCase.php @@ -3,7 +3,6 @@ namespace MBLSolutions\Report\Tests; use Illuminate\Foundation\Application; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Collection; use Illuminate\Support\Str; use Maatwebsite\Excel\ExcelServiceProvider; @@ -17,8 +16,6 @@ class LaravelTestCase extends OTBTestCase { - use RefreshDatabase; - /** {@inheritdoc} **/ protected function setUp(): void { diff --git a/tests/Unit/Repositories/ScheduledReportRepositoryTest.php b/tests/Unit/Repositories/ScheduledReportRepositoryTest.php index 5cefe53..e814c23 100644 --- a/tests/Unit/Repositories/ScheduledReportRepositoryTest.php +++ b/tests/Unit/Repositories/ScheduledReportRepositoryTest.php @@ -14,8 +14,6 @@ class ScheduledReportRepositoryTest extends LaravelTestCase { - use RefreshDatabase; - protected ScheduledReportRepository $repository; protected Report $report;