Skip to content

Commit 06ce58f

Browse files
committed
allow for JSON update
1 parent 058b44b commit 06ce58f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

store/backend/migrations/versions/f8c3bc088c2d_normalize_note_keys_with_order.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,32 @@ def _downgrade_note_keys(note_keys):
8282
def 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

9699
def 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

Comments
 (0)