Skip to content

Commit

Permalink
Hopefully fix server scope DDL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Sep 12, 2023
1 parent dbfd54a commit 5f94468
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 24 deletions.
2 changes: 2 additions & 0 deletions bans-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
<arbitrarybinarytype>BLOB</arbitrarybinarytype>
<alterviewstatement>ALTER VIEW</alterviewstatement>
<zerosmallintliteral>CAST(0 AS SMALLINT)</zerosmallintliteral>
<migratescopestart>CAST(</migratescopestart>
<migratescopeend> AS CHARACTER VARYING(32))</migratescopeend>
</placeholders>
<locations>
<location>filesystem:src/main/resources/database-migrations</location>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public String zeroSmallintLiteral() {
};
}

public String[] migrateScope() {
return switch (this) {
case MARIADB, MYSQL -> new String[] {"", ""};
case HSQLDB, POSTGRES, COCKROACH -> new String[] {
"CAST(",
" AS CHARACTER VARYING(32))"
};
};
}

String getConnectionInitSql() {

return switch (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ private Flyway createFlyway(MigrationState migrationState) {
"inettype", vendor.inetType(),
"arbitrarybinarytype", vendor.arbitraryBinaryType(),
"alterviewstatement", vendor.alterViewStatement(),
"zerosmallintliteral", vendor.zeroSmallintLiteral()
"zerosmallintliteral", vendor.zeroSmallintLiteral(),
"migratescopestart", vendor.migrateScope()[0],
"migratescopeend", vendor.migrateScope()[1]
))
.locations("classpath:database-migrations")
// Override classpath scanning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ${alterviewstatement} "${tableprefix}simple_bans" AS
SELECT "puns"."id", "puns"."type",
"victims"."type" AS "victim_type", "victims"."uuid" AS "victim_uuid", "victims"."address" AS "victim_address",
"puns"."operator", "puns"."reason",
(CASE
${migratescopestart}(CASE
WHEN "puns"."scope_id" IS NULL THEN ''
ELSE "scopes"."value"
END) AS "scope",
END)${migratescopeend} AS "scope",
"puns"."start", "puns"."end",
(CASE
WHEN "tracks"."namespace" IS NULL THEN NULL
Expand Down Expand Up @@ -59,10 +59,10 @@ ${alterviewstatement} "${tableprefix}simple_mutes" AS
SELECT "puns"."id", "puns"."type",
"victims"."type" AS "victim_type", "victims"."uuid" AS "victim_uuid", "victims"."address" AS "victim_address",
"puns"."operator", "puns"."reason",
(CASE
${migratescopestart}(CASE
WHEN "puns"."scope_id" IS NULL THEN ''
ELSE "scopes"."value"
END) AS "scope",
END)${migratescopeend} AS "scope",
"puns"."start", "puns"."end",
(CASE
WHEN "tracks"."namespace" IS NULL THEN NULL
Expand Down Expand Up @@ -98,10 +98,10 @@ ${alterviewstatement} "${tableprefix}simple_warns" AS
SELECT "puns"."id", "puns"."type",
"victims"."type" AS "victim_type", "victims"."uuid" AS "victim_uuid", "victims"."address" AS "victim_address",
"puns"."operator", "puns"."reason",
(CASE
${migratescopestart}(CASE
WHEN "puns"."scope_id" IS NULL THEN ''
ELSE "scopes"."value"
END) AS "scope",
END)${migratescopeend} AS "scope",
"puns"."start", "puns"."end",
(CASE
WHEN "tracks"."namespace" IS NULL THEN NULL
Expand Down Expand Up @@ -137,10 +137,10 @@ ${alterviewstatement} "${tableprefix}simple_history" AS
SELECT "puns"."id", "puns"."type",
"victims"."type" AS "victim_type", "victims"."uuid" AS "victim_uuid", "victims"."address" AS "victim_address",
"puns"."operator", "puns"."reason",
(CASE
${migratescopestart}(CASE
WHEN "puns"."scope_id" IS NULL THEN ''
ELSE "scopes"."value"
END) AS "scope",
END)${migratescopeend} AS "scope",
"puns"."start", "puns"."end",
(CASE
WHEN "tracks"."namespace" IS NULL THEN NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.junit.jupiter.api.Test;
import space.arim.api.util.testing.InjectableConstructor;
import space.arim.libertybans.core.env.ParallelisedListener;
import space.arim.libertybans.core.env.PlatformListener;

public class SpigotEnvTest {
Expand All @@ -31,8 +30,9 @@ public void allListenersDeclared() {
new InjectableConstructor(SpigotEnv.class)
.verifyParametersContainSubclassesOf(PlatformListener.class, (clazz) -> {
// Exclude CommandHandler since it is constructed directly
// Exclude ParallelisedListener, which would never be injected
return !clazz.equals(CommandHandler.class) && !clazz.equals(ParallelisedListener.class);
// Use only classes in our package or subpackages
return !clazz.equals(CommandHandler.class)
&& clazz.getPackageName().startsWith(getClass().getPackageName());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.junit.jupiter.api.Test;
import space.arim.api.util.testing.InjectableConstructor;
import space.arim.libertybans.core.env.ParallelisedListener;
import space.arim.libertybans.core.env.PlatformListener;

public class SpongeEnvTest {
Expand All @@ -31,10 +30,10 @@ public void allListenersDeclared() {
new InjectableConstructor(SpongeEnv.class)
.verifyParametersContainSubclassesOf(PlatformListener.class, (clazz) -> {
// Exclude CommandHandler since it is constructed directly
// Exclude ParallelisedListener, which would never be injected
// Use only classes in our package or subpackages
// Exclude anonymous or local classes
return !clazz.equals(CommandHandler.class)
&& !clazz.equals(ParallelisedListener.class)
&& clazz.getPackageName().startsWith(getClass().getPackageName())
&& !clazz.isAnonymousClass()
&& !clazz.isLocalClass();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void kickPlayer(Void player, Component message) {
}

@Override
public <D> boolean sendPluginMessageIfListening(Void player, PluginMessage<D, ?> pluginMessage, D data) {
public <D> void sendPluginMessage(Void player, PluginMessage<D, ?> pluginMessage, D data) {
throw new UnsupportedOperationException();
}

Expand All @@ -90,6 +90,11 @@ public InetAddress getAddressFor(Void player) {
throw new UnsupportedOperationException();
}

@Override
public String getNameFor(Void player) {
throw new UnsupportedOperationException();
}

@Override
public boolean hasPermission(Void player, String permission) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,18 @@

import org.junit.jupiter.api.Test;
import space.arim.api.util.testing.InjectableConstructor;
import space.arim.libertybans.core.env.ParallelisedListener;
import space.arim.libertybans.core.env.PlatformListener;

import java.util.Set;

public class VelocityEnvTest {

@Test
public void allListenersDeclared() {
new InjectableConstructor(VelocityEnv.class)
.verifyParametersContainSubclassesOf(PlatformListener.class, (clazz) -> {
// Exclude CommandHandler since it is constructed directly
// Exclude ParallelisedListener, which would never be injected
boolean excluded = Set.of(
CommandHandler.class, ParallelisedListener.class
).contains(clazz);
return !excluded;
// Use only classes in our package or subpackages
return !clazz.equals(CommandHandler.class) &&
clazz.getPackageName().startsWith(getClass().getPackageName());
});
}
}

0 comments on commit 5f94468

Please sign in to comment.