Commit 69fffed0 authored by Frantisek Simon's avatar Frantisek Simon

Remove DB migrations which are no longer needed until some other DB changes...

Remove DB migrations which are no longer needed until some other DB changes will be made. Changed directory separator replacing to "/" to reflect gradle documentation
parent 2995dcc0
......@@ -123,7 +123,7 @@ task prepareSoundAssets(dependsOn: prepareAssets) {
include '**/*.mp3'
includeEmptyDirs false
eachFile { FileCopyDetails fcd ->
fcd.setPath(fcd.getRelativePath().toString().replace(File.separator, '.'))
fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
}
outputs.upToDateWhen { false }
}.execute()
......@@ -149,7 +149,7 @@ task prepareJsonAssets(dependsOn: prepareAssets) {
include '**/*.json'
includeEmptyDirs false
eachFile { FileCopyDetails fcd ->
fcd.setPath(fcd.getRelativePath().toString().replace(File.separator, '.'))
fcd.setPath(fcd.getRelativePath().toString().replace('/', '.'))
}
outputs.upToDateWhen { false }
}.execute()
......
......@@ -137,9 +137,6 @@ public class TablexiaStorage {
}
private void MigrateData() {
UserDAO.migrateUserSignaturesData();
UserDAO.migrateUserTableStructure();
UserDAO.fixUserNames();
}
private void reset(boolean reset) {
......
......@@ -282,95 +282,6 @@ public class UserDAO {
return null;
}
//////////////////////////// DB MIGRATIONS
public static void migrateUserSignaturesData() {
String replaceSql = "update user set signature = ? where id = ?";
String conditionSql = "select id, signature from user where signature like '%\"size\"%'";
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(conditionSql);
PreparedStatement replaceStatement = TablexiaStorage.getInstance().prepareStatement(replaceSql);
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
long id = resultSet.getLong("id");
String signature = resultSet.getString("signature");
// replace old JSON structure with new one
signature = signature.replaceAll("\\{\"items\":", "");
signature = signature.replaceAll("\"x\"", "class:cz.nic.tablexia.util.Point,x");
signature = signature.replaceAll("\"y\"", "y");
signature = signature.replaceAll(",\"ordered\":true,\"size\":[0-9]+\\}|,\"size\":[0-9]+,\"ordered\":true\\}", "");
replaceStatement.setString(1, signature);
replaceStatement.setLong(2, id);
replaceStatement.addBatch();
}
statement.close();
replaceStatement.executeBatch();
replaceStatement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot migrate user signature data", e);
}
}
public static void fixUserNames() {
String replaceSql = "update user set name = ? where id = ?";
String selectSql = "select id, name from user";
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(selectSql);
PreparedStatement replaceStatement = TablexiaStorage.getInstance().prepareStatement(replaceSql);
try {
ResultSet resultSet = statement.executeQuery();
while (resultSet.next()) {
long id = resultSet.getLong("id");
String name = resultSet.getString("name").replaceAll("\\u0000", "");
replaceStatement.setString(1, name);
replaceStatement.setLong(2, id);
replaceStatement.addBatch();
}
statement.close();
replaceStatement.executeBatch();
replaceStatement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot fix user name", e);
}
}
public static void migrateUserTableStructure() {
String addUuidColumn = "ALTER TABLE user ADD COLUMN uuid TEXT";
String addSyncAtColumn = "ALTER TABLE game ADD COLUMN sync_at INTEGER";
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(addUuidColumn);
if (statement == null) {
Log.info(UserDAO.class, "uuid column in user table is already there");
} else {
try {
statement.executeUpdate();
statement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot migrate user structure: " + e.getMessage(), e);
}
}
PreparedStatement syncAtStatement = TablexiaStorage.getInstance().prepareStatement(addSyncAtColumn);
if (syncAtStatement == null) {
Log.info(UserDAO.class, "sync_at column in game table is already there");
} else {
try {
syncAtStatement.executeUpdate();
syncAtStatement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot migrate game structure: " + e.getMessage(), e);
}
}
}
//////////////////////////// EVENT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment