Added ability to fully remove database
This commit is contained in:
parent
f96494cf07
commit
962a842b44
5 changed files with 7 additions and 0 deletions
BIN
db/database.db
BIN
db/database.db
Binary file not shown.
|
|
@ -2,6 +2,7 @@ import os
|
|||
|
||||
ROOT_PATH = project_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
||||
SECRETS_FILE_PATH = ROOT_PATH + '/secrets/auth.yaml'
|
||||
DATABASE_FILE_PATH = ROOT_PATH + '/db/database.db'
|
||||
|
||||
DATABASE_FILE_PROJECT_PATH = f"/db/database.db"
|
||||
SQLITE_URL = f"sqlite://{DATABASE_FILE_PROJECT_PATH}"
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ from src.modules import data_connection
|
|||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# Startup
|
||||
data_connection.delete_database()
|
||||
data_connection.create_db_and_tables()
|
||||
yield
|
||||
# Shutdown
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ def get_user_wishlist_collection() -> list[boardgame_classes.BoardGame]:
|
|||
def get_plays() -> list[play_classes.Play]:
|
||||
return bgg_connection.get_plays()
|
||||
|
||||
def delete_database():
|
||||
db_connection.delete_database()
|
||||
|
||||
def create_db_and_tables():
|
||||
db_connection.create_db_and_tables()
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from sqlmodel import create_engine, SQLModel
|
||||
from src.config import definitions
|
||||
import os
|
||||
|
||||
sqlite_url = definitions.SQLITE_URL
|
||||
|
||||
|
|
@ -7,6 +8,8 @@ sqlite_url = definitions.SQLITE_URL
|
|||
connect_args = {"check_same_thread": False}
|
||||
engine = create_engine(sqlite_url, echo=True, connect_args=connect_args)
|
||||
|
||||
def delete_database():
|
||||
os.remove(definitions.DATABASE_FILE_PATH)
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
Loading…
Reference in a new issue