From 192fec6952bfc404705c13c050720c207db6b4e0 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 19 Oct 2020 01:50:12 +0300 Subject: [PATCH] Fix rounding in thread messages that only contain an ID Internally, the thread_messages table's body column's type was undefined in sqlite. This is because it was set to mediumtext, but sqlite doesn't have that type. Because of that, sqlite treated the column as a numeric column. Sqlite also allows storing text data in numeric columns (because reasons), so in most cases everything worked fine. It was only when storing an actual number, like an ID, that it was also *treated* as a number. And since snowflake IDs are larger than the maximum safe integer in JavaScript, the stored ID could get rounded when retrieving data from the database. --- ...31_fix_thread_messages_body_column_type.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/data/migrations/20201019013831_fix_thread_messages_body_column_type.js diff --git a/src/data/migrations/20201019013831_fix_thread_messages_body_column_type.js b/src/data/migrations/20201019013831_fix_thread_messages_body_column_type.js new file mode 100644 index 0000000..ecfbdd5 --- /dev/null +++ b/src/data/migrations/20201019013831_fix_thread_messages_body_column_type.js @@ -0,0 +1,19 @@ +exports.up = async function(knex) { + await knex.schema.table("thread_messages", table => { + table.text("temp_body"); + }); + + await knex.raw("UPDATE thread_messages SET temp_body = body"); + + await knex.schema.table("thread_messages", table => { + table.dropColumn("body"); + }); + + await knex.schema.table("thread_messages", table => { + table.renameColumn("temp_body", "body"); + }); +}; + +exports.down = async function(knex) { + +};