Fix #29.
This commit is contained in:
@@ -81,6 +81,7 @@ public class OrmLiteSqlStorage implements IStorage {
|
|||||||
|
|
||||||
public static class Migrations {
|
public static class Migrations {
|
||||||
public static final String FIX_ACCEPTED_DAO = "2019_12_09__2254__fix_accepted_dao";
|
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;
|
private Dao<ThreePidInviteIO, String> invDao;
|
||||||
@@ -127,6 +128,12 @@ public class OrmLiteSqlStorage implements IStorage {
|
|||||||
fixAcceptedDao(connPol);
|
fixAcceptedDao(connPol);
|
||||||
changelogDao.create(new ChangelogDao(Migrations.FIX_ACCEPTED_DAO, new Date(), "Recreate the accepted table."));
|
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 {
|
private void fixAcceptedDao(ConnectionSource connPool) throws SQLException {
|
||||||
@@ -135,6 +142,12 @@ public class OrmLiteSqlStorage implements IStorage {
|
|||||||
TableUtils.createTableIfNotExists(connPool, AcceptedDao.class);
|
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 {
|
private <V, K> Dao<V, K> createDaoAndTable(ConnectionSource connPool, Class<V> c) throws SQLException {
|
||||||
return createDaoAndTable(connPool, c, false);
|
return createDaoAndTable(connPool, c, false);
|
||||||
}
|
}
|
||||||
|
@@ -6,13 +6,16 @@ import com.j256.ormlite.table.DatabaseTable;
|
|||||||
@DatabaseTable(tableName = "hashes")
|
@DatabaseTable(tableName = "hashes")
|
||||||
public class HashDao {
|
public class HashDao {
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false, id = true)
|
@DatabaseField(generatedId = true)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@DatabaseField(canBeNull = false, uniqueCombo = true)
|
||||||
private String mxid;
|
private String mxid;
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false, uniqueCombo = true)
|
||||||
private String medium;
|
private String medium;
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false, uniqueCombo = true)
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
@DatabaseField(canBeNull = false)
|
@DatabaseField(canBeNull = false)
|
||||||
@@ -28,6 +31,14 @@ public class HashDao {
|
|||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getMxid() {
|
public String getMxid() {
|
||||||
return mxid;
|
return mxid;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user