diff --git a/src/User/Helper/MigrationHelper.php b/src/User/Helper/MigrationHelper.php new file mode 100644 index 0000000..e4d76bb --- /dev/null +++ b/src/User/Helper/MigrationHelper.php @@ -0,0 +1,59 @@ + $this->integer(), 'updated_at' => $this->integer()->notNull(), 'created_at' => $this->integer()->notNull(), - ] + ], + MigrationHelper::resolveTableOptions($this->db->driverName) ); $this->createIndex('idx_user_username', '{{%user}}', 'username', true); diff --git a/src/User/Migration/m000000_000002_create_profile_table.php b/src/User/Migration/m000000_000002_create_profile_table.php index 18c1a7d..3f20778 100644 --- a/src/User/Migration/m000000_000002_create_profile_table.php +++ b/src/User/Migration/m000000_000002_create_profile_table.php @@ -11,6 +11,7 @@ namespace Da\User\Migration; +use Da\User\Helper\MigrationHelper; use yii\db\Migration; class m000000_000002_create_profile_table extends Migration @@ -29,10 +30,13 @@ class m000000_000002_create_profile_table extends Migration 'website' => $this->string(255), 'timezone' => $this->string(40), 'bio' => $this->text(), - ] + ], + MigrationHelper::resolveTableOptions($this->db->driverName) ); - $this->addForeignKey('fk_profile_user', '{{%profile}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT'); + $restrict = MigrationHelper::isMicrosoftSQLServer($this->db->driverName) ? 'NO ACTION' : 'RESTRICT'; + + $this->addForeignKey('fk_profile_user', '{{%profile}}', 'user_id', '{{%user}}', 'id', 'CASCADE', $restrict); } public function down() diff --git a/src/User/Migration/m000000_000003_create_social_account_table.php b/src/User/Migration/m000000_000003_create_social_account_table.php index 9ca299e..feb87fb 100644 --- a/src/User/Migration/m000000_000003_create_social_account_table.php +++ b/src/User/Migration/m000000_000003_create_social_account_table.php @@ -11,6 +11,7 @@ namespace Da\User\Migration; +use Da\User\Helper\MigrationHelper; use yii\db\Migration; class m000000_000003_create_social_account_table extends Migration @@ -29,7 +30,8 @@ class m000000_000003_create_social_account_table extends Migration 'username' => $this->string(255), 'data' => $this->text(), 'created_at' => $this->integer(), - ] + ], + MigrationHelper::resolveTableOptions($this->db->driverName) ); $this->createIndex( @@ -48,7 +50,7 @@ class m000000_000003_create_social_account_table extends Migration '{{%user}}', 'id', 'CASCADE', - 'RESTRICT' + (MigrationHelper::isMicrosoftSQLServer($this->db->driverName) ? 'NO ACTION' : 'RESTRICT') ); } diff --git a/src/User/Migration/m000000_000004_create_token_table.php b/src/User/Migration/m000000_000004_create_token_table.php index 05184e4..10aeb51 100644 --- a/src/User/Migration/m000000_000004_create_token_table.php +++ b/src/User/Migration/m000000_000004_create_token_table.php @@ -11,6 +11,7 @@ namespace Da\User\Migration; +use Da\User\Helper\MigrationHelper; use yii\db\Migration; class m000000_000004_create_token_table extends Migration @@ -24,12 +25,15 @@ class m000000_000004_create_token_table extends Migration 'code' => $this->string(32)->notNull(), 'type' => $this->smallInteger(6)->notNull(), 'created_at' => $this->integer()->notNull(), - ] + ], + MigrationHelper::resolveTableOptions($this->db->driverName) ); $this->createIndex('idx_token_user_id_code_type', '{{%token}}', ['user_id', 'code', 'type'], true); - $this->addForeignKey('fk_token_user', '{{%token}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT'); + $restrict = MigrationHelper::isMicrosoftSQLServer($this->db->driverName) ? 'NO ACTION' : 'RESTRICT'; + + $this->addForeignKey('fk_token_user', '{{%token}}', 'user_id', '{{%user}}', 'id', 'CASCADE', $restrict); } public function down()