From be43f1df1b095785df9f7166400a22506cce45be Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 15 Oct 2025 10:30:30 +0200 Subject: [PATCH 1/3] Fall back to sqlite when database creation fails --- planemo/galaxy/profiles.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/planemo/galaxy/profiles.py b/planemo/galaxy/profiles.py index 40db27dda..1ed55a8b3 100644 --- a/planemo/galaxy/profiles.py +++ b/planemo/galaxy/profiles.py @@ -97,10 +97,19 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds): if database_type not in ["sqlite", "postgres_singularity"]: database_source = create_database_source(**kwds) database_identifier = _profile_to_database_identifier(profile_name) - database_source.create_database( - database_identifier, - ) - database_connection = database_source.sqlalchemy_url(database_identifier) + try: + database_source.create_database( + database_identifier, + ) + except RuntimeError as e: + # If postgres database creation fails (e.g., role doesn't exist, connection issues), + # fall back to sqlite + ctx.log(f"Failed to create postgres database: {e}. Falling back to sqlite.") + database_type = "sqlite" + database_location = os.path.join(profile_directory, "galaxy.sqlite") + database_connection = DATABASE_LOCATION_TEMPLATE % database_location + else: + database_connection = database_source.sqlalchemy_url(database_identifier) elif database_type == "postgres_singularity": database_connection + database_source.sqlalchemy_url(database_identifier) else: From ad2557abd1f759367b82d371e971979c045861f0 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 15 Oct 2025 15:33:22 +0200 Subject: [PATCH 2/3] Fall back to sqlite only if database type is set to auto --- planemo/galaxy/profiles.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/planemo/galaxy/profiles.py b/planemo/galaxy/profiles.py index 1ed55a8b3..5728b11bf 100644 --- a/planemo/galaxy/profiles.py +++ b/planemo/galaxy/profiles.py @@ -84,6 +84,7 @@ def _create_profile_docker(ctx, profile_directory, profile_name, kwds): def _create_profile_local(ctx, profile_directory, profile_name, kwds): database_type = kwds.get("database_type", "auto") + allow_sqlite_fallback = database_type == "auto" if database_type == "auto": if which("psql"): database_type = "postgres" @@ -101,13 +102,15 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds): database_source.create_database( database_identifier, ) - except RuntimeError as e: - # If postgres database creation fails (e.g., role doesn't exist, connection issues), - # fall back to sqlite - ctx.log(f"Failed to create postgres database: {e}. Falling back to sqlite.") - database_type = "sqlite" - database_location = os.path.join(profile_directory, "galaxy.sqlite") - database_connection = DATABASE_LOCATION_TEMPLATE % database_location + except RuntimeError: + if allow_sqlite_fallback: + # If postgres database creation fails (e.g., role doesn't exist, connection issues), + # fall back to sqlite + database_type = "sqlite" + database_location = os.path.join(profile_directory, "galaxy.sqlite") + database_connection = DATABASE_LOCATION_TEMPLATE % database_location + else: + raise else: database_connection = database_source.sqlalchemy_url(database_identifier) elif database_type == "postgres_singularity": From f2f947cbec0f5a366ab2ef8e70d42f4064dc2e22 Mon Sep 17 00:00:00 2001 From: Marius van den Beek Date: Wed, 15 Oct 2025 18:09:53 +0200 Subject: [PATCH 3/3] handle sqlite explicitly Co-authored-by: Nicola Soranzo --- planemo/galaxy/profiles.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/planemo/galaxy/profiles.py b/planemo/galaxy/profiles.py index 5728b11bf..39f203a5e 100644 --- a/planemo/galaxy/profiles.py +++ b/planemo/galaxy/profiles.py @@ -107,15 +107,13 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds): # If postgres database creation fails (e.g., role doesn't exist, connection issues), # fall back to sqlite database_type = "sqlite" - database_location = os.path.join(profile_directory, "galaxy.sqlite") - database_connection = DATABASE_LOCATION_TEMPLATE % database_location else: raise else: database_connection = database_source.sqlalchemy_url(database_identifier) elif database_type == "postgres_singularity": database_connection + database_source.sqlalchemy_url(database_identifier) - else: + if database_type == "sqlite": database_location = os.path.join(profile_directory, "galaxy.sqlite") database_connection = DATABASE_LOCATION_TEMPLATE % database_location