From 7e0d58200f31157d6f822e58936a39cea4b7b23a Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sat, 15 Sep 2018 20:57:26 +0100 Subject: [PATCH] Table creation on longer tries to occur if it already exists. --- .gitignore | 3 ++- .../java/uk/co/neviyn/Observations/dao/ObservationDao.java | 4 ++-- .../src/main/java/uk/co/neviyn/Observations/dao/SiteDao.java | 2 +- .../src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index e83e4e2..693ced2 100644 --- a/.gitignore +++ b/.gitignore @@ -191,4 +191,5 @@ typings/ backend/src/main/resources/assets frontend/node !maven-wrapper.jar -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml +*.db \ No newline at end of file diff --git a/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java b/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java index 61dd3d8..a719344 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/dao/ObservationDao.java @@ -13,12 +13,12 @@ import uk.co.neviyn.Observations.core.Observation; @RegisterRowMapper(Observation.Mapper.class) public interface ObservationDao { - @SqlUpdate("CREATE TABLE observations (id INTEGER PRIMARY KEY AUTO_INCREMENT, siteId INTEGER, tutorManyId INTEGER, " + + @SqlUpdate("CREATE TABLE IF NOT EXISTS observations (id INTEGER PRIMARY KEY, siteId INTEGER, tutorManyId INTEGER, " + "observed TEXT, monitoring INTEGER, control INTEGER, conservatism INTEGER, teamwork INTEGER, knowledge INTEGER, " + "rawData TEXT, date DATE)") void createObservationTable(); - @SqlUpdate("CREATE TABLE observation_tutor (tutorId INT NOT NULL, observationId INT NOT NULL, " + + @SqlUpdate("CREATE TABLE IF NOT EXISTS observation_tutor (tutorId INT NOT NULL, observationId INT NOT NULL, " + "FOREIGN KEY (tutorID) REFERENCES tutor(id), FOREIGN KEY (observationId) REFERENCES observations(id))") void createObservationTutorTable(); diff --git a/backend/src/main/java/uk/co/neviyn/Observations/dao/SiteDao.java b/backend/src/main/java/uk/co/neviyn/Observations/dao/SiteDao.java index 12b2843..a682c4e 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/dao/SiteDao.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/dao/SiteDao.java @@ -10,7 +10,7 @@ import uk.co.neviyn.Observations.core.Site; @RegisterRowMapper(Site.Mapper.class) public interface SiteDao { - @SqlUpdate("CREATE TABLE site (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100))") + @SqlUpdate("CREATE TABLE IF NOT EXISTS site (id INTEGER PRIMARY KEY, name VARCHAR(100))") void createSiteTable(); @SqlQuery("SELECT * FROM site") diff --git a/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java b/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java index f47d06e..a9ba41f 100644 --- a/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java +++ b/backend/src/main/java/uk/co/neviyn/Observations/dao/TutorDao.java @@ -12,7 +12,7 @@ import uk.co.neviyn.Observations.core.Tutor; @RegisterRowMapper(Tutor.Mapper.class) public interface TutorDao { - @SqlUpdate("CREATE TABLE tutor (id INTEGER PRIMARY KEY AUTO_INCREMENT, " + + @SqlUpdate("CREATE TABLE IF NOT EXISTS tutor (id INTEGER PRIMARY KEY, " + "name VARCHAR(100), site INT, FOREIGN KEY (site) REFERENCES site(id))") void createTutorTable();