From 3b0019a516a732e1a0cdbde1d2ce58a1c96cf953 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 17 Dec 2015 15:47:18 +1300 Subject: Start Liquibase library integration --- database/db.changelog-3.0.xml | 15 +++++++++++++++ database/db.changelog-3.1.xml | 15 +++++++++++++++ database/db.changelog-3.2.xml | 15 +++++++++++++++ database/db.changelog-master.xml | 11 +++++++++++ debug.xml | 2 ++ pom.xml | 5 +++++ src/org/traccar/database/DataManager.java | 28 +++++++++++++++++++++++++++- 7 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 database/db.changelog-3.0.xml create mode 100644 database/db.changelog-3.1.xml create mode 100644 database/db.changelog-3.2.xml create mode 100644 database/db.changelog-master.xml diff --git a/database/db.changelog-3.0.xml b/database/db.changelog-3.0.xml new file mode 100644 index 000000000..b05ec6a03 --- /dev/null +++ b/database/db.changelog-3.0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/database/db.changelog-3.1.xml b/database/db.changelog-3.1.xml new file mode 100644 index 000000000..b05ec6a03 --- /dev/null +++ b/database/db.changelog-3.1.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/database/db.changelog-3.2.xml b/database/db.changelog-3.2.xml new file mode 100644 index 000000000..b05ec6a03 --- /dev/null +++ b/database/db.changelog-3.2.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/database/db.changelog-master.xml b/database/db.changelog-master.xml new file mode 100644 index 000000000..3dab44a15 --- /dev/null +++ b/database/db.changelog-master.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/debug.xml b/debug.xml index d3a869961..019c20d10 100644 --- a/debug.xml +++ b/debug.xml @@ -50,6 +50,8 @@ true false + ./database/db.changelog-master.xml + traccar diff --git a/pom.xml b/pom.xml index 3c11979c6..83e364c73 100644 --- a/pom.xml +++ b/pom.xml @@ -107,6 +107,11 @@ jersey-media-json-jackson ${jersey.version} + + org.liquibase + liquibase-core + 3.4.2 + diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 7d8966d9a..caf6d9db3 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -30,6 +30,15 @@ import java.util.HashMap; import java.util.Map; import javax.naming.InitialContext; import javax.sql.DataSource; + +import liquibase.Contexts; +import liquibase.Liquibase; +import liquibase.database.Database; +import liquibase.database.DatabaseFactory; +import liquibase.exception.DatabaseException; +import liquibase.exception.LiquibaseException; +import liquibase.resource.FileSystemResourceAccessor; +import liquibase.resource.ResourceAccessor; import org.traccar.Config; import org.traccar.helper.DriverDelegate; import org.traccar.helper.Log; @@ -147,10 +156,27 @@ public class DataManager implements IdentityManager { return query; } - private void initDatabaseSchema() throws SQLException { + private void initDatabaseSchema() throws SQLException, LiquibaseException { if (config.getString("web.type", "new").equals("new") || config.getString("web.type", "new").equals("api")) { + /*try { + ResourceAccessor resourceAccessor = new FileSystemResourceAccessor(); + + Database database = DatabaseFactory.getInstance().openDatabase( + config.getString("database.url"), + config.getString("database.user"), + config.getString("database.password"), + null, resourceAccessor); + + Liquibase liquibase = new Liquibase( + config.getString("database.changelog"), new FileSystemResourceAccessor(), database); + + liquibase.update(new Contexts()); + } catch (Exception e) { + Log.warning(e); + }*/ + boolean exist = false; try (Connection connection = dataSource.getConnection(); -- cgit v1.2.3