fix: i actually sorta finished it and added a migration script

This commit is contained in:
əlemi 2022-08-25 20:03:33 +02:00
parent ba721a4b30
commit b750aa140f
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,21 @@
import sqlite3
def migrate_old_documents_to_namespaced_documents(db:str):
db = sqlite3.connect(db)
values = db.cursor().execute("SELECT * FROM documents", ()).fetchall();
for k,v in values:
if "_" in k:
addon, key = k.split("_", 1)
db.cursor().execute("CREATE TABLE IF NOT EXISTS documents_{addon} (name TEXT PRIMARY KEY, value TEXT)", ())
db.cursor().execute("INSERT INTO documents_{addon} VALUES (?, ?)", (key, v))
db.cursor().execute("DELETE FROM documents WHERE name = ?", k)
if __name__ == "__main__":
import sys
if len(sys.argv) < 2:
print("[!] No argument given")
exit(-1)
migrate_old_documents_to_namespaced_documents(sys.argv[1])

View file

@ -21,13 +21,14 @@ class AuthenticatorState:
legacy : bool = False
class AddonStorage:
# TODO this uses py formatting in SQL queries, can we avoid it?
db: sqlite3.Connection
name: str
def __init__(self, db:sqlite3.Connection, name:str):
self.db = db
self.name = name
self.db.cursor().execute('CREATE TABLE IF NOT EXISTS documents (name TEXT PRIMARY KEY, value TEXT)')
self.db.cursor().execute(f'CREATE TABLE IF NOT EXISTS documents_{self.name} (name TEXT PRIMARY KEY, value TEXT)')
self.db.commit()
# fstrings in queries are evil but if you go to this length to fuck up you kinda deserve it :)