Skip to content

Commit 63fd503

Browse files
committed
Added creation of directory for data migrations. Assets folder refactored.
1 parent 637896c commit 63fd503

File tree

5 files changed

+54
-23
lines changed

5 files changed

+54
-23
lines changed

assets/config/data-migrations.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* @author José Lorente <[email protected]>
5+
* @license The MIT License (MIT)
6+
* @copyright José Lorente
7+
* @version 1.0
8+
*/
9+
return [
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Table
13+
|--------------------------------------------------------------------------
14+
|
15+
| The name of the table where the data migrations will be registered. Be
16+
| careful to not using the same name for the table as the normal migrations.
17+
*/
18+
'table' => 'migrations_data'
19+
];

assets/database/migrations_data/.gitkeep

Whitespace-only changes.

config/data-migrations.php

-15
This file was deleted.

src/Console/Traits/DataMigrationCommandTrait.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ trait DataMigrationCommandTrait
2424
*/
2525
protected function getMigrationPath()
2626
{
27-
return $this->laravel->databasePath() . DIRECTORY_SEPARATOR . 'data_migrations';
27+
if (!is_null($targetPath = $this->input->getOption('path'))) {
28+
return $this->laravel->basePath() . '/' . $targetPath;
29+
} else {
30+
return $this->laravel->databasePath() . DIRECTORY_SEPARATOR . 'migrations_data';
31+
}
2832
}
2933

3034
}

src/DataMigrationsServiceProvider.php

+30-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,27 @@ public function boot()
6363
{
6464
if ($this->app->runningInConsole()) {
6565
$this->registerConfig();
66+
$this->registerFolder();
6667
}
6768
}
6869

70+
/**
71+
* Registers the config file for the package.
72+
*/
6973
protected function registerConfig()
7074
{
7175
$this->publishes([
72-
__DIR__ . '/../config/data-migrations.php' => config_path('data-migrations.php'),
76+
__DIR__ . '/../assets/config/data-migrations.php' => config_path('data-migrations.php'),
77+
], 'data-migrations');
78+
}
79+
80+
/**
81+
* Registers the default folder of where the data migrations will be created.
82+
*/
83+
protected function registerFolder()
84+
{
85+
$this->publishes([
86+
__DIR__ . '/../assets/database/migrations_data' => database_path('data_migrations'),
7387
], 'data-migrations');
7488
}
7589

@@ -80,14 +94,17 @@ protected function registerConfig()
8094
*/
8195
public function register()
8296
{
83-
$this->registerRepository();
84-
$this->registerMigrator();
85-
$this->registerArtisanCommands();
97+
$this->bindRepository();
98+
$this->bindMigrator();
99+
$this->bindArtisanCommands();
86100

87101
$this->commands($this->commands);
88102
}
89103

90-
protected function registerRepository()
104+
/**
105+
* Binds the repository used by the data migrations.
106+
*/
107+
protected function bindRepository()
91108
{
92109
$this->app->singleton('migration.data.repository', function ($app) {
93110
$table = config('data-migrations.table');
@@ -96,7 +113,10 @@ protected function registerRepository()
96113
});
97114
}
98115

99-
protected function registerMigrator()
116+
/**
117+
* Binds the migrator used by the data migrations.
118+
*/
119+
protected function bindMigrator()
100120
{
101121
$this->app->singleton('migrator.data', function($app) {
102122
$repository = $app['migration.data.repository'];
@@ -105,7 +125,10 @@ protected function registerMigrator()
105125
});
106126
}
107127

108-
protected function registerArtisanCommands()
128+
/**
129+
* Binds the commands to execute the data migrations.
130+
*/
131+
protected function bindArtisanCommands()
109132
{
110133
$this->app->singleton('command.migrate-data', function ($app) {
111134
return new MigrateDataCommand($app['migrator.data']);

0 commit comments

Comments
 (0)