summaryrefslogtreecommitdiff
path: root/db/migrations/2018_01_01_000003_fix_old_tables.php
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrations/2018_01_01_000003_fix_old_tables.php')
-rw-r--r--db/migrations/2018_01_01_000003_fix_old_tables.php41
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()
+ {
+ }
+}