diff options
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.java | 35 |
1 files changed, 35 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 e0721e97..c7a77882 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 @@ -15,6 +15,7 @@ public class Updater { addHasUsbAccessField(); addLogTable(); fixEmailFieldLength(); + addNetworkShares(); } private static void addLectureLocationMapTable() throws SQLException { @@ -147,4 +148,38 @@ public class Updater { throw e; } } + + private static void addNetworkShares() 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("networkshares")) { + return; // Table exists, don't do anything + } + } + // Add table + MysqlStatement tableAddStmt = connection.prepareStatement( + "CREATE TABLE `networkshare` (" + + " `shareid` int(11) NOT NULL AUTO_INCREMENT," + + " `lectureid` char(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL," + + " `shareuid` char(36) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL," + + " `sharedata` varchar(200) COLLATE utf8mb4_unicode_ci DEFAULT NULL," + + " PRIMARY KEY (`shareid`)," + + " KEY `fk_lectureid_1` (`lectureid`)" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"); + tableAddStmt.executeUpdate(); + // Add constraint + MysqlStatement constraintStmt = connection.prepareStatement( + "ALTER TABLE `networkshare` ADD CONSTRAINT `fk_lectureid_1`" + + " FOREIGN KEY (`lectureid`) REFERENCES `sat`.`lecture` (`lectureid`)" + + " ON DELETE CASCADE ON UPDATE CASCADE"); + constraintStmt.executeUpdate(); + connection.commit(); + LOGGER.info("Updated database: Added networkshare table"); + } catch (SQLException e) { + LOGGER.error("Query failed in Updater.addNetworkShares()", e); + throw e; + } + } } |