summaryrefslogtreecommitdiff
path: root/db/migrations/2019_09_07_000001_create_schedule_shift_table.php
blob: c9cd7cfe854d9b5f0e74a519a127a9348361a246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php

namespace Engelsystem\Migrations;

use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreateScheduleShiftTable extends Migration
{
    use Reference;

    /**
     * Run the migration
     */
    public function up()
    {
        $this->schema->create(
            'schedules',
            function (Blueprint $table) {
                $table->increments('id');
                $table->string('url');
            }
        );

        $this->schema->create(
            'schedule_shift',
            function (Blueprint $table) {
                $table->integer('shift_id')->index()->unique();
                if ($this->schema->hasTable('Shifts')) {
                    // Legacy table access
                    $table->foreign('shift_id')
                        ->references('SID')->on('Shifts')
                        ->onUpdate('cascade')
                        ->onDelete('cascade');
                }

                $this->references($table, 'schedules');
                $table->uuid('guid');
            }
        );

        if ($this->schema->hasTable('Shifts')) {
            $this->schema->table(
                'Shifts',
                function (Blueprint $table) {
                    $table->dropColumn('PSID');
                }
            );
        }

        if ($this->schema->hasTable('Room')) {
            $this->schema->table(
                'Room',
                function (Blueprint $table) {
                    $table->dropColumn('from_frab');
                }
            );
        }
    }

    /**
     * Reverse the migration
     */
    public function down()
    {
        if ($this->schema->hasTable('Room')) {
            $this->schema->table(
                'Room',
                function (Blueprint $table) {
                    $table->boolean('from_frab')
                        ->default(false);
                }
            );
        }

        if ($this->schema->hasTable('Shifts')) {
            $this->schema->table(
                'Shifts',
                function (Blueprint $table) {
                    $table->integer('PSID')
                        ->nullable()->default(null)
                        ->unique();
                }
            );
        }

        $this->schema->drop('schedule_shift');
        $this->schema->drop('schedules');
    }
}