Skip to content

Commit

Permalink
init_db() only once on initial import of db
Browse files Browse the repository at this point in the history
  • Loading branch information
samj committed Jul 20, 2024
1 parent 2a1dc26 commit c01bd62
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def init_db():
alembic_cfg.set_main_option("sqlalchemy.url", f"sqlite:///{db_path}")
command.upgrade(alembic_cfg, "head")

# Call init_db() when the module is first imported
init_db()

async def execute_query(query, params=None):
# TODO: logger.adebug from structlog
logger.debug(f"Executing query: {query} with params: {params}")
Expand Down
2 changes: 1 addition & 1 deletion backend/managers/AssetsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self):
if not hasattr(self, '_initialized'):
with self._lock:
if not hasattr(self, '_initialized'):
db.init_db()
# db.init_db()
self._initialized = True

async def create_asset(self, user_id, title, creator, subject, description):
Expand Down
2 changes: 1 addition & 1 deletion backend/managers/ChannelsManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
if not hasattr(self, '_initialized'):
with self._lock:
if not hasattr(self, '_initialized'):
db.init_db()
# db.init_db()
self._initialized = True

async def create_channel(self, name, uri):
Expand Down
2 changes: 1 addition & 1 deletion backend/managers/ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, tenant=None):
if not hasattr(self, '_initialized'):
self.encryption = Encryption()
self.tenant = tenant
db.init_db()
# db.init_db()
self._initialized = True

# CRUD operations
Expand Down
2 changes: 1 addition & 1 deletion backend/managers/UsersManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):
if not hasattr(self, '_initialized'):
with self._lock:
if not hasattr(self, '_initialized'):
db.init_db()
# db.init_db()
self._initialized = True

async def create_user(self, name, email):
Expand Down

0 comments on commit c01bd62

Please sign in to comment.