diff --git a/readme.md b/readme.md index 895a7ed..71d280a 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ This package is a customized version of Laravel's default database migrator, it There is no timestamp previews since the run order is based on how you register the migrations. ### Warning -This Package Supports Laravel 5.1 and 5.2, other versions may need some adjusts in order to work and are not recommended. +This Package Supports Laravel starting on 5.2 up to the latest stable version. ### Installing @@ -26,6 +26,26 @@ After installing the Package, you can now register it's provider into your confi ] ``` +And publish configuration: with + +``` +php artisan vendor:publish --provider="Migrator\MigrationServiceProvider" +``` + +### Upgrading from v1.x to v2.0. + +On v1.x, this package uses the same table name as the default migration engine. + +On version v2, there is a separate table used for tracking migrations, and it defaults to: `migrator_table` + +If you are upgrading from v1, you may either rename the `migrations` table to `migrator_table` **OR** +publish the config file and set the migrator table name to `migrations`. + +Either should work. + +v2 works alongside default migrations, for projects who want to namespace migrations +but already have many migrations in place. + ### Usage As the default Laravel migrator, this one has all the original commands, to list the available options, you can see all the available options using `php artisan` command. @@ -41,6 +61,9 @@ migrator:rollback Rollback the last database migration migrator:status Show the status of each migration ``` + + + #### Creating Migrations In order to generate an empty migration, please provide the migrator with the full qualified class name, as the example. diff --git a/resources/config/migrator.php b/resources/config/migrator.php new file mode 100644 index 0000000..0375886 --- /dev/null +++ b/resources/config/migrator.php @@ -0,0 +1,13 @@ + 'migrator_table' +]; diff --git a/src/MigrationServiceProvider.php b/src/MigrationServiceProvider.php index 0e23c90..5e5a7bd 100644 --- a/src/MigrationServiceProvider.php +++ b/src/MigrationServiceProvider.php @@ -22,6 +22,21 @@ class MigrationServiceProvider extends ServiceProvider */ protected $defer = false; + /** + * Boot the service provider. + */ + public function boot() + { + // config file path. + $configFilePath = __DIR__ . '/../resources/config/migrator.php'; + // mark the publishable file. + $this->publishes([ + $configFilePath => config_path('migrator.php'), + ]); + // merge default with custom config. + $this->mergeConfigFrom($configFilePath, 'seotools'); + } + /** * Register the service provider. * @@ -51,7 +66,8 @@ public function register() protected function registerRepository() { $this->app->singleton('migrator.repository', function ($app) { - $table = $app['config']['database.migrations']; + // try own configuration first, use default one otherwise. + $table = $app['config']['migrator.table'] ?? $app['config']['database.migrations']; return new DatabaseMigrationRepository($app['db'], $table); }); @@ -99,7 +115,7 @@ protected function registerCommands() // and register each one of them with an application container. They will // be resolved in the Artisan start file and registered on the console. foreach ($commands as $command) { - $this->{'register'.$command.'Command'}(); + $this->{'register' . $command . 'Command'}(); } // Once the commands are registered in the application IoC container we will @@ -225,10 +241,15 @@ protected function registerInstallCommand() public function provides() { return [ - 'migrator.instance', 'migrator.repository', 'command.migrator', - 'command.migrator.rollback', 'command.migrator.reset', - 'command.migrator.refresh', 'command.migrator.install', - 'command.migrator.status', 'migrator.creator', + 'migrator.instance', + 'migrator.repository', + 'command.migrator', + 'command.migrator.rollback', + 'command.migrator.reset', + 'command.migrator.refresh', + 'command.migrator.install', + 'command.migrator.status', + 'migrator.creator', 'command.migrator.make', ]; }