Skip to content

Commit

Permalink
Merge pull request #104 from mblsolutions/AB#53749-Report-Package-Pub…
Browse files Browse the repository at this point in the history
…lish-Migrations-Conditionally--master

AB#53749 - Report Package Publish Migrations Conditionally
  • Loading branch information
hayleyberryl2s authored Nov 19, 2024
2 parents 15ad671 + 64391f9 commit c977a73
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/laravel-report-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 40 additions & 0 deletions config/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,

];
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -41,5 +40,4 @@ public function down(): void
{
Schema::dropIfExists('reports');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -36,5 +35,4 @@ public function down(): void
{
Schema::dropIfExists('report_fields');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -34,5 +33,4 @@ public function down(): void
{
Schema::dropIfExists('report_selects');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -35,5 +34,4 @@ public function down(): void
{
Schema::dropIfExists('report_joins');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -31,5 +30,4 @@ public function down(): void
{
Schema::dropIfExists('report_middleware');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -40,5 +39,4 @@ public function down(): void
{
Schema::dropIfExists('report_jobs');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -37,5 +36,4 @@ public function down(): void
{
Schema::dropIfExists('scheduled_reports');
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,4 +29,4 @@ public function down()
$table->dropColumn('admin_only');
});
}
}
};
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 8 additions & 1 deletion src/ReportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}

}
3 changes: 0 additions & 3 deletions tests/LaravelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,8 +16,6 @@

class LaravelTestCase extends OTBTestCase
{
use RefreshDatabase;

/** {@inheritdoc} **/
protected function setUp(): void
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Unit/Repositories/ScheduledReportRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

class ScheduledReportRepositoryTest extends LaravelTestCase
{
use RefreshDatabase;

protected ScheduledReportRepository $repository;

protected Report $report;
Expand Down

0 comments on commit c977a73

Please sign in to comment.