Merged in migration-namespaces (pull request #1)

Make migrations namespaced: move migrations from "@Da/User/resources/migrations/*.php" to "Da\User\Migration\*.php"
This commit is contained in:
2amigos
2016-12-13 13:26:41 +01:00
7 changed files with 54 additions and 12 deletions

40
README.md Normal file
View File

@ -0,0 +1,40 @@
Migrations
==========
Add the following settings to your console application configuration file:
```php
return [
// ...
'controllerMap' => [
'migrate' => [
'class' => \yii\console\controllers\MigrateController::class,
'migrationNamespaces' => [
'Da\User\Migration',
],
],
],
// ...
];
```
This will allow you to run only a single console command:
```
./yii migrate
```
It prevents you from manual tracking of new migrations coming from our extension. What if we would add a new migration class, and you forgot to run appropriate console command to launch them?
Without namespaced migrations it would be:
```
./yii migrate
./yii migrate --migrationPath="@Da/User/resources/migrations"
```
Without namespaced migrations it's just:
```
./yii migrate
```

View File

@ -1,5 +1,4 @@
<?php <?php
namespace Da\User; namespace Da\User;
use Da\User\Helper\ClassMapHelper; use Da\User\Helper\ClassMapHelper;
@ -21,7 +20,6 @@ class Bootstrap implements BootstrapInterface
*/ */
public function bootstrap($app) public function bootstrap($app)
{ {
if ($app->hasModule('user') && $app->getModule('user') instanceof Module) { if ($app->hasModule('user') && $app->getModule('user') instanceof Module) {
$map = $this->buildClassMap($app->getModule('user')->classMap); $map = $this->buildClassMap($app->getModule('user')->classMap);
$this->initContainer($app,$map); $this->initContainer($app,$map);
@ -49,8 +47,6 @@ class Bootstrap implements BootstrapInterface
{ {
$di = Yii::$container; $di = Yii::$container;
try { try {
// events // events
$di->set(Event\FormEvent::class); $di->set(Event\FormEvent::class);
$di->set(Event\ProfileEvent::class); $di->set(Event\ProfileEvent::class);

View File

@ -1,7 +1,9 @@
<?php <?php
namespace Da\User\Migration;
use yii\db\Migration;
class m000000_000001_create_user_table extends \yii\db\Migration class m000000_000001_create_user_table extends Migration
{ {
public function up() public function up()
{ {
@ -17,10 +19,9 @@ class m000000_000001_create_user_table extends \yii\db\Migration
'confirmed_at' => $this->integer(), 'confirmed_at' => $this->integer(),
'blocked_at' => $this->integer(), 'blocked_at' => $this->integer(),
'updated_at' => $this->integer()->notNull(), 'updated_at' => $this->integer()->notNull(),
'created_at' =>$this->integer()->notNull() 'created_at' => $this->integer()->notNull()
]); ]);
$this->createIndex('idx_user_username', '{{%user}}', 'username', true); $this->createIndex('idx_user_username', '{{%user}}', 'username', true);
$this->createIndex('idx_user_email', '{{%user}}', 'email', true); $this->createIndex('idx_user_email', '{{%user}}', 'email', true);
} }

View File

@ -1,7 +1,9 @@
<?php <?php
namespace Da\User\Migration;
use yii\db\Migration;
class m000000_000002_create_profile_table extends \yii\db\Migration class m000000_000002_create_profile_table extends Migration
{ {
public function up() public function up()
{ {
@ -14,7 +16,7 @@ class m000000_000002_create_profile_table extends \yii\db\Migration
'gravatar_email' => $this->string(255), 'gravatar_email' => $this->string(255),
'gravatar_id' => $this->string(32), 'gravatar_id' => $this->string(32),
'location' => $this->string(255), 'location' => $this->string(255),
'website'=> $this->string(255), 'website' => $this->string(255),
'timezone' => $this->string(40), 'timezone' => $this->string(40),
'bio' => $this->text() 'bio' => $this->text()
] ]

View File

@ -1,7 +1,9 @@
<?php <?php
namespace Da\User\Migration;
use yii\db\Migration;
class m000000_000003_create_social_account_table extends \yii\db\Migration class m000000_000003_create_social_account_table extends Migration
{ {
public function up() public function up()
{ {

View File

@ -1,7 +1,9 @@
<?php <?php
namespace Da\User\Migration;
use yii\db\Migration;
class m000000_000004_create_token_table extends \yii\db\Migration class m000000_000004_create_token_table extends Migration
{ {
public function up() public function up()
{ {

View File

@ -1,5 +1,4 @@
<?php <?php
namespace Da\User; namespace Da\User;
use Da\User\Contracts\MailChangeStrategyInterface; use Da\User\Contracts\MailChangeStrategyInterface;