Skip to content

Commit

Permalink
Fix wrong db column type being read when migrating logging channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Aug 26, 2024
1 parent 1b83f66 commit 929f5e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/neoforged/camelot/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ static void init() throws IOException {
.callbacks(schemaMigrationCallback(14, connection -> {
LOGGER.info("Migrating logging channels from main.db to configuration.db");
try (var stmt = connection.createStatement()) {
// So uh, while the type in the table is meant to be an int, it was actually a string. The new DB also stores a string
var rs = stmt.executeQuery("select type, channel from logging_channels");
config.useExtension(LoggingChannelsDAO.class, extension -> {
while (rs.next()) {
extension.insert(rs.getLong(2), LoggingChannelsDAO.Type.values()[rs.getInt(1)]);
extension.insert(rs.getLong(2), LoggingChannelsDAO.Type.valueOf(rs.getString(1)));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.neoforged.camelot.db.transactionals;

import net.dv8tion.jda.api.entities.emoji.Emoji;
import org.jdbi.v3.core.enums.EnumByOrdinal;
import org.jdbi.v3.core.enums.EnumByName;
import org.jdbi.v3.sqlobject.statement.SqlQuery;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
import org.jdbi.v3.sqlobject.transaction.Transactional;
Expand All @@ -11,7 +11,6 @@
/**
* A transactional used to interact with {@link Type logging channels}.
*/
@EnumByOrdinal
public interface LoggingChannelsDAO extends Transactional<LoggingChannelsDAO> {

@SqlUpdate("insert into logging_channels(channel, type) values (?, ?)")
Expand All @@ -29,6 +28,7 @@ public interface LoggingChannelsDAO extends Transactional<LoggingChannelsDAO> {
@SqlQuery("select type from logging_channels where channel = ?")
List<Type> getTypesForChannel(long channelId);

@EnumByName
enum Type {
MODERATION("Moderation", "Moderation events, such as bans and warnings", "🔨"),
JOINS("Joins", "Join and leave events", "🚪"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/db/config/V1__logging_threadpings.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
create table logging_channels
(
type tinyint not null,
type text not null,
channel unsigned big int not null,
constraint logging_channels_keys primary key (type, channel)
);
Expand Down

0 comments on commit 929f5e6

Please sign in to comment.