fix: preserve NUL characters in persisted messages
Store message text as UTF-8 bytes and migrate existing rows without loss. Cover HTTP round trips, restart persistence, Unicode limits and idempotent retries. Adapt direct database tools to the binary storage format.
This commit is contained in:
@@ -29,7 +29,7 @@ def main():
|
||||
with connection() as conn:
|
||||
conn.execute(
|
||||
"INSERT INTO messages (id,chat_id,sender_id,text,created_at) "
|
||||
"SELECT gen_random_uuid(), %s, %s, 'synthetic-' || n, "
|
||||
"SELECT gen_random_uuid(), %s, %s, convert_to('synthetic-' || n, 'UTF8'), "
|
||||
"%s::timestamptz + n * interval '1 microsecond' "
|
||||
"FROM generate_series(1,%s) AS n",
|
||||
(chat["id"], user["id"], base, args.count),
|
||||
|
||||
@@ -50,7 +50,7 @@ def main():
|
||||
for name, size, chat_id in chats:
|
||||
conn.execute(
|
||||
"INSERT INTO messages (id,chat_id,sender_id,text,created_at) "
|
||||
"SELECT gen_random_uuid(),%s,%s,%s || n,%s::timestamptz + n * interval '1 microsecond' "
|
||||
"SELECT gen_random_uuid(),%s,%s,convert_to(%s || n, 'UTF8'),%s::timestamptz + n * interval '1 microsecond' "
|
||||
"FROM generate_series(1,%s) n",
|
||||
(chat_id, user["id"], name + "-synthetic-", base, size),
|
||||
)
|
||||
@@ -107,7 +107,7 @@ def main():
|
||||
with conn.transaction():
|
||||
conn.execute(
|
||||
"INSERT INTO messages (id,chat_id,sender_id,text,created_at) "
|
||||
"SELECT gen_random_uuid(),%s,%s,'write-synthetic-' || n,"
|
||||
"SELECT gen_random_uuid(),%s,%s,convert_to('write-synthetic-' || n, 'UTF8'),"
|
||||
"clock_timestamp() + n * interval '1 microsecond' "
|
||||
"FROM generate_series(1,500) n",
|
||||
(write_chat, user["id"]),
|
||||
|
||||
Reference in New Issue
Block a user