CreateFormBuilderTables::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
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 CreateFormBuilderTables extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        if (!Schema::hasTable('med_forms')) {
17
            Schema::create('med_forms', function (Blueprint $table) {
18
                $table->id();
19
                $table->uuid('uniq_id');
20
                $table->text('intro')->nullable();
21
                $table->boolean('in_database')->default(0);
22
                $table->boolean('by_mail')->default(0);
23
                $table->boolean('display_captcha')->default(0);
24
                $table->string('mail_to', 255)->nullable();
25
                $table->boolean('include_data')->default(0);
26
                $table->string('subject_admin', 255)->nullable();
27
                $table->text('message_admin')->nullable();
28
                $table->boolean('copy_user')->default(0);
29
                $table->string('field_mail_name')->nullable();
30
                $table->string('subject_user', 255)->nullable();
31
                $table->text('message_user')->nullable();
32
                $table->boolean('display_title')->default(1);
33
                $table->boolean('display_intro')->default(1);
34
                $table->boolean('display_header')->default(1);
35
                $table->boolean('display_footer')->default(1);
36
                $table->boolean('multiple_steps')->default(0);
37
                $table->json('formio_component')->nullable();
38
                $table->json('validation_rules')->nullable();
39
                $table->unsignedBigInteger('created_by')->nullable();
40
                $table->unsignedBigInteger('updated_by')->nullable();
41
                $table->timestamps();
42
            });
43
        }
44
45
        if (!Schema::hasTable('med_form_translations')) {
46
            Schema::create('med_form_translations', function (Blueprint $table) {
47
                $table->id();
48
                $table->string('title', 255)->nullable();
49
                $table->string('text_button');
50
                $table->string('slug')->nullable();
51
                $table->string('locale')->nullable();
52
                $table->text('description')->nullable();
53
                $table->text('header')->nullable();
54
                $table->text('footer')->nullable();
55
                $table->timestamps();
56
                $table->unsignedBigInteger('form_id')->nullable();
57
                $table->foreign('form_id')
58
                    ->references('id')
59
                    ->on('med_forms')
60
                    ->onDelete('cascade');
61
            });
62
        }
63
64
        if (!Schema::hasTable('med_entries')) {
65
            Schema::create('med_entries', function (Blueprint $table) {
66
                $table->id();
67
                $table->text('structure_form')->nullable();
68
                $table->text('structure_result')->nullable();
69
                $table->unsignedBigInteger('fb_form_id');
70
                $table->timestamps();
71
                $table->foreign('fb_form_id')->references('id')->on('med_forms');
72
            });
73
        }
74
    }
75
76
    /**
77
     * Reverse the migrations.
78
     *
79
     * @return void
80
     */
81
    public function down()
82
    {
83
        // Drop tables in reverse order of creation to avoid foreign key constraint issues
84
        Schema::dropIfExists('med_entries');
85
        Schema::dropIfExists('med_form_translations');
86
        Schema::dropIfExists('med_forms');
87
        Schema::dropIfExists('formbuilders');
88
    }
89
}
90