Skip to content

Commit 6ab2feb

Browse files
committed
Set NULLS NOT DISTINCT on constraint of database-backed app commands cache key
Fixes it always updating, since a `null` guild ID is used for global commands, and it was always distinct, meaning it never triggered the UNIQUE constraint, thus always creating a new entry in some cases
1 parent 728859d commit 6ab2feb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

BotCommands-core/src/main/kotlin/io/github/freya022/botcommands/internal/core/db/DatabaseImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.sql.Connection
2222
import kotlin.time.toKotlinDuration
2323

2424
// If the build script has 3.0.0-alpha.5_DEV, use the next release version, in this case 3.0.0-alpha.6
25-
private const val latestVersion = "3.0.0-beta.1" // Change in the latest migration script too
25+
private const val latestVersion = "3.0.0-beta.9" // Change in the latest migration script too
2626

2727
private val logger = KotlinLogging.logger { }
2828

@@ -147,4 +147,4 @@ internal class DatabaseImpl internal constructor(
147147

148148
return compatibleFactories.first()
149149
}
150-
}
150+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
------------------------------------------------------ 9th migration script for BotCommands ------------------------------------------------------
2+
---------------------------------- Make sure to run the previous scripts (chronological order) before this one -----------------------------------
3+
4+
SET SCHEMA 'bc';
5+
6+
UPDATE bc_version
7+
SET version = '3.0.0-beta.9'
8+
WHERE one_row = true;
9+
10+
ALTER TABLE application_commands_cache
11+
DROP CONSTRAINT application_commands_cache_application_id_guild_id_key;
12+
13+
TRUNCATE application_commands_cache;
14+
15+
ALTER TABLE application_commands_cache
16+
ADD UNIQUE NULLS NOT DISTINCT (application_id, guild_id);

0 commit comments

Comments
 (0)