Dockerized everything and added CI/CD deployment

This commit is contained in:
c-d-p
2025-04-22 22:54:31 +02:00
parent bf147af3ef
commit 02d191853b
17 changed files with 434 additions and 71 deletions

View File

@@ -0,0 +1,35 @@
from core.celery_app import celery_app
@celery_app.task
def cleardb(hard: bool):
"""
Clear the database based on the 'hard' flag.
'hard'=True: Drop and recreate all tables.
'hard'=False: Delete data from tables except users.
"""
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from core.config import settings
from core.database import Base
engine = create_engine(settings.DB_URL)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
db = SessionLocal()
if hard:
# Drop and recreate all tables
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)
db.commit()
return {"message": "Database reset (HARD)"}
else:
# Delete data from tables except users
tables = Base.metadata.tables.keys()
for table_name in tables:
# delete all tables that isn't the users table
if table_name != "users":
table = Base.metadata.tables[table_name]
print(f"Deleting table: {table_name}")
db.execute(table.delete())
db.commit()
return {"message": "Database cleared"}