Fix missing unique constraint on storage_id table

This commit is contained in:
AsamK 2024-02-18 22:01:31 +01:00
parent 67fd10b978
commit cd88e896fa
2 changed files with 4 additions and 3 deletions

View file

@ -495,7 +495,7 @@ public class AccountDatabase extends Database {
CREATE TABLE storage_id (
_id INTEGER PRIMARY KEY,
type INTEGER NOT NULL,
storage_id BLOB NOT NULL
storage_id BLOB UNIQUE NOT NULL
) STRICT;
ALTER TABLE group_v1 ADD COLUMN storage_id BLOB;
ALTER TABLE group_v1 ADD COLUMN storage_record BLOB;

View file

@ -7,6 +7,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class UnknownStorageIdStore {
@ -26,7 +27,7 @@ public class UnknownStorageIdStore {
}
}
public Collection<StorageId> getUnknownStorageIds(Connection connection) throws SQLException {
public Set<StorageId> getUnknownStorageIds(Connection connection) throws SQLException {
final var sql = (
"""
SELECT s.type, s.storage_id
@ -35,7 +36,7 @@ public class UnknownStorageIdStore {
).formatted(TABLE_STORAGE_ID);
try (final var statement = connection.prepareStatement(sql)) {
try (var result = Utils.executeQueryForStream(statement, this::getStorageIdFromResultSet)) {
return result.toList();
return result.collect(Collectors.toSet());
}
}
}