diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-10-07 14:53:52 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-10-24 19:15:07 +0200 |
commit | 5f46fd2f1506148e7eafa34ab29f88ca299d889c (patch) | |
tree | 0e8b5b245b6a34141b5f1211ef870f499fa8d2ae /db/migrations | |
parent | b46207f91176cf944284c01c213d3f69075377a4 (diff) |
Database: Don't use `0000-00-00 00:00:00` as a datetime
Diffstat (limited to 'db/migrations')
-rw-r--r-- | db/migrations/2018_01_01_000003_fix_old_tables.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/db/migrations/2018_01_01_000003_fix_old_tables.php b/db/migrations/2018_01_01_000003_fix_old_tables.php new file mode 100644 index 00000000..31aa15ae --- /dev/null +++ b/db/migrations/2018_01_01_000003_fix_old_tables.php @@ -0,0 +1,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() + { + } +} |