Skip to content

Commit f5f3816

Browse files
committed
fix: fixed bug in peewee storage where updated/migrated model was expected
1 parent 667e5f0 commit f5f3816

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

aw_datastore/storages/peewee.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import iso8601
1313
from aw_core.dirs import get_data_dir
1414
from aw_core.models import Event
15+
from playhouse.migrate import SqliteMigrator, migrate
1516
from playhouse.sqlite_ext import SqliteExtDatabase
1617

1718
import peewee
@@ -44,7 +45,6 @@
4445

4546

4647
def auto_migrate(path: str) -> None:
47-
from playhouse.migrate import SqliteMigrator, migrate
4848

4949
db = SqliteExtDatabase(path)
5050
migrator = SqliteMigrator(db)
@@ -154,13 +154,15 @@ def __init__(self, testing: bool = True, filepath: Optional[str] = None) -> None
154154
self.bucket_keys: Dict[str, int] = {}
155155
BucketModel.create_table(safe=True)
156156
EventModel.create_table(safe=True)
157-
self.update_bucket_keys()
158157

159158
# Migrate database if needed, requires closing the connection first
160159
self.db.close()
161160
auto_migrate(filepath)
162161
self.db.connect()
163162

163+
# Update bucket keys
164+
self.update_bucket_keys()
165+
164166
def update_bucket_keys(self) -> None:
165167
buckets = BucketModel.select()
166168
self.bucket_keys = {bucket.id: bucket.key for bucket in buckets}

0 commit comments

Comments
 (0)