aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-07-08 14:25:37 +0000
committerElmar Ludwig <elmar.ludwig@uni-osnabrueck.de>2022-07-08 14:25:37 +0000
commit68d4b8dc021d8512cd76742ee882d9bb20b90eea (patch)
tree27f1fe8e7eeb9430a689b33f17764e199b38274a /lib
parent52889ffda044320275d574bde20a46d6aa88ee20 (diff)
avoid running migration twice, fixes #1265
Closes #1265 Merge request studip/studip!774
Diffstat (limited to 'lib')
-rw-r--r--lib/migrations/DatabaseMigrationTrait.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/migrations/DatabaseMigrationTrait.php b/lib/migrations/DatabaseMigrationTrait.php
new file mode 100644
index 0000000..f8fad72
--- /dev/null
+++ b/lib/migrations/DatabaseMigrationTrait.php
@@ -0,0 +1,22 @@
+<?php
+trait DatabaseMigrationTrait
+{
+ /**
+ * Returns whether a key/index with the given name exists on the given
+ * table.
+ */
+ protected function keyExists(string $table, string $key): bool
+ {
+ $query = "SHOW INDEX FROM `$table` WHERE Key_name = ?";
+ return (bool) DBManager::get()->fetchOne($query, [$key]);
+ }
+
+ /**
+ * Returns whether a column with the given name exists on the given table.
+ */
+ protected function columnExists(string $table, string $column): bool
+ {
+ $query = "SHOW COLUMNS FROM `{$table}` LIKE ?";
+ return (bool) DBManager::get()->fetchOne($query, [$column]);
+ }
+}