@@ -82,26 +82,32 @@ def _downgrade_note_keys(note_keys):
8282def upgrade ():
8383 conn = op .get_bind ()
8484 rows = conn .execute (sa .text ("SELECT id, note_keys FROM annotations" )).fetchall ()
85+ update_stmt = sa .text (
86+ "UPDATE annotations SET note_keys = :note_keys WHERE id = :id"
87+ ).bindparams (
88+ sa .bindparam ("note_keys" , type_ = sa .JSON ()),
89+ sa .bindparam ("id" , type_ = sa .Text ()),
90+ )
8591 for row in rows :
8692 nk = row .note_keys
8793 if not nk :
8894 continue
8995 normalized = _normalize_note_keys (nk )
90- conn .execute (
91- sa .text ("UPDATE annotations SET note_keys = :note_keys WHERE id = :id" ),
92- {"id" : row .id , "note_keys" : normalized },
93- )
96+ conn .execute (update_stmt , {"id" : row .id , "note_keys" : normalized })
9497
9598
9699def downgrade ():
97100 conn = op .get_bind ()
98101 rows = conn .execute (sa .text ("SELECT id, note_keys FROM annotations" )).fetchall ()
102+ update_stmt = sa .text (
103+ "UPDATE annotations SET note_keys = :note_keys WHERE id = :id"
104+ ).bindparams (
105+ sa .bindparam ("note_keys" , type_ = sa .JSON ()),
106+ sa .bindparam ("id" , type_ = sa .Text ()),
107+ )
99108 for row in rows :
100109 nk = row .note_keys
101110 if not nk :
102111 continue
103112 downgraded = _downgrade_note_keys (nk )
104- conn .execute (
105- sa .text ("UPDATE annotations SET note_keys = :note_keys WHERE id = :id" ),
106- {"id" : row .id , "note_keys" : downgraded },
107- )
113+ conn .execute (update_stmt , {"id" : row .id , "note_keys" : downgraded })
0 commit comments