blixem/third-party-migrations
package_schema_version table to track per-package schema states, which is critical for multi-tenant or multi-package Laravel applications where migrations must be isolated.Version0000_Install).Version0001_AddColumn).
This mirrors Laravel’s native migration conventions, easing adoption.bundles.php configuration lacks a direct Laravel equivalent. A custom service provider or package bootstrap would be needed to register the bundle’s components (e.g., migration loader, version tracker).Artisan command structure may require wrapping or extending existing migrate commands to support package-specific version checks.package_schema_version table must be manually created or migrated. Laravel’s migrations table is separate, risking potential conflicts if not synchronized.down() methods in migrations.MigrateFresh) may need customization to validate package-specific schema states.Migration Isolation:
Schema::defaultStringLength() or other global settings need to be preserved per-package?Versioning Strategy:
Version0001) align with Composer package versions or follow a custom schema?php artisan migrate:rollback) be managed for package-specific migrations?Performance:
package_schema_version table have on query performance in high-transaction environments?Tooling Integration:
migrate:status or migrate:fresh commands?Maintenance:
package_schema_version table in a multi-developer environment?Doctrine\Migrations\Configuration\Migration\PhpFile).package_schema_version table logic).migrate:package to run migrations for a specific package).doctrine/dbal).Schema::create() within package migrations to avoid Doctrine overhead, but lose cross-DB compatibility.Phase 1: Core Integration
package_schema_version table via a Laravel migration (e.g., create_package_schema_versions_table.php).ThirdPartyMigrationsServiceProvider) to:
migrate command to filter migrations by package.// app/Providers/ThirdPartyMigrationsServiceProvider.php
public function register() {
$this->app->singleton(VersionTracker::class, function () {
return new VersionTracker(new Connection($this->app['db']));
});
}
Phase 2: Package Adoption
Resources/migrations/ (e.g., Version0001_AddUserTable.php).// src/Traits/ThirdPartyMigration.php
abstract class ThirdPartyMigration extends Migration {
protected string $packageName;
protected int $version;
public function __construct(string $packageName, int $version) {
$this->packageName = $packageName;
$this->version = $version;
}
}
Phase 3: Artisan Extensions
migrate:package {package}: Run migrations for a specific package.migrate:package:status: Show version status per package.// app/Console/Commands/MigratePackage.php
protected function handle() {
$package = $this->argument('package');
$migrations = $this->getPackageMigrations($package);
// Execute migrations...
}
package.migration.running) for observability.MigrateFresh with a custom seed to reset package_schema_version:
// tests/TestCase.php
protected function setUp(): void {
parent::setUp();
$this->artisan('migrate:fresh');
$this->artisan('db:seed', ['--class' => 'PackageSchemaVersionsSeeder']);
}
php artisan migrate).package_schema_version with initial package versions (e.g., 0).php artisan migrate:package {vendor/package} to apply migrations.Version{next}_Update.php migrations.php artisan migrate:package {package} --step=1 for incremental updates.package_schema_version and migrations tables diverge. Mitigate with:
php artisan migrate:status + custom validation).// composer.json
"scripts": {
"post-install-cmd": [
"php artisan migrate:package vendor/package"
]
}
migrate:package in Laravel 11+).storage/logs/laravel.log:
// In ThirdPartyMigration class
public function up() {
Log::info("Running {$this->packageName} migration {$this->version}");
// Migration logic...
}
migrate:package:debug command to show SQL queries for a package’s migrations.vendor/package from v2.0 to v1.0, run php artisan migrate:package vendor/package down --step=1").migrate:package:rollback command with confirmation prompts.package_schema_version:
Schema::table('package_schema_version', function (Blueprint $table) {
$table->index(['package_name', 'version']);
});
Version0001_Part1, Version0001_Part2).DB::transaction(function () {
$this->versionTracker->updateVersion($package, $version);
// Run migration...
});
How can I help you explore Laravel packages today?