Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update migrations syntax #826

Merged
merged 2 commits into from Jan 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 25 additions & 26 deletions migrations/m140209_132017_init.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

/**
* @author Dmitry Erofeev <dmeroff@gmail.com
Expand All @@ -20,23 +19,23 @@ class m140209_132017_init extends Migration
public function up()
{
$this->createTable('{{%user}}', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING . '(25) NOT NULL',
'email' => Schema::TYPE_STRING . '(255) NOT NULL',
'password_hash' => Schema::TYPE_STRING . '(60) NOT NULL',
'auth_key' => Schema::TYPE_STRING . '(32) NOT NULL',
'confirmation_token' => Schema::TYPE_STRING . '(32) NULL',
'confirmation_sent_at' => Schema::TYPE_INTEGER. ' NULL',
'confirmed_at' => Schema::TYPE_INTEGER. ' NULL',
'unconfirmed_email' => Schema::TYPE_STRING . '(255) NULL',
'recovery_token' => Schema::TYPE_STRING . '(32) NULL',
'recovery_sent_at' => Schema::TYPE_INTEGER. ' NULL',
'blocked_at' => Schema::TYPE_INTEGER. ' NULL',
'registered_from' => Schema::TYPE_INTEGER. ' NULL',
'logged_in_from' => Schema::TYPE_INTEGER. ' NULL',
'logged_in_at' => Schema::TYPE_INTEGER. ' NULL',
'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL',
'id' => $this->primaryKey(),
'username' => $this->string(25)->notNull(),
'email' => $this->string(255)->notNull(),
'password_hash' => $this->string(60)->notNull(),
'auth_key' => $this->string(32)->notNull(),
'confirmation_token' => $this->string(32)->null(),
'confirmation_sent_at' => $this->integer()->null(),
'confirmed_at' => $this->integer()->null(),
'unconfirmed_email' => $this->string(255)->null(),
'recovery_token' => $this->string(32)->null(),
'recovery_sent_at' => $this->integer()->null(),
'blocked_at' => $this->integer()->null(),
'registered_from' => $this->integer()->null(),
'logged_in_from' => $this->integer()->null(),
'logged_in_at' => $this->integer()->null(),
'created_at' => $this->integer()->notNull(),
'updated_at' => $this->integer()->notNull(),
], $this->tableOptions);

$this->createIndex('{{%user_unique_username}}', '{{%user}}', 'username', true);
Expand All @@ -45,14 +44,14 @@ public function up()
$this->createIndex('{{%user_recovery}}', '{{%user}}', 'id, recovery_token', true);

$this->createTable('{{%profile}}', [
'user_id' => Schema::TYPE_INTEGER . ' PRIMARY KEY',
'name' => Schema::TYPE_STRING . '(255) NULL',
'public_email' => Schema::TYPE_STRING . '(255) NULL',
'gravatar_email' => Schema::TYPE_STRING . '(255) NULL',
'gravatar_id' => Schema::TYPE_STRING . '(32) NULL',
'location' => Schema::TYPE_STRING . '(255) NULL',
'website' => Schema::TYPE_STRING . '(255) NULL',
'bio' => Schema::TYPE_TEXT. ' NULL',
'user_id' => $this->primaryKey(),
'name' => $this->string(255)->null(),
'public_email' => $this->string(255)->null(),
'gravatar_email' => $this->string(255)->null(),
'gravatar_id' => $this->string(32)->null(),
'location' => $this->string(255)->null(),
'website' => $this->string(255)->null(),
'bio' => $this->text()->null(),
], $this->tableOptions);

$this->addForeignKey('{{%fk_user_profile}}', '{{%profile}}', 'user_id', '{{%user}}', 'id', $this->cascade, $this->restrict);
Expand Down
11 changes: 5 additions & 6 deletions migrations/m140403_174025_create_account_table.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

/**
* @author Dmitry Erofeev <dmeroff@gmail.com
Expand All @@ -20,11 +19,11 @@ class m140403_174025_create_account_table extends Migration
public function up()
{
$this->createTable('{{%account}}', [
'id' => Schema::TYPE_PK,
'user_id' => Schema::TYPE_INTEGER. ' NULL',
'provider' => Schema::TYPE_STRING . ' NOT NULL',
'client_id' => Schema::TYPE_STRING . ' NOT NULL',
'properties' => Schema::TYPE_TEXT . ' NULL',
'id' => $this->primaryKey(),
'user_id' => $this->integer()->null(),
'provider' => $this->string()->notNull(),
'client_id' => $this->string()->notNull(),
'properties' => $this->text()->null(),
], $this->tableOptions);

$this->createIndex('{{%account_unique}}', '{{%account}}', ['provider', 'client_id'], true);
Expand Down
17 changes: 8 additions & 9 deletions migrations/m140504_113157_update_tables.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

/**
* @author Dmitry Erofeev <dmeroff@gmail.com>
Expand All @@ -29,7 +28,7 @@ public function up()
$this->dropColumn('{{%user}}', 'logged_in_from');
$this->dropColumn('{{%user}}', 'logged_in_at');
$this->renameColumn('{{%user}}', 'registered_from', 'registration_ip');
$this->addColumn('{{%user}}', 'flags', Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0');
$this->addColumn('{{%user}}', 'flags', $this->integer()->notNull()->defaultValue(0));

// account table
$this->renameColumn('{{%account}}', 'properties', 'data');
Expand All @@ -43,16 +42,16 @@ public function down()
// user table
if ($this->dbType == 'sqlsrv') {
// this is needed because we need to drop the default constraint first
$this->dropColumnConstraints('{{%user}}','flags');
$this->dropColumnConstraints('{{%user}}', 'flags');
}
$this->dropColumn('{{%user}}', 'flags');
$this->renameColumn('{{%user}}', 'registration_ip', 'registered_from');
$this->addColumn('{{%user}}', 'logged_in_at', Schema::TYPE_INTEGER);
$this->addColumn('{{%user}}', 'logged_in_from', Schema::TYPE_INTEGER);
$this->addColumn('{{%user}}', 'recovery_sent_at', Schema::TYPE_INTEGER);
$this->addColumn('{{%user}}', 'recovery_token', Schema::TYPE_STRING . '(32)');
$this->addColumn('{{%user}}', 'confirmation_sent_at', Schema::TYPE_INTEGER);
$this->addColumn('{{%user}}', 'confirmation_token', Schema::TYPE_STRING . '(32)');
$this->addColumn('{{%user}}', 'logged_in_at', $this->integer());
$this->addColumn('{{%user}}', 'logged_in_from', $this->integer());
$this->addColumn('{{%user}}', 'recovery_sent_at', $this->integer());
$this->addColumn('{{%user}}', 'recovery_token', $this->string(32));
$this->addColumn('{{%user}}', 'confirmation_sent_at', $this->integer());
$this->addColumn('{{%user}}', 'confirmation_token', $this->string(32));
$this->createIndex('{{%user_confirmation}}', '{{%user}}', 'id, confirmation_token', true);
$this->createIndex('{{%user_recovery}', '{{%user}}', 'id, recovery_token', true);
}
Expand Down
9 changes: 4 additions & 5 deletions migrations/m140504_130429_create_token_table.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

/**
* @author Dmitry Erofeev <dmeroff@gmail.com>
Expand All @@ -20,10 +19,10 @@ class m140504_130429_create_token_table extends Migration
public function up()
{
$this->createTable('{{%token}}', [
'user_id' => Schema::TYPE_INTEGER . ' NOT NULL',
'code' => Schema::TYPE_STRING . '(32) NOT NULL',
'created_at' => Schema::TYPE_INTEGER . ' NOT NULL',
'type' => Schema::TYPE_SMALLINT . ' NOT NULL',
'user_id' => $this->integer()->notNull(),
'code' => $this->string(32)->notNull(),
'created_at' => $this->integer()->notNull(),
'type' => $this->smallInteger()->notNull(),
], $this->tableOptions);

$this->createIndex('{{%token_unique}}', '{{%token}}', ['user_id', 'code', 'type'], true);
Expand Down
5 changes: 2 additions & 3 deletions migrations/m140830_171933_fix_ip_field.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

/**
* @author Dmitry Erofeev <dmeroff@gmail.com>
Expand All @@ -19,11 +18,11 @@ class m140830_171933_fix_ip_field extends Migration
{
public function up()
{
$this->alterColumn('{{%user}}', 'registration_ip', Schema::TYPE_BIGINT. ' NULL');
$this->alterColumn('{{%user}}', 'registration_ip', $this->bigInteger()->null());
}

public function down()
{
$this->alterColumn('{{%user}}', 'registration_ip', Schema::TYPE_INTEGER. ' NULL');
$this->alterColumn('{{%user}}', 'registration_ip', $this->integer()->null());
}
}
10 changes: 5 additions & 5 deletions migrations/m141222_110026_update_ip_field.php
Expand Up @@ -11,7 +11,6 @@

use dektrium\user\migrations\Migration;
use yii\db\Query;
use yii\db\Schema;

class m141222_110026_update_ip_field extends Migration
{
Expand All @@ -21,7 +20,7 @@ public function up()

$transaction = Yii::$app->db->beginTransaction();
try {
$this->alterColumn('{{%user}}', 'registration_ip', Schema::TYPE_STRING . '(45) NULL');
$this->alterColumn('{{%user}}', 'registration_ip', $this->string(45)->null());
foreach ($users as $user) {
if ($user['ip'] == null) {
continue;
Expand All @@ -44,16 +43,17 @@ public function down()
$transaction = Yii::$app->db->beginTransaction();
try {
foreach ($users as $user) {
if ($user['ip'] == null)
if ($user['ip'] == null) {
continue;
}
Yii::$app->db->createCommand()->update('{{%user}}', [
'registration_ip' => ip2long($user['ip'])
], 'id = ' . $user['id'])->execute();
}
if ($this->dbType == 'pgsql') {
$this->alterColumn('{{%user}}', 'registration_ip', Schema::TYPE_BIGINT . ' USING registration_ip::bigint');
$this->alterColumn('{{%user}}', 'registration_ip', $this->bigInteger() . ' USING registration_ip::bigint');
} else {
$this->alterColumn('{{%user}}', 'registration_ip', Schema::TYPE_BIGINT. ' NULL');
$this->alterColumn('{{%user}}', 'registration_ip', $this->bigInteger()->null());
}

$transaction->commit();
Expand Down
11 changes: 5 additions & 6 deletions migrations/m141222_135246_alter_username_length.php
Expand Up @@ -10,16 +10,15 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

class m141222_135246_alter_username_length extends Migration
{
public function up()
{
if ($this->dbType == 'sqlsrv') {
$this->dropIndex('{{%user_unique_username}}','{{%user}}');
}
$this->alterColumn('{{%user}}', 'username', Schema::TYPE_STRING . '(255) NOT NULL');
$this->dropIndex('{{%user_unique_username}}', '{{%user}}');
}
$this->alterColumn('{{%user}}', 'username', $this->string(255)->notNull());
if ($this->dbType == 'sqlsrv') {
$this->createIndex('{{%user_unique_username}}', '{{%user}}', 'username', true);
}
Expand All @@ -28,9 +27,9 @@ public function up()
public function down()
{
if ($this->dbType == 'sqlsrv') {
$this->dropIndex('{{%user_unique_username}}','{{%user}}');
$this->dropIndex('{{%user_unique_username}}', '{{%user}}');
}
$this->alterColumn('{{%user}}', 'username', Schema::TYPE_STRING . '(25) NOT NULL');
$this->alterColumn('{{%user}}', 'username', $this->string(25)->notNull());
if ($this->dbType == 'sqlsrv') {
$this->createIndex('{{%user_unique_username}}', '{{%user}}', 'username', true);
}
Expand Down
9 changes: 4 additions & 5 deletions migrations/m150614_103145_update_social_account_table.php
@@ -1,17 +1,16 @@
<?php

use yii\db\Query;
use yii\db\Schema;
use dektrium\user\migrations\Migration;

class m150614_103145_update_social_account_table extends Migration
{
public function up()
{
$this->addColumn('{{%social_account}}', 'code', Schema::TYPE_STRING . '(32) NULL');
$this->addColumn('{{%social_account}}', 'created_at', Schema::TYPE_INTEGER. ' NULL');
$this->addColumn('{{%social_account}}', 'email', Schema::TYPE_STRING. ' NULL');
$this->addColumn('{{%social_account}}', 'username', Schema::TYPE_STRING. ' NULL');
$this->addColumn('{{%social_account}}', 'code', $this->string(32)->null());
$this->addColumn('{{%social_account}}', 'created_at', $this->integer()->null());
$this->addColumn('{{%social_account}}', 'email', $this->string()->null());
$this->addColumn('{{%social_account}}', 'username', $this->string()->null());
$this->createIndex('{{%account_unique_code}}', '{{%social_account}}', 'code', true);

$accounts = (new Query())->from('{{%social_account}}')->select('id')->all();
Expand Down
13 changes: 6 additions & 7 deletions migrations/m150623_212711_fix_username_notnull.php
Expand Up @@ -10,7 +10,6 @@
*/

