summaryrefslogtreecommitdiff
path: root/db/migrations
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2018-09-02 16:55:35 +0200
committerGitHub <noreply@github.com>2018-09-02 16:55:35 +0200
commita103bc06e28f5eca6ba9c28c81ae1227d689f224 (patch)
tree759d675b621eed86b20f14abe448e83fa8d22562 /db/migrations
parentbd8ceda6830f97247b73932b85ce41af5b8d2ab0 (diff)
parent2bebbeb1919e1d370ac5c0668e0db5ea63e73292 (diff)
Merge pull request #452 from MyIgel/rebuild-database
Rebuild database
Diffstat (limited to 'db/migrations')
-rw-r--r--db/migrations/2018_01_01_000001_import_install_sql.php59
-rw-r--r--db/migrations/2018_01_01_000002_import_update_sql.php27
2 files changed, 86 insertions, 0 deletions
diff --git a/db/migrations/2018_01_01_000001_import_install_sql.php b/db/migrations/2018_01_01_000001_import_install_sql.php
new file mode 100644
index 00000000..bd7ec7ae
--- /dev/null
+++ b/db/migrations/2018_01_01_000001_import_install_sql.php
@@ -0,0 +1,59 @@
+<?php
+
+use Engelsystem\Database\Migration\Migration;
+
+class ImportInstallSql extends Migration
+{
+ protected $oldTables = [
+ 'AngelTypes',
+ 'EventConfig',
+ 'GroupPrivileges',
+ 'Groups',
+ 'LogEntries',
+ 'Messages',
+ 'NeededAngelTypes',
+ 'News',
+ 'NewsComments',
+ 'Privileges',
+ 'Questions',
+ 'Room',
+ 'ShiftEntry',
+ 'Shifts',
+ 'ShiftTypes',
+ 'User',
+ 'UserAngelTypes',
+ 'UserDriverLicenses',
+ 'UserGroups',
+ ];
+
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ foreach ($this->oldTables as $table) {
+ if ($this->schema->hasTable($table)) {
+ return;
+ }
+ }
+
+ $sql = file_get_contents(__DIR__ . '/../install.sql');
+ $this->schema->getConnection()->unprepared($sql);
+ }
+
+
+ /**
+ * Reverse the migration
+ */
+ public
+ function down()
+ {
+ $this->schema->getConnection()->statement('SET FOREIGN_KEY_CHECKS=0;');
+
+ foreach ($this->oldTables as $table) {
+ if ($this->schema->hasTable($table)) {
+ $this->schema->dropIfExists($table);
+ }
+ }
+ }
+}
diff --git a/db/migrations/2018_01_01_000002_import_update_sql.php b/db/migrations/2018_01_01_000002_import_update_sql.php
new file mode 100644
index 00000000..58687d6c
--- /dev/null
+++ b/db/migrations/2018_01_01_000002_import_update_sql.php
@@ -0,0 +1,27 @@
+<?php
+
+use Engelsystem\Database\Migration\Migration;
+
+class ImportUpdateSql extends Migration
+{
+ /**
+ * Run the migration
+ */
+ public function up()
+ {
+ if ($this->schema->hasTable('UserWorkLog')) {
+ return;
+ }
+
+ $sql = file_get_contents(__DIR__ . '/../update.sql');
+ $this->schema->getConnection()->unprepared($sql);
+ }
+
+ /**
+ * Reverse the migration
+ */
+ public function down()
+ {
+ $this->schema->dropIfExists('UserWorkLog');
+ }
+}