CreateMedFormFieldsTables   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 30
c 1
b 0
f 0
dl 0
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 29 3
A down() 0 9 1
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class CreateMedFormFieldsTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (!Schema::hasTable('med_form_fields')) {
17
            Schema::create('med_form_fields', function (Blueprint $table) {
18
                $table->id();
19
                $table->string('key'); 
20
                $table->unsignedBigInteger('form_id')->nullable();
21
                $table->foreign('form_id')->references('id')->on('med_forms')->onDelete('set null');
22
                $table->unsignedBigInteger('form_step_id')->nullable();
23
                $table->foreign('form_step_id')->references('id')->on('med_form_steps')->onDelete('set null');
24
                $table->string('type')->nullable();
25
                $table->boolean('is_required')->default(false);
26
                $table->boolean('is_active')->default(true);
27
                $table->integer('order')->nullable();
28
                $table->timestamps();
29
            });
30
        }
31
32
        if (!Schema::hasTable('med_form_field_translations')) {
33
            Schema::create('med_form_field_translations', function (Blueprint $table) {
34
                $table->id();
35
                $table->unsignedBigInteger('form_field_id')->nullable();
36
                $table->foreign('form_field_id')->references('id')->on('med_form_fields')->onDelete('cascade');
37
                $table->string('locale')->nullable();
38
                $table->string('label')->nullable();
39
                $table->string('placeholder')->nullable();
40
                $table->text('description')->nullable();
41
                $table->string('default_value')->nullable();
42
                $table->timestamps();
43
            });
44
        }
45
    }
46
    /**
47
     * Reverse the migrations.
48
     *
49
     * @return void
50
     */
51
    public function down()
52
    {
53
        // Drop tables in reverse order of creation to avoid foreign key constraint issues
54
        Schema::dropIfExists('med_form_field_translations');
55
        Schema::dropIfExists('med_form_fields');
56
        // You might want to review these, as they seem to be unrelated to the tables created in up()
57
        Schema::dropIfExists('med_entries');
58
        Schema::dropIfExists('med_form_translations');
59
        Schema::dropIfExists('med_forms');
60
    }
61
}
62