Skip to content

Commit

Permalink
fix: fixed bug in peewee storage where updated/migrated model was exp…
Browse files Browse the repository at this point in the history
…ected
  • Loading branch information
ErikBjare committed May 26, 2023
1 parent 667e5f0 commit f5f3816
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions aw_datastore/storages/peewee.py
Expand Up @@ -12,6 +12,7 @@
import iso8601
from aw_core.dirs import get_data_dir
from aw_core.models import Event
from playhouse.migrate import SqliteMigrator, migrate
from playhouse.sqlite_ext import SqliteExtDatabase

import peewee
Expand Down Expand Up @@ -44,7 +45,6 @@


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

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

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

# Update bucket keys
self.update_bucket_keys()

def update_bucket_keys(self) -> None:
buckets = BucketModel.select()
self.bucket_keys = {bucket.id: bucket.key for bucket in buckets}
Expand Down

0 comments on commit f5f3816

Please sign in to comment.