From 5f46fd2f1506148e7eafa34ab29f88ca299d889c Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 7 Oct 2018 14:53:52 +0200 Subject: Database: Don't use `0000-00-00 00:00:00` as a datetime --- db/migrations/2018_01_01_000003_fix_old_tables.php | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 db/migrations/2018_01_01_000003_fix_old_tables.php (limited to 'db/migrations') 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 @@ +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() + { + } +} -- cgit v1.2.3-54-g00ecf