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.
cshd
Dragory 2020-10-19 01:50:12 +03:00
parent 5b0f9d31b7
commit 192fec6952
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 19 additions and 0 deletions

View File

@ -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) {
};