This commit is contained in:
Anatoliy Sablin
2020-03-22 12:12:47 +03:00
parent 072e5f66cb
commit 5baeb42623
2 changed files with 27 additions and 3 deletions

View File

@@ -81,6 +81,7 @@ public class OrmLiteSqlStorage implements IStorage {
public static class Migrations {
public static final String FIX_ACCEPTED_DAO = "2019_12_09__2254__fix_accepted_dao";
public static final String FIX_HASH_DAO_UNIQUE_INDEX = "2020_03_22__1153__fix_hash_dao_unique_index";
}
private Dao<ThreePidInviteIO, String> invDao;
@@ -127,6 +128,12 @@ public class OrmLiteSqlStorage implements IStorage {
fixAcceptedDao(connPol);
changelogDao.create(new ChangelogDao(Migrations.FIX_ACCEPTED_DAO, new Date(), "Recreate the accepted table."));
}
ChangelogDao fixHashDaoUniqueIndex = changelogDao.queryForId(Migrations.FIX_HASH_DAO_UNIQUE_INDEX);
if (fixHashDaoUniqueIndex == null) {
fixHashDaoUniqueIndex(connPol);
changelogDao
.create(new ChangelogDao(Migrations.FIX_HASH_DAO_UNIQUE_INDEX, new Date(), "Add the id and migrate the unique index."));
}
}
private void fixAcceptedDao(ConnectionSource connPool) throws SQLException {
@@ -135,6 +142,12 @@ public class OrmLiteSqlStorage implements IStorage {
TableUtils.createTableIfNotExists(connPool, AcceptedDao.class);
}
private void fixHashDaoUniqueIndex(ConnectionSource connPool) throws SQLException {
LOGGER.info("Migration: {}", Migrations.FIX_HASH_DAO_UNIQUE_INDEX);
TableUtils.dropTable(hashDao, true);
TableUtils.createTableIfNotExists(connPool, HashDao.class);
}
private <V, K> Dao<V, K> createDaoAndTable(ConnectionSource connPool, Class<V> c) throws SQLException {
return createDaoAndTable(connPool, c, false);
}

View File

@@ -6,13 +6,16 @@ import com.j256.ormlite.table.DatabaseTable;
@DatabaseTable(tableName = "hashes")
public class HashDao {
@DatabaseField(canBeNull = false, id = true)
@DatabaseField(generatedId = true)
private Long id;
@DatabaseField(canBeNull = false, uniqueCombo = true)
private String mxid;
@DatabaseField(canBeNull = false)
@DatabaseField(canBeNull = false, uniqueCombo = true)
private String medium;
@DatabaseField(canBeNull = false)
@DatabaseField(canBeNull = false, uniqueCombo = true)
private String address;
@DatabaseField(canBeNull = false)
@@ -28,6 +31,14 @@ public class HashDao {
this.hash = hash;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMxid() {
return mxid;
}