Skip to content

Commit 2c9c3c8

Browse files
committed
Remove older migration callbacks
1 parent 0a5ec0e commit 2c9c3c8

File tree

7 files changed

+6
-146
lines changed

7 files changed

+6
-146
lines changed

modules/custom-pings/src/main/java/net/neoforged/camelot/module/custompings/CustomPingsModule.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import net.neoforged.camelot.api.config.ConfigOption;
99
import net.neoforged.camelot.api.config.type.Options;
1010
import net.neoforged.camelot.config.module.CustomPings;
11-
import net.neoforged.camelot.module.BuiltInModule;
1211
import net.neoforged.camelot.module.api.CamelotModule;
13-
import net.neoforged.camelot.module.custompings.db.PingsCallbacks;
14-
import net.neoforged.camelot.module.custompings.db.PingsDAO;
1512

1613
@RegisterCamelotModule
1714
public class CustomPingsModule extends CamelotModule.WithDatabase<CustomPings> {
@@ -20,28 +17,6 @@ public class CustomPingsModule extends CamelotModule.WithDatabase<CustomPings> {
2017

2118
public CustomPingsModule(ModuleProvider.Context context) {
2219
super(context, CustomPings.class);
23-
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder
24-
.add(BuiltInModule.DatabaseSource.PINGS, 4, stmt -> {
25-
logger.info("Moving custom ping threads from pings.db to custom-pings.db");
26-
var threads = stmt.executeQuery("select * from ping_threads");
27-
db().useExtension(PingsDAO.class, db -> {
28-
while (threads.next()) {
29-
db.insertThread(threads.getLong(1), 0, threads.getLong(2));
30-
}
31-
});
32-
33-
logger.info("Moving custom pings from pings.db to custom-pings.db");
34-
PingsCallbacks.migrating = true;
35-
var pings = stmt.executeQuery("select * from pings");
36-
db().useExtension(PingsDAO.class, db -> {
37-
while (pings.next()) {
38-
db.insert(pings.getLong(2), pings.getLong(3), pings.getString(4), pings.getString(5));
39-
}
40-
});
41-
PingsCallbacks.migrating = false;
42-
43-
CustomPingListener.requestRefresh();
44-
}));
4520

4621
var registrar = context.guildConfigs();
4722
registrar.groupDisplayName("Custom Pings");

modules/custom-pings/src/main/java/net/neoforged/camelot/module/custompings/db/PingsCallbacks.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
import net.neoforged.camelot.module.custompings.CustomPingListener;
55

66
public class PingsCallbacks {
7-
public static volatile boolean migrating;
8-
97
@ExecutionCallback(methodName = "insert")
108
public static void onInsert(PingsDAO dao, long guild, long user, String regex, String message) {
11-
if (!migrating) {
12-
CustomPingListener.requestRefresh();
13-
}
9+
CustomPingListener.requestRefresh();
1410
}
1511

1612
@ExecutionCallback(methodName = "deletePing")

modules/info-channels/src/main/java/net/neoforged/camelot/module/infochannels/InfoChannelsModule.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@
66
import net.neoforged.camelot.ModuleProvider;
77
import net.neoforged.camelot.ap.RegisterCamelotModule;
88
import net.neoforged.camelot.config.module.InfoChannels;
9-
import net.neoforged.camelot.db.schemas.GithubLocation;
10-
import net.neoforged.camelot.module.BuiltInModule;
119
import net.neoforged.camelot.module.api.CamelotModule;
1210
import net.neoforged.camelot.module.infochannels.command.InfoChannelCommand;
1311
import net.neoforged.camelot.module.infochannels.command.RuleCommand;
14-
import net.neoforged.camelot.module.infochannels.db.InfoChannel;
15-
import net.neoforged.camelot.module.infochannels.db.InfoChannelsDAO;
16-
import net.neoforged.camelot.module.infochannels.db.RulesDAO;
1712

1813
import java.util.concurrent.TimeUnit;
1914

@@ -24,38 +19,6 @@
2419
public class InfoChannelsModule extends CamelotModule.WithDatabase<InfoChannels> {
2520
public InfoChannelsModule(ModuleProvider.Context context) {
2621
super(context, InfoChannels.class);
27-
28-
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder
29-
.add(BuiltInModule.DatabaseSource.MAIN, 15, stmt -> {
30-
logger.info("Migrating info channels from main.db to info-channels.db");
31-
var infoChannels = stmt.executeQuery("select * from info_channels");
32-
db().useExtension(InfoChannelsDAO.class, db -> {
33-
while (infoChannels.next()) {
34-
db.insert(
35-
new InfoChannel(
36-
infoChannels.getLong(1),
37-
GithubLocation.parse(infoChannels.getString(2)),
38-
infoChannels.getBoolean(3),
39-
infoChannels.getString(4),
40-
InfoChannel.Type.values()[infoChannels.getInt(5)]
41-
)
42-
);
43-
}
44-
});
45-
46-
logger.info("Migrating rules from main.db to info-channels.db");
47-
var rules = stmt.executeQuery("select * from rules");
48-
db().useExtension(RulesDAO.class, db -> {
49-
while (rules.next()) {
50-
db.insert(
51-
rules.getLong(1),
52-
rules.getLong(2),
53-
rules.getInt(3),
54-
rules.getString(4)
55-
);
56-
}
57-
});
58-
}));
5922
}
6023

6124
@Override

modules/quotes/src/main/java/net/neoforged/camelot/module/quotes/QuotesModule.java

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import net.neoforged.camelot.ModuleProvider;
1313
import net.neoforged.camelot.ap.RegisterCamelotModule;
1414
import net.neoforged.camelot.config.module.Quotes;
15-
import net.neoforged.camelot.module.BuiltInModule;
1615
import net.neoforged.camelot.module.TricksModule;
1716
import net.neoforged.camelot.module.api.CamelotModule;
1817
import net.neoforged.camelot.module.quotes.db.Quote;
@@ -47,40 +46,9 @@
4746
public class QuotesModule extends CamelotModule.WithDatabase<Quotes> {
4847
public QuotesModule(ModuleProvider.Context context) {
4948
super(context, Quotes.class);
50-
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder
51-
.add(BuiltInModule.DatabaseSource.MAIN, 16, stmt -> {
52-
logger.info("Migrating quote authors from main.db to quotes.db");
53-
var authors = stmt.executeQuery("select * from quote_authors");
54-
db().useExtension(QuotesDAO.class, db -> {
55-
while (authors.next()) {
56-
db.insertAuthor(
57-
authors.getInt(1),
58-
authors.getLong(2),
59-
authors.getString(3),
60-
authors.getLong(4)
61-
);
62-
}
63-
});
64-
65-
logger.info("Migrating quotes from main.db to quotes.db");
66-
var quotes = stmt.executeQuery("select * from quotes");
67-
db().useExtension(QuotesDAO.class, db -> {
68-
while (quotes.next()) {
69-
db.insertQuote(
70-
quotes.getLong(2),
71-
quotes.getInt(3),
72-
quotes.getString(4),
73-
quotes.getString(5),
74-
quotes.getLong(6),
75-
null,
76-
quotes.getInt(1)
77-
);
78-
}
79-
});
80-
}));
8149

8250
accept(TricksModule.COMPILING_SCRIPT, compilingScript -> compilingScript.object().putLazyGetter("guild.getQuotes", () -> db().withExtension(QuotesDAO.class, db ->
83-
db.getQuotes(compilingScript.context().guild().getIdLong(), 0, Integer.MAX_VALUE)).stream()
51+
db.getQuotes(compilingScript.context().guild().getIdLong(), 0, Integer.MAX_VALUE)).stream()
8452
.map(q -> ScriptObject.of("Quote")
8553
.put("id", q.id())
8654
.put("quote", q.quote())
@@ -106,7 +74,7 @@ public void registerCommands(CommandClientBuilder builder) {
10674

10775
builder.addContextMenu(new MessageContextMenu() {
10876
{
109-
name = "Add quote";
77+
name = "Add quote";
11078
}
11179

11280
@Override
@@ -127,6 +95,7 @@ protected void execute(MessageContextMenuEvent event) {
12795
}
12896

12997
private Font usedFont;
98+
13099
@Override
131100
public void setup(JDA jda) {
132101
final QuotesDAO db = BotMain.getModule(QuotesModule.class).db().onDemand(QuotesDAO.class);
@@ -161,7 +130,8 @@ private void updateAuthors(final JDA jda, final QuotesDAO db) {
161130
}));
162131
}
163132

164-
public record MemberLike(String name, String avatar, Color color) {}
133+
public record MemberLike(String name, String avatar, Color color) {
134+
}
165135

166136
public byte[] makeQuoteImage(final Guild guild, final @Nullable MemberLike member, final Quote quote) {
167137
final ByteArrayOutputStream out = new ByteArrayOutputStream();

modules/reminders/src/main/java/net/neoforged/camelot/module/reminders/RemindersModule.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
import net.neoforged.camelot.api.config.type.Options;
3838
import net.neoforged.camelot.config.module.Reminders;
3939
import net.neoforged.camelot.listener.DismissListener;
40-
import net.neoforged.camelot.module.BuiltInModule;
4140
import net.neoforged.camelot.module.api.CamelotModule;
4241
import net.neoforged.camelot.module.reminders.db.Reminder;
43-
import net.neoforged.camelot.module.reminders.db.RemindersCallbacks;
4442
import net.neoforged.camelot.module.reminders.db.RemindersDAO;
4543
import net.neoforged.camelot.util.Emojis;
4644
import net.neoforged.camelot.util.Utils;
@@ -69,24 +67,6 @@ public class RemindersModule extends CamelotModule.WithDatabase<Reminders> {
6967
public RemindersModule(ModuleProvider.Context context) {
7068
super(context, Reminders.class);
7169

72-
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder
73-
.add(BuiltInModule.DatabaseSource.MAIN, 17, statement -> {
74-
logger.info("Moving reminders from main.db to reminders.db");
75-
RemindersCallbacks.migrating = true;
76-
var rs = statement.executeQuery("select * from reminders");
77-
db().useExtension(RemindersDAO.class, db -> {
78-
while (rs.next()) {
79-
db.insertReminder(
80-
rs.getLong(2),
81-
rs.getLong(3),
82-
rs.getLong(4),
83-
rs.getString(5)
84-
);
85-
}
86-
});
87-
RemindersCallbacks.migrating = false;
88-
}));
89-
9070
var userRegistrar = context.userConfigs()
9171
.groupDisplayName("Reminders");
9272

modules/reminders/src/main/java/net/neoforged/camelot/module/reminders/db/RemindersCallbacks.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
* Callbacks for {@link RemindersDAO}.
1212
*/
1313
public class RemindersCallbacks {
14-
public static volatile boolean migrating;
15-
1614
/**
1715
* A callback that is called when a new reminder is added to the database.
1816
* This callback will schedule the reminder to the {@link RemindersModule#EXECUTOR}.
1917
*/
2018
@ExecutionCallback(methodName = "insertReminder", phase = ExecutionCallback.Phase.POST)
2119
public static void onReminderAdded(RemindersDAO dao, long user, long channel, long time, String reminder) {
22-
if (migrating) return;
23-
2420
final int id = dao.getHandle().createQuery("select max(id) from reminders").execute((statement, ctx) -> statement.get().getResultSet().getInt(1));
2521
BotMain.EXECUTOR.schedule(() -> BotMain.getModule(RemindersModule.class).run(id), time - Instant.now().getEpochSecond(), TimeUnit.SECONDS);
2622
}

modules/thread-pings/src/main/java/net/neoforged/camelot/module/threadpings/ThreadPingsModule.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,6 @@ public ThreadPingsModule(ModuleProvider.Context context) {
2222
super(context, ThreadPings.class);
2323
accept(BuiltInModule.CONFIGURATION_COMMANDS, configCommandBuilder -> configCommandBuilder
2424
.accept(new ThreadPingsCommand.ConfigureChannel(this), new ThreadPingsCommand.ConfigureGuild(this), new ThreadPingsCommand.View(this)));
25-
26-
accept(BuiltInModule.DB_MIGRATION_CALLBACKS, builder -> builder
27-
.add(BuiltInModule.DatabaseSource.PINGS, 3, stmt -> {
28-
logger.info("Migrating thread pings from pings.db to thread-pings.db");
29-
var rs = stmt.executeQuery("select channel, role from thread_pings");
30-
db().useExtension(ThreadPingsDAO.class, extension -> {
31-
while (rs.next()) {
32-
extension.add(rs.getLong(1), rs.getLong(2));
33-
}
34-
});
35-
})
36-
.add(BuiltInModule.DatabaseSource.CONFIG, 2, stmt -> {
37-
logger.info("Migrating thread pings from configuration.db to thread-pings.db");
38-
var rs = stmt.executeQuery("select channel, role from thread_pings");
39-
db().useExtension(ThreadPingsDAO.class, extension -> {
40-
while (rs.next()) {
41-
extension.add(rs.getLong(1), rs.getLong(2));
42-
}
43-
});
44-
}));
4525
}
4626

4727
@Override

0 commit comments

Comments
 (0)