Browse Source

Add migrations for upcoming Groups entity

Bubka 4 years ago
parent
commit
8dfa6d19fe

+ 32 - 0
database/migrations/2020_10_20_210129_create_groups_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateGroupsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('groups', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('groups');
+    }
+}

+ 41 - 0
database/migrations/2020_10_20_211115_add_group_id_column_to_twofaccounts_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddGroupIdColumnToTwofaccountsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::enableForeignKeyConstraints();
+
+        Schema::table('twofaccounts', function (Blueprint $table) {
+            $table->foreignId('group_id')
+                  ->after('id')
+                  ->nullable()
+                  ->constrained()
+                  ->onDelete('set null');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::disableForeignKeyConstraints();
+
+        Schema::table('twofaccounts', function (Blueprint $table) {
+            //$table->dropForeign('group_id');
+            $table->dropColumn('group_id');
+        });
+    }
+}