diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-02-02 15:35:34 +0100 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-02-02 15:42:37 +0100 |
| commit | c26453b6150eb3dad09e97c1a2b5ba796ae8af39 (patch) | |
| tree | 0e2e46b832e691f5c8e89e893554b8a6e2248acd /velascobot2 | |
| parent | 5da9900ccc1e4313e488ec370b61bb945dbe4e18 (diff) | |
| download | velascobot2-c26453b6150eb3dad09e97c1a2b5ba796ae8af39.tar.xz velascobot2-c26453b6150eb3dad09e97c1a2b5ba796ae8af39.zip | |
Fix all chats 2
Diffstat (limited to 'velascobot2')
| -rw-r--r-- | velascobot2/database.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/velascobot2/database.py b/velascobot2/database.py index 156f1f5..720d10c 100644 --- a/velascobot2/database.py +++ b/velascobot2/database.py @@ -243,11 +243,20 @@ class Database: # I made an oopsie when converting the old jsons to sqlite. I will remove this in the next commit def fix_all_chats(self): + self.merge_and_rename_key('', ' ') + + def merge_and_rename_key(self, old_key: str, new_key: str): with _SQLiteContextMgr(database=self.db_name) as db: - db.execute( - "UPDATE vocab SET key = ? WHERE key = ?", - ('', ' ') - ) + db.execute(""" + INSERT INTO vocab (chat_id, key, word, count) + SELECT chat_id, ?, word, count + FROM vocab + WHERE key = ? + ON CONFLICT(chat_id, key, word) DO UPDATE SET count = count + excluded.count + """, (new_key, old_key)) + + # delete old key entries + db.execute("DELETE FROM vocab WHERE key = ?", (old_key,)) def get_all_chats(self) -> list[ChatData]: with _SQLiteContextMgr(database=self.db_name) as db: |
