Skip to content

Commit bb19a24

Browse files
committed
fix: migration 관련 코드 버그 수정
1 parent d502f55 commit bb19a24

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

src/httpc/catcher/_db.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class TransactionDatabase(MutableMapping[httpx.Request, httpx.Response]):
7777
AND json(headers) = json(CAST(? AS TEXT))
7878
AND content = CAST(? AS BLOB)
7979
)"""
80-
_iter_keys = "SELECT (method, url, headers, content) FROM transactions WHERE type = ?"
80+
_iter_keys = "SELECT method, url, headers, content FROM transactions WHERE type = ?"
8181
_delete_all = "DELETE FROM transactions WHERE type = ?"
8282
_add_compressed_column = "ALTER TABLE transactions ADD COLUMN compressed BOOLEAN NOT NULL DEFAULT FALSE"
8383
_iter_uncompressed = "SELECT ROWID, response FROM transactions WHERE type = ?, compressed == FALSE"
@@ -170,13 +170,13 @@ def __init__(
170170
with suppress(sqlite3.OperationalError):
171171
self._cx.execute("PRAGMA journal_mode = wal")
172172

173+
if migrate_old_database:
174+
self.migrate_old_database()
175+
173176
if flagged == "rwc":
174177
self._execute(self._build_table)
175178
self._execute(self._build_index)
176179

177-
if migrate_old_database:
178-
self.migrate_old_database()
179-
180180
def migrate_old_database(self):
181181
with suppress(DBError):
182182
self._execute(self._add_compressed_column)
@@ -193,12 +193,6 @@ def migrate_old_database(self):
193193
if "transactions" in tables:
194194
return
195195

196-
# 새로운 데이터베이스에 필요한 type column이 있는 경우 migration이 이미 된 것이니 종료
197-
with self._execute("SELECT sql FROM sqlite_schema WHERE name == ?", (tables[0],)) as cu:
198-
sql, = cu.fetchone()
199-
if "type" in sql:
200-
return
201-
202196
self._execute(self._build_table)
203197

204198
for table in tables:
@@ -207,10 +201,10 @@ def migrate_old_database(self):
207201
try:
208202
self._execute(f"""INSERT INTO transactions (
209203
type, method, url, headers, content, response, compressed
210-
) VALUES SELECT (
204+
) SELECT
211205
?, method, url, headers, content, response, compressed
212-
) FROM {table}
213-
""", table)
206+
FROM {table}
207+
""", (table,))
214208
except DBError:
215209
pass
216210
else:

0 commit comments

Comments
 (0)