Skip to content

Commit

Permalink
added database creation to the database class initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKassab committed Nov 23, 2023
1 parent b1a579d commit 29ba3b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bot/cogs/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, bot):
async def on_ready(self):
self.check_new_releases.start()

@tasks.loop(hours=12)
@tasks.loop(hours=24)
async def check_new_releases(self):
logging.info('Checking for new releases')
artists = self.bot.db.get_all_artists()
Expand Down
9 changes: 8 additions & 1 deletion services/fanbotdatabase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import contextmanager

from settings import DB_URL
from sqlalchemy import Column, String, Integer, ForeignKey, BigInteger, create_engine, Table
from sqlalchemy import Column, String, Integer, ForeignKey, BigInteger, create_engine, Table, inspect
from sqlalchemy.orm import relationship, sessionmaker, joinedload, make_transient
from sqlalchemy.ext.declarative import declarative_base
import logging
Expand Down Expand Up @@ -82,6 +82,13 @@ def __init__(self, session=None):
self.Session = sessionmaker(bind=self.engine)
self._session = session

existing_table_names = inspect(self.engine).get_table_names()
defined_table_names = {table.name for table in Base.metadata.tables.values()}

if not defined_table_names.issubset(set(existing_table_names)):
Base.metadata.create_all(self.engine)
logging.info("Database tables created.")

self._guilds = {}
self._artists = {}
self.load_cache()
Expand Down

0 comments on commit 29ba3b5

Please sign in to comment.