diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-17 15:47:18 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-17 15:47:18 +1300 |
commit | 3b0019a516a732e1a0cdbde1d2ce58a1c96cf953 (patch) | |
tree | 00389392dacf9066e46c813dc5d566b1443251b4 | |
parent | 48305c4c43c79a9575cf7573990e5127bbe88950 (diff) | |
download | trackermap-server-3b0019a516a732e1a0cdbde1d2ce58a1c96cf953.tar.gz trackermap-server-3b0019a516a732e1a0cdbde1d2ce58a1c96cf953.tar.bz2 trackermap-server-3b0019a516a732e1a0cdbde1d2ce58a1c96cf953.zip |
Start Liquibase library integration
-rw-r--r-- | database/db.changelog-3.0.xml | 15 | ||||
-rw-r--r-- | database/db.changelog-3.1.xml | 15 | ||||
-rw-r--r-- | database/db.changelog-3.2.xml | 15 | ||||
-rw-r--r-- | database/db.changelog-master.xml | 11 | ||||
-rw-r--r-- | debug.xml | 2 | ||||
-rw-r--r-- | pom.xml | 5 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 28 |
7 files changed, 90 insertions, 1 deletions
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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 + http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> + + <changeSet author="authorName" id="changelog-1.0"> + <createTable tableName="TablesAndTables"> + <column name="COLUMN1" type="TEXT"> + <constraints nullable="true" primaryKey="false" unique="false"/> + </column> + </createTable> + </changeSet> +</databaseChangeLog> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 + http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> + + <changeSet author="authorName" id="changelog-1.0"> + <createTable tableName="TablesAndTables"> + <column name="COLUMN1" type="TEXT"> + <constraints nullable="true" primaryKey="false" unique="false"/> + </column> + </createTable> + </changeSet> +</databaseChangeLog> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9 + http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> + + <changeSet author="authorName" id="changelog-1.0"> + <createTable tableName="TablesAndTables"> + <column name="COLUMN1" type="TEXT"> + <constraints nullable="true" primaryKey="false" unique="false"/> + </column> + </createTable> + </changeSet> +</databaseChangeLog> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<databaseChangeLog + xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog + http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd"> + + <include file="db.changelog-3.0.xml"/> + <include file="db.changelog-3.1.xml"/> + <include file="db.changelog-3.2.xml"/> +</databaseChangeLog> @@ -50,6 +50,8 @@ <entry key='database.mock'>true</entry> <entry key='database.xml'>false</entry> + <entry key='database.changelog'>./database/db.changelog-master.xml</entry> + <entry key='database.checkTable'>traccar</entry> <entry key='database.selectSchemaVersion'> @@ -107,6 +107,11 @@ <artifactId>jersey-media-json-jackson</artifactId> <version>${jersey.version}</version> </dependency> + <dependency> + <groupId>org.liquibase</groupId> + <artifactId>liquibase-core</artifactId> + <version>3.4.2</version> + </dependency> </dependencies> <build> 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(); |