engelsystem/db/migrations/2018_01_01_000003_fix_old_t...

45 lines
1.0 KiB
PHP
Raw Normal View History

<?php
2018-10-24 13:35:31 +02:00
namespace Engelsystem\Migrations;
use Engelsystem\Database\Migration\Migration;
use Illuminate\Database\Schema\Blueprint;
class FixOldTables extends Migration
{
/**
* Run the migration
*/
public function up(): void
{
$connection = $this->schema->getConnection();
foreach (
[
'User' => 'CreateDate',
'NewsComments' => 'Datum',
2019-11-10 23:26:23 +01:00
] 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): void {
$table->dateTime($column)->default('0001-01-01 00:00:00')->change();
});
}
}
/**
* Reverse the migration
*/
public function down(): void
{
}
}