From 4f095edee06a8eaeefb6d1b9ba63ed2568e8dce2 Mon Sep 17 00:00:00 2001
From: tobias <thinkdifferent055@gmail.com>
Date: Fri, 24 Feb 2017 00:27:18 +0100
Subject: [PATCH] Fixed Sql Create Statments

---
 .../de/tobias/playpad/server/PlayPadServer.scala   |  2 ++
 .../tobias/playpad/server/server/SqlHelper.scala   | 14 +++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala b/src/main/scala/de/tobias/playpad/server/PlayPadServer.scala
index 1f4b24d..242dd63 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 6eeb558..33833cb 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,
-- 
GitLab