CreateMedFormStepsTables::up()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 30
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 30
rs 9.536
cc 3
nc 4
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateMedFormStepsTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
17
        if (!Schema::hasTable('med_form_steps')) {
18
            Schema::create('med_form_steps', function (Blueprint $table) {
19
                $table->id();
20
                $table->integer('order')->nullable();
21
                $table->string('key')->nullable();
22
                $table->boolean('is_active')->default(0);
23
                $table->unsignedBigInteger('form_id')->nullable();
24
                $table->foreign('form_id')
25
                ->references('id')
26
                ->on('med_forms')
27
                ->onDelete('set null');
28
                $table->timestamps();
29
            });
30
        }
31
32
        if (!Schema::hasTable('med_step_form_translations')) {
33
            Schema::create('med_form_step_translations', function (Blueprint $table) {
34
                $table->id();
35
                $table->string('title', 255)->nullable();
36
                $table->string('locale')->nullable();
37
                $table->unsignedBigInteger('form_step_id')->nullable();
38
                $table->foreign('form_step_id')
39
                    ->references('id')
40
                    ->on('med_form_steps')
41
                    ->onDelete('set null');
42
                $table->text('description')->nullable();
43
                $table->timestamps();
44
            });
45
        }
46
    }
47
48
    /**
49
     * Reverse the migrations.
50
     *
51
     * @return void
52
     */
53
    public function down()
54
    {
55
        // Drop tables in reverse order of creation to avoid foreign key constraint issues
56
        Schema::dropIfExists('med_entries');
57
        Schema::dropIfExists('med_form_translations');
58
        Schema::dropIfExists('med_forms');
59
        Schema::dropIfExists('formbuilders');
60
    }
61
}
62