diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-18 22:04:13 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-12-18 22:04:13 +1300 |
commit | cfceba4f5e1e84fb1690ee95eb3c7172771e9e30 (patch) | |
tree | 1f2b77b4cc93e06e1ee28e258761f3ccca108eb3 | |
parent | 7ccf052eec0d2d71903c99bd8620c2bbfa45f311 (diff) | |
download | traccar-server-cfceba4f5e1e84fb1690ee95eb3c7172771e9e30.tar.gz traccar-server-cfceba4f5e1e84fb1690ee95eb3c7172771e9e30.tar.bz2 traccar-server-cfceba4f5e1e84fb1690ee95eb3c7172771e9e30.zip |
Add user creation to database changelog
-rw-r--r-- | database/db.changelog-3.0.xml | 8 | ||||
-rw-r--r-- | debug.xml | 1 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 58 |
3 files changed, 8 insertions, 59 deletions
diff --git a/database/db.changelog-3.0.xml b/database/db.changelog-3.0.xml index 4f94494b4..fd400ff3d 100644 --- a/database/db.changelog-3.0.xml +++ b/database/db.changelog-3.0.xml @@ -190,5 +190,13 @@ <column name="zoom" valueNumeric="0" /> </insert> + <insert tableName="user"> + <column name="name" value="admin" /> + <column name="email" value="admin" /> + <column name="hashedPassword" value="D33DCA55ABD4CC5BC76F2BC0B4E603FE2C6F61F4C1EF2D47" /> + <column name="salt" value="000000000000000000000000000000000000000000000000" /> + <column name="admin" valueBoolean="true" /> + </insert> + </changeSet> </databaseChangeLog> @@ -47,7 +47,6 @@ <entry key='database.url'>jdbc:h2:./target/database</entry> <entry key='database.user'>sa</entry> <entry key='database.password'></entry> - <entry key='database.mock'>true</entry> <entry key='database.xml'>false</entry> <entry key='database.changelog'>./database/db.changelog-master.xml</entry> diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 37cbac35d..e2e1d9f18 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -30,9 +30,7 @@ import javax.naming.InitialContext; import javax.sql.DataSource; import liquibase.Contexts; -import liquibase.LabelExpression; import liquibase.Liquibase; -import liquibase.changelog.ChangeSetStatus; import liquibase.database.Database; import liquibase.database.DatabaseFactory; import liquibase.exception.LiquibaseException; @@ -48,7 +46,6 @@ import org.traccar.model.Position; import org.traccar.model.Server; import org.traccar.model.User; import org.traccar.web.AsyncServlet; -import org.traccar.web.JsonConverter; public class DataManager implements IdentityManager { @@ -169,62 +166,7 @@ public class DataManager implements IdentityManager { Liquibase liquibase = new Liquibase( config.getString("database.changelog"), resourceAccessor, database); - boolean first = true; - for (ChangeSetStatus status : liquibase.getChangeSetStatuses(null, new LabelExpression())) { - if (!status.getWillRun()) { - first = false; - break; - } - } - liquibase.update(new Contexts()); - - if (first) { - User admin = new User(); - admin.setName("admin"); - admin.setEmail("admin"); - admin.setAdmin(true); - admin.setPassword("admin"); - addUser(admin); - - mockData(admin.getId()); - } - } - } - - private void mockData(long userId) { - if (config.getBoolean("database.mock")) { - try { - - Device device = new Device(); - device.setName("test1"); - device.setUniqueId("123456789012345"); - addDevice(device); - linkDevice(userId, device.getId()); - - Position position = new Position(); - position.setDeviceId(device.getId()); - - position.setTime(JsonConverter.parseDate("2015-05-22T12:00:01.000Z")); - position.setLatitude(-36.8785803); - position.setLongitude(174.7281713); - addPosition(position); - - position.setTime(JsonConverter.parseDate("2015-05-22T12:00:02.000Z")); - position.setLatitude(-36.8870932); - position.setLongitude(174.7473116); - addPosition(position); - - position.setTime(JsonConverter.parseDate("2015-05-22T12:00:03.000Z")); - position.setLatitude(-36.8932371); - position.setLongitude(174.7743053); - addPosition(position); - - updateLatestPosition(position); - - } catch (SQLException error) { - Log.warning(error); - } } } |