summaryrefslogtreecommitdiff
path: root/db/migrations/2018_01_01_000003_fix_old_tables.php
blob: 31aa15aedd0d5090bb03baf568c436ad15a650f2 (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
<?php

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

class FixOldTables extends Migration
{
    /**
     * Run the migration
     */
    public function up()
    {
        $connection = $this->schema->getConnection();

        foreach (
            [
                'User'         => 'CreateDate',
                'NewsComments' => 'Datum',
            ] as $table => $column) {
            if (!$this->schema->hasTable($table)) {
                continue;
            }

            $connection
                ->table($table)
                ->where($column, '<', '0001-01-01 00:00:00')
                ->update([$column => '0001-01-01 00:00:00']);

            $this->schema->table($table, function (Blueprint $table) use ($column) {
                $table->dateTime($column)->default('0001-01-01 00:00:00')->change();
            });
        }
    }

    /**
     * Reverse the migration
     */
    public function down()
    {
    }
}