summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
diff options
context:
space:
mode:
authorSimon Rettberg2016-07-20 13:53:15 +0200
committerSimon Rettberg2016-07-20 13:53:15 +0200
commit25629b04334e8d0cafd00ec4c61d8e2fc2dcd649 (patch)
tree0b0010aab64b3b52a1aeaf1c6f43eb15d91edb5a /dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
parent[client] disabled UI elements for unfinished features (diff)
downloadtutor-module-25629b04334e8d0cafd00ec4c61d8e2fc2dcd649.tar.gz
tutor-module-25629b04334e8d0cafd00ec4c61d8e2fc2dcd649.tar.xz
tutor-module-25629b04334e8d0cafd00ec4c61d8e2fc2dcd649.zip
[server] Add log table; add log messages to relevant actions and events
Diffstat (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java')
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
index abb2f665..e0721e97 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/database/Updater.java
@@ -13,6 +13,7 @@ public class Updater {
addLocationPrivateField();
addLectureLocationMapTable();
addHasUsbAccessField();
+ addLogTable();
fixEmailFieldLength();
}
@@ -87,6 +88,41 @@ public class Updater {
}
}
+ private static void addLogTable() throws SQLException {
+ try (MysqlConnection connection = Database.getConnection()) {
+ MysqlStatement tablesStmt = connection.prepareStatement("SHOW TABLES");
+ ResultSet tables = tablesStmt.executeQuery();
+ while (tables.next()) {
+ if (tables.getString(1).equals("actionlog")) {
+ return; // Table exists, don't do anything
+ }
+ }
+ // Add table
+ MysqlStatement tableAddStmt = connection.prepareStatement("CREATE TABLE `actionlog` ("
+ + " `actionid` int(11) NOT NULL AUTO_INCREMENT,"
+ + " `dateline` bigint(20) NOT NULL,"
+ + " `userid` char(36) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,"
+ + " `targetid` char(36) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL,"
+ + " `description` varchar(500) NOT NULL,"
+ + " PRIMARY KEY (`actionid`),"
+ + " KEY userid (userid, dateline),"
+ + " KEY targetid (targetid, dateline),"
+ + " KEY dateline (dateline)"
+ + " ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci");
+ tableAddStmt.executeUpdate();
+ // Add constraint
+ MysqlStatement constraintStmt = connection.prepareStatement("ALTER TABLE `actionlog`"
+ + " ADD FOREIGN KEY ( `userid` ) REFERENCES `sat`.`user` (`userid`)"
+ + " ON DELETE SET NULL ON UPDATE CASCADE");
+ constraintStmt.executeUpdate();
+ connection.commit();
+ LOGGER.info("Updated database: Added actionlog table");
+ } catch (SQLException e) {
+ LOGGER.error("Query failed in Updater.addLogTable()", e);
+ throw e;
+ }
+ }
+
/**
* Make email field longer. Was 50 chars, which is not enough in rare cases
* :)