From 60bed74a0de06275c2720f38f53438d2b46a7530 Mon Sep 17 00:00:00 2001 From: Zeecka Date: Wed, 31 Dec 2025 22:47:20 +0100 Subject: [PATCH] Now working --- aperisolve/app.py | 5 +++-- aperisolve/models.py | 26 ++++++++++++-------------- compose.dev.yml | 1 + compose.yml | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/aperisolve/app.py b/aperisolve/app.py index 295faaa..734097c 100644 --- a/aperisolve/app.py +++ b/aperisolve/app.py @@ -33,9 +33,10 @@ app.config["MAX_CONTENT_LENGTH"] = int( ) RESULT_FOLDER.mkdir(parents=True, exist_ok=True) - db.init_app(app) -init_db(app) +with app.app_context(): + init_db(app) + redis_conn = Redis(host="redis", port=6379) queue = Queue(connection=redis_conn) diff --git a/aperisolve/models.py b/aperisolve/models.py index c38ad96..dc47053 100644 --- a/aperisolve/models.py +++ b/aperisolve/models.py @@ -62,7 +62,7 @@ class IHDR(db.Model): # type: ignore packed = Column(BigInteger, nullable=False) -def create_crc_db() -> None: +def fill_ihdr_db() -> None: """ Creates a database of common PNG IHDR (Image Header) entries by generating combinations of standard PNG parameters such as resolutions, bit depths, @@ -132,18 +132,16 @@ def init_db(app: Flask) -> None: with app.app_context(): if getenv("CLEAR_AT_RESTART", "0") == "1": # Force clear if CLEAR_AT_RESTART print("Clearing database and file system at restart...") - db.drop_all() # Clear existing tables if configured - db.session.commit() # pylint: disable=no-member + db.session.remove() # pylint: disable=no-member + db.drop_all() rmtree(Path("./results"), ignore_errors=True) # Clear results folder - if not db.engine.dialect.has_table( - db.engine.connect(), "image" - ): # If not configured - db.create_all() - print("Database structure created successfully.") - if getenv("SKIP_IHDR_FILL", "0") == "1": - print("Skipping IHDR lookup table fill as per configuration.") - else: - print("Filling IHDR lookup table...") - create_crc_db() - print("IHDR table filled successfully.") + db.create_all() + print("Database structure created successfully.") + + if getenv("SKIP_IHDR_FILL", "0") == "1": + print("Skipping IHDR lookup table fill as per configuration.") + else: + print("Filling IHDR lookup table...") + fill_ihdr_db() + print("IHDR table filled successfully.") diff --git a/compose.dev.yml b/compose.dev.yml index 523ee2f..1bdd982 100644 --- a/compose.dev.yml +++ b/compose.dev.yml @@ -41,6 +41,7 @@ services: environment: - FLASK_DEBUG=true - FLASK_ENV=development + - CLEAR_AT_RESTART=0 # Always false for worker to prevent double clearing redis: image: redis:8 diff --git a/compose.yml b/compose.yml index 2afcb73..4489e66 100644 --- a/compose.yml +++ b/compose.yml @@ -37,6 +37,8 @@ services: - postgres env_file: - .env + environment: + - CLEAR_AT_RESTART=0 # Always false for worker to prevent double clearing postgres: image: postgres:18