summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--composer.json1
-rw-r--r--db/install.sql6
-rw-r--r--db/migrations/2018_01_01_000003_fix_old_tables.php41
-rw-r--r--tests/Unit/HasDatabase.php1
4 files changed, 46 insertions, 3 deletions
diff --git a/composer.json b/composer.json
index 0632bbc3..681d3ccf 100644
--- a/composer.json
+++ b/composer.json
@@ -21,6 +21,7 @@
"ext-PDO": "*",
"ext-SimpleXML": "*",
"ext-xml": "*",
+ "doctrine/dbal": "^2.8",
"erusev/parsedown": "^1.6",
"illuminate/container": "5.5.*",
"illuminate/database": "5.5.*",
diff --git a/db/install.sql b/db/install.sql
index 3c3e41e6..e1c9d579 100644
--- a/db/install.sql
+++ b/db/install.sql
@@ -205,7 +205,7 @@ DROP TABLE IF EXISTS `NewsComments`;
CREATE TABLE `NewsComments` (
`ID` bigint(11) NOT NULL,
`Refid` int(11) NOT NULL DEFAULT '0',
- `Datum` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
+ `Datum` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`Text` text NOT NULL,
`UID` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@@ -395,7 +395,7 @@ CREATE TABLE `User` (
`Sprache` char(64) NOT NULL,
`Menu` char(1) NOT NULL DEFAULT 'L',
`lastLogIn` int(11) NOT NULL,
- `CreateDate` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
+ `CreateDate` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`Art` varchar(30) DEFAULT NULL,
`kommentar` text,
`Hometown` varchar(255) NOT NULL DEFAULT '',
@@ -411,7 +411,7 @@ CREATE TABLE `User` (
--
INSERT INTO `User` (`UID`, `Nick`, `Name`, `Vorname`, `Alter`, `Telefon`, `DECT`, `Handy`, `email`, `email_shiftinfo`, `jabber`, `Size`, `Passwort`, `password_recovery_token`, `Gekommen`, `Aktiv`, `force_active`, `Tshirt`, `color`, `Sprache`, `Menu`, `lastLogIn`, `CreateDate`, `Art`, `kommentar`, `Hometown`, `api_key`, `got_voucher`, `arrival_date`, `planned_arrival_date`, `planned_departure_date`) VALUES
-(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', 1, '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 1, 0, 1, 0, 'de_DE.UTF-8', 'L', 1474990948, '0000-00-00 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235', 0, 1439490478, 1436964455, 1440161255);
+(1, 'admin', 'Gates', 'Bill', 42, '', '-', '', 'admin@example.com', 1, '', 'XL', '$6$rounds=5000$hjXbIhoRTH3vKiRa$Wl2P2iI5T9iRR.HHu/YFHswBW0WVn0yxCfCiX0Keco9OdIoDK6bIAADswP6KvMCJSwTGdV8PgA8g8Xfw5l8BD1', NULL, 1, 1, 0, 1, 0, 'de_DE.UTF-8', 'L', 1474990948, '0001-01-01 00:00:00', '', '', '', '038850abdd1feb264406be3ffa746235', 0, 1439490478, 1436964455, 1440161255);
-- --------------------------------------------------------
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()
+ {
+ }
+}
diff --git a/tests/Unit/HasDatabase.php b/tests/Unit/HasDatabase.php
index d69f0a3a..36f9fba2 100644
--- a/tests/Unit/HasDatabase.php
+++ b/tests/Unit/HasDatabase.php
@@ -40,6 +40,7 @@ trait HasDatabase
->insert([
['migration' => '2018_01_01_000001_import_install_sql'],
['migration' => '2018_01_01_000002_import_update_sql'],
+ ['migration' => '2018_01_01_000003_fix_old_tables'],
]);
$migration->run(__DIR__ . '/../../db/migrations');