summaryrefslogtreecommitdiff
path: root/db/migrations/2018_12_21_000000_change_users_contact_dect_field_size.php
blob: 0478b13870ed011f420a332cb747686b6ce65ad4 (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
<?php

namespace Engelsystem\Migrations;

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

class ChangeUsersContactDectFieldSize extends Migration
{
    /** @var array */
    protected $tables = [
        'AngelTypes'    => 'contact_dect',
        'users_contact' => 'dect',
    ];

    /**
     * Run the migration
     */
    public function up()
    {
        $this->changeDectTo(40);
    }

    /**
     * Reverse the migration
     */
    public function down()
    {
        $this->changeDectTo(5);
    }

    /**
     * @param int $length
     */
    protected function changeDectTo(int $length)
    {
        foreach ($this->tables as $table => $column) {
            if (!$this->schema->hasTable($table)) {
                continue;
            }

            $this->schema->table($table, function (Blueprint $table) use ($column, $length) {
                $table->string($column, $length)->change();
            });
        }
    }
}