From b7c79800eb3d3c3d0c1c6e37d2fb6da64930f6db Mon Sep 17 00:00:00 2001 From: P0nk Date: Tue, 28 Feb 2023 21:29:44 +0100 Subject: [PATCH] Fix note not showing if case mismatch in name This wouldn't be a problem in the first case, if there was a foreign key connection between note and character tables. Can't add that quite yet though. --- database/postgres-scripts/create-db-and-admin-user.sql | 3 +-- src/main/java/database/note/NoteDao.java | 10 ++++++---- .../resources/db/migration/postgresql/V0.2__note.sql | 1 - 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/database/postgres-scripts/create-db-and-admin-user.sql b/database/postgres-scripts/create-db-and-admin-user.sql index 6de094088e..66ff0c5254 100644 --- a/database/postgres-scripts/create-db-and-admin-user.sql +++ b/database/postgres-scripts/create-db-and-admin-user.sql @@ -1,4 +1,3 @@ CREATE DATABASE cosmic; -CREATE USER cosmic_admin WITH ENCRYPTED PASSWORD 'redsnailshell'; +CREATE USER cosmic_admin WITH CREATEROLE ENCRYPTED PASSWORD 'redsnailshell'; GRANT ALL PRIVILEGES ON DATABASE cosmic TO cosmic_admin; -ALTER ROLE cosmic_admin WITH CREATEROLE; \ No newline at end of file diff --git a/src/main/java/database/note/NoteDao.java b/src/main/java/database/note/NoteDao.java index dd77e8290c..0427c13616 100644 --- a/src/main/java/database/note/NoteDao.java +++ b/src/main/java/database/note/NoteDao.java @@ -33,18 +33,20 @@ public class NoteDao { } } - public List findAllByTo(String to) { + public List findAllByTo(String receiver) { try (Handle handle = connection.getHandle()) { + // Using LOWER as a workaround for notes not appearing when being sent to name with wrongly typed casing. + // Ideally, the character ids should be the identifier rather than name. return handle.createQuery(""" SELECT * FROM note WHERE deleted = 0 - AND receiver = ?""") - .bind(0, to) + AND LOWER(receiver) = LOWER(?)""") + .bind(0, receiver) .mapTo(Note.class) .list(); } catch (JdbiException e) { - throw new DaoException("Failed to find notes sent to: %s".formatted(to), e); + throw new DaoException("Failed to find notes sent to: %s".formatted(receiver), e); } } diff --git a/src/main/resources/db/migration/postgresql/V0.2__note.sql b/src/main/resources/db/migration/postgresql/V0.2__note.sql index d01a0e3865..9b210e5558 100644 --- a/src/main/resources/db/migration/postgresql/V0.2__note.sql +++ b/src/main/resources/db/migration/postgresql/V0.2__note.sql @@ -8,6 +8,5 @@ CREATE TABLE note( deleted smallint NOT NULL, PRIMARY KEY (id) ); -CREATE INDEX note_received_idx ON note(receiver); GRANT SELECT, INSERT, UPDATE ON note TO ${server-username}; GRANT USAGE ON note_id_seq TO ${server-username};