From 0faf61f044ee91c5693a1942ac8d253ad84dd182 Mon Sep 17 00:00:00 2001 From: Antonio Ramirez Date: Sat, 10 Dec 2016 21:33:29 +0100 Subject: [PATCH] added migrations --- .../m000000_000001_create_user_table.php | 31 ++++++++++++ .../m000000_000002_create_profile_table.php | 30 ++++++++++++ ...000_000003_create_social_account_table.php | 47 +++++++++++++++++++ .../m000000_000004_create_token_table.php | 27 +++++++++++ 4 files changed, 135 insertions(+) create mode 100644 lib/User/resources/migrations/m000000_000001_create_user_table.php create mode 100644 lib/User/resources/migrations/m000000_000002_create_profile_table.php create mode 100644 lib/User/resources/migrations/m000000_000003_create_social_account_table.php create mode 100644 lib/User/resources/migrations/m000000_000004_create_token_table.php diff --git a/lib/User/resources/migrations/m000000_000001_create_user_table.php b/lib/User/resources/migrations/m000000_000001_create_user_table.php new file mode 100644 index 0000000..a7f192c --- /dev/null +++ b/lib/User/resources/migrations/m000000_000001_create_user_table.php @@ -0,0 +1,31 @@ +createTable('{{%user}}', [ + 'id' => $this->primaryKey(), + 'username' => $this->string(255)->notNull(), + 'email' => $this->string(255)->notNull(), + 'password_hash' => $this->string(60)->notNull(), + 'auth_key' => $this->string(32)->notNull(), + 'unconfirmed_email' => $this->string(255), + 'registration_id' => $this->string(45), + 'confirmed_at' => $this->integer(), + 'blocked_at' => $this->integer(), + 'updated_at' => $this->integer()->notNull(), + 'created_at' =>$this->integer()->notNull() + ]); + + + $this->createIndex('idx_user_username', '{{%user}}', 'username', true); + $this->createIndex('idx_user_email', '{{%user}}', 'email', true); + } + + public function down() + { + $this->dropTable('{{%user}}'); + } +} diff --git a/lib/User/resources/migrations/m000000_000002_create_profile_table.php b/lib/User/resources/migrations/m000000_000002_create_profile_table.php new file mode 100644 index 0000000..ee12a17 --- /dev/null +++ b/lib/User/resources/migrations/m000000_000002_create_profile_table.php @@ -0,0 +1,30 @@ +createTable( + '{{%profile}}', + [ + 'user_id' => $this->primaryKey(), + 'name' => $this->string(255), + 'public_email' => $this->string(255), + 'gravatar_email' => $this->string(255), + 'gravatar_id' => $this->string(32), + 'location' => $this->string(255), + 'website'=> $this->string(255), + 'timezone' => $this->string(40), + 'bio' => $this->text() + ] + ); + + $this->addForeignKey('fk_profile_user', '{{%profile}}', 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT'); + } + + public function down() + { + $this->dropTable('{{%profile}}'); + } +} diff --git a/lib/User/resources/migrations/m000000_000003_create_social_account_table.php b/lib/User/resources/migrations/m000000_000003_create_social_account_table.php new file mode 100644 index 0000000..58e74dd --- /dev/null +++ b/lib/User/resources/migrations/m000000_000003_create_social_account_table.php @@ -0,0 +1,47 @@ +createTable( + '{{%social_account}}', + [ + 'id' => $this->primaryKey(), + 'user_id' => $this->integer(), + 'provider' => $this->string(255)->notNull(), + 'client_id' => $this->string(255)->notNull(), + 'code' => $this->string(32), + 'email' => $this->string(255), + 'username' => $this->string(255), + 'data' => $this->text(), + 'created_at' => $this->integer() + ] + ); + + $this->createIndex( + 'idx_social_account_provider_client_id', + '{{%social_account}}', + ['provider', 'client_id'], + true + ); + + $this->createIndex('idx_social_account_code', '{{%social_account}}', 'code', true); + + $this->addForeignKey( + 'fk_social_account_user', + '{{%social_account}}', + 'user_id', + '{{%user}}', + 'id', + 'CASCADE', + 'RESTRICT' + ); + } + + public function down() + { + $this->dropTable('{{%social_account}}'); + } +} diff --git a/lib/User/resources/migrations/m000000_000004_create_token_table.php b/lib/User/resources/migrations/m000000_000004_create_token_table.php new file mode 100644 index 0000000..0fa4fce --- /dev/null +++ b/lib/User/resources/migrations/m000000_000004_create_token_table.php @@ -0,0 +1,27 @@ +createTable( + '{{%token}}', + [ + 'user_id' => $this->integer(), + 'code' => $this->string(32)->notNull(), + 'type' => $this->smallInteger(6)->notNull(), + 'created_at' => $this->integer()->notNull() + ] + ); + + $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'); + } + + public function down() + { + $this->dropTable('{{%token}}'); + } +}