diff --git a/src/main/java/fi/lpam/dataluokat/Tietokanta.java b/src/main/java/fi/lpam/dataluokat/Tietokanta.java index d41f4ed..589d26a 100644 --- a/src/main/java/fi/lpam/dataluokat/Tietokanta.java +++ b/src/main/java/fi/lpam/dataluokat/Tietokanta.java @@ -24,26 +24,19 @@ public class Tietokanta { osoite = "jdbc:sqlite:" + tietokantatiedosto.getAbsolutePath(); - - try (Connection conn = haeYhteys()) { - InputStream is = Objects.requireNonNull(Main.class.getClassLoader().getResourceAsStream("tietokanta.sql")); - BufferedReader br = new BufferedReader(new InputStreamReader(is)); - String sql = br.readAllAsString(); - - for (String query : sql.split(";")) { - conn.createStatement().execute(query); - } - } - catch (SQLException | IOException e) { - handleException(e); + String sql = ""; + try (BufferedReader br = new BufferedReader( + new InputStreamReader( + Objects.requireNonNull(Main.class.getClassLoader() + .getResourceAsStream("tietokanta.sql"))))) { + sql = br.readAllAsString(); + } catch (IOException e) { + throw new RuntimeException(e); } - //Lisää kuljetuspäivät asiakassarakkeeseen (v2.0.2->3.x.x) - String[] sarakkeet = {"lauantaiKpl", "sunnuntaiKpl"}; - for (String sarake : sarakkeet) { + for (String query : sql.split(";")) { try (Connection conn = haeYhteys()) { - PreparedStatement stmt = conn.prepareStatement("alter table asiakkaat add column " + sarake + " int not null default 0"); - stmt.execute(); + conn.createStatement().execute(query); } catch (SQLException e) { if (!e.getMessage().contains("duplicate column name")) { handleException(e); diff --git a/src/main/resources/tietokanta.sql b/src/main/resources/tietokanta.sql index 9cdf382..eb708ef 100644 --- a/src/main/resources/tietokanta.sql +++ b/src/main/resources/tietokanta.sql @@ -40,4 +40,11 @@ create table if not exists kuljetukset ( lisätieto varchar(255) ); -create index if not exists idx_kuljetuspvm on kuljetukset(kuljetusPäivämäärä); \ No newline at end of file +create index if not exists idx_kuljetuspvm on kuljetukset(kuljetusPäivämäärä); + +--2.0.2->3.x.x +alter table asiakkaat add lauantaiKpl int not null default 0; +alter table asiakkaat add sunnuntaiKpl int not null default 0; + +--3.x.x->4.0.0 +alter table kuljetukset add tyyppi varchar(50); \ No newline at end of file