diff --git a/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala b/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala index 1f4b24dda8f0934a467d7d854a8f67ea59998f62..242dd63c08e2efe99b184cf2980e50cd454225b4 100644 --- a/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala +++ b/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala @@ -8,6 +8,7 @@ import com.j256.ormlite.jdbc.JdbcConnectionSource import com.j256.ormlite.table.TableUtils import de.tobias.playpad.server.account.{Account, Session} import de.tobias.playpad.server.plugin.Plugin +import de.tobias.playpad.server.server.SqlHelper import de.tobias.playpad.server.server.account._ import de.tobias.playpad.server.server.plugin.{PluginGet, PluginList} import de.tobias.playpad.server.server.project._ @@ -47,6 +48,7 @@ object PlayPadServer extends App { TableUtils.createTableIfNotExists(connectionSource, classOf[Plugin]) TableUtils.createTableIfNotExists(connectionSource, classOf[Account]) TableUtils.createTableIfNotExists(connectionSource, classOf[Session]) + SqlHelper.createTables(databaseConnection) // Setup Http Server port(8090) diff --git a/src/main/scala/de/tobias/playpad/server/server/SqlHelper.scala b/src/main/scala/de/tobias/playpad/server/server/SqlHelper.scala index 6eeb5582e0c2df8b90d9d4b852ef347b65688627..33833cb54a0bf3f040befa1e5c36bc2d8af62ffa 100644 --- a/src/main/scala/de/tobias/playpad/server/server/SqlHelper.scala +++ b/src/main/scala/de/tobias/playpad/server/server/SqlHelper.scala @@ -76,7 +76,7 @@ object SqlHelper { } createTable( - """CREATE TABLE `Project` ( + """CREATE TABLE IF NOT EXISTS `Project` ( | `id` varchar(48) NOT NULL DEFAULT '', | `name` varchar(255) DEFAULT NULL, | `account_id` int(11) DEFAULT NULL, @@ -84,28 +84,28 @@ object SqlHelper { | UNIQUE KEY `id` (`id`) |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) createTable( - """CREATE TABLE `Page` ( + """CREATE TABLE IF NOT EXISTS `Page` ( | `id` varchar(48) NOT NULL DEFAULT '', | `name` varchar(255) DEFAULT NULL, | `position` int(11) DEFAULT NULL, | `project_id` varchar(48) DEFAULT NULL, | PRIMARY KEY (`id`), - | UNIQUE KEY `id` (`id`) + | UNIQUE KEY `id` (`id`), | CONSTRAINT `Page_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `Project` (`id`) ON DELETE CASCADE |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) createTable( - """CREATE TABLE `Pad` ( + """CREATE TABLE IF NOT EXISTS `Pad` ( | `id` varchar(48) NOT NULL DEFAULT '', | `name` varchar(255) DEFAULT NULL, | `position` int(11) DEFAULT NULL, | `page` int(11) DEFAULT NULL, | `page_id` varchar(48) DEFAULT NULL, | PRIMARY KEY (`id`), - | UNIQUE KEY `id` (`id`) + | UNIQUE KEY `id` (`id`), | CONSTRAINT `Pad_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `Page` (`id`) ON DELETE CASCADE |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) createTable( - """CREATE TABLE `Path` ( + """CREATE TABLE IF NOT EXISTS `Path` ( | `id` varchar(40) NOT NULL DEFAULT '', | `path` text, | `pad_id` varchar(40) DEFAULT NULL, @@ -114,7 +114,7 @@ object SqlHelper { | CONSTRAINT `Path_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) createTable( - """CREATE TABLE `Design` ( + """CREATE TABLE IF NOT EXISTS `Design` ( | `id` varchar(40) NOT NULL DEFAULT '', | `background_color` varchar(20) DEFAULT NULL, | `play_color` varchar(20) DEFAULT NULL,