Skip to content

Commit

Permalink
Merge pull request artesaos#11 from artesaos/feature/preparing-v2
Browse files Browse the repository at this point in the history
Migrator V2.0
  • Loading branch information
hernandev authored Oct 3, 2018
2 parents d29ac51 + b3775d9 commit 98ace9c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
25 changes: 24 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions resources/config/migrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php return [

/*
|--------------------------------------------------------------------------
| Artesaos\Migrator config.
|--------------------------------------------------------------------------
|
| Explicit configuration for Artesaos\Migrator
|
*/

'table' => 'migrator_table'
];
33 changes: 27 additions & 6 deletions src/MigrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
];
}
Expand Down

0 comments on commit 98ace9c

Please sign in to comment.