use dektrium\user\migrations\Migration;
use yii\db\Schema;

class m150623_212711_fix_username_notnull extends Migration
{
Expand All @@ -20,9 +19,9 @@ public function up()
$this->alterColumn('{{%user}}', 'username', 'SET NOT NULL');
} else {
if ($this->dbType == 'sqlsrv') {
$this->dropIndex('{{%user_unique_username}}','{{%user}}');
$this->dropIndex('{{%user_unique_username}}', '{{%user}}');
}
$this->alterColumn('{{%user}}', 'username', Schema::TYPE_STRING . '(255) NOT NULL');
$this->alterColumn('{{%user}}', 'username', $this->string(255)->notNull());
if ($this->dbType == 'sqlsrv') {
$this->createIndex('{{%user_unique_username}}', '{{%user}}', 'username', true);
}
Expand All @@ -31,13 +30,13 @@ public function up()

public function down()
{
if($this->dbType == "pgsql"){
if ($this->dbType == "pgsql") {
$this->alterColumn('{{%user}}', 'username', 'DROP NOT NULL');
}else{
} else {
if ($this->dbType == 'sqlsrv') {
$this->dropIndex('{{%user_unique_username}}','{{%user}}');
$this->dropIndex('{{%user_unique_username}}', '{{%user}}');
}
$this->alterColumn('{{%user}}', 'username', Schema::TYPE_STRING . '(255) NULL');
$this->alterColumn('{{%user}}', 'username', $this->string(255)->null());
if ($this->dbType == 'sqlsrv') {
$this->createIndex('{{%user_unique_username}}', '{{%user}}', 'username', true);
}
Expand Down
4 changes: 1 addition & 3 deletions migrations/m151218_234654_add_timezone_to_profile.php
Expand Up @@ -9,19 +9,17 @@
* file that was distributed with this source code.
*/

use yii\db\Schema;
use dektrium\user\migrations\Migration;

class m151218_234654_add_timezone_to_profile extends Migration
{
public function up()
{
$this->addColumn('{{%profile}}', 'timezone', Schema::TYPE_STRING . '(40) NULL');
$this->addColumn('{{%profile}}', 'timezone', $this->string(40)->null());
}

public function down()
{
$this->dropcolumn('{{%profile}}', 'timezone');
}

}