Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.confuser.banmanager.common.commands.CommonCommand;
import me.confuser.banmanager.common.configs.Config;
import me.confuser.banmanager.common.configs.PluginInfo;
import me.confuser.banmanager.common.storage.migration.MigrationRunner;
import me.confuser.banmanager.webenhancer.common.commands.PinCommand;
import me.confuser.banmanager.webenhancer.common.configs.DefaultConfig;
import me.confuser.banmanager.webenhancer.common.configs.MessagesConfig;
Expand Down Expand Up @@ -55,6 +56,15 @@ public WebEnhancerPlugin(PluginInfo pluginInfo, CommonLogger logger, File dataFo
public final void enable() throws Exception {
setupConfigs();

MigrationRunner webMigrations = new MigrationRunner(
BanManagerPlugin.getInstance(),
BmAPI.getLocalConnection(),
BanManagerPlugin.getInstance().getConfig().getLocalDb(),
"webenhancer",
"logs",
WebEnhancerPlugin.class.getClassLoader());
webMigrations.migrate();

try {
setupStorage();
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,6 @@ public LogStorage(ConnectionSource connection) throws SQLException {

if (!isTableExists()) {
TableUtils.createTable(connection, tableConfig);
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " CHANGE `created` `created` BIGINT UNSIGNED");
} catch (SQLException e) {
}

boolean columnAdded = false;
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() +
" ADD COLUMN messageHash CHAR(64)");
columnAdded = true;
} catch (SQLException e) {
}

try {
executeRawNoArgs("CREATE INDEX idx_" + tableConfig.getTableName() +
"_created_hash ON " + tableConfig.getTableName() + " (created, messageHash)");
} catch (SQLException e) {
}

if (columnAdded) {
try {
executeRawNoArgs(
"UPDATE " + tableConfig.getTableName() +
" SET messageHash = SHA2(message, 256)" +
" WHERE messageHash IS NULL"
);
BanManagerPlugin.getInstance().getLogger().info("[WebEnhancer] Log hash migration completed");
} catch (SQLException e) {
BanManagerPlugin.getInstance().getLogger().info("[WebEnhancer] SQL hash migration skipped (SHA2 not available) - new logs will be indexed");
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public PlayerPinStorage(ConnectionSource connection) throws SQLException {

if (!this.isTableExists()) {
TableUtils.createTable(connection, tableConfig);
} else {
try {
executeRawNoArgs("ALTER TABLE " + tableConfig.getTableName() + " CHANGE `expires` `expires` BIGINT UNSIGNED");
} catch (SQLException e) {
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/db/webenhancer/V1__baseline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Timestamp columns
ALTER TABLE ${logs} CHANGE `created` `created` BIGINT UNSIGNED;
ALTER TABLE ${playerPins} CHANGE `expires` `expires` BIGINT UNSIGNED;

-- Message hash column + index
ALTER TABLE ${logs} ADD COLUMN messageHash CHAR(64);
CREATE INDEX idx_${logs}_created_hash ON ${logs} (created, messageHash);

-- Backfill hashes (may fail on H2 which lacks SHA2 -- runner swallows the error)
UPDATE ${logs} SET messageHash = SHA2(message, 256) WHERE messageHash IS NULL;
1 change: 1 addition & 0 deletions common/src/main/resources/db/webenhancer/migrations.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V1__baseline.sql lenient
Loading