@@ -85,6 +85,7 @@ def _create_profile_docker(ctx, profile_directory, profile_name, kwds):
8585
8686def _create_profile_local (ctx , profile_directory , profile_name , kwds ):
8787 database_type = kwds .get ("database_type" , "auto" )
88+ allow_sqlite_fallback = database_type == "auto"
8889 if database_type == "auto" :
8990 if which ("psql" ):
9091 database_type = "postgres"
@@ -98,13 +99,22 @@ def _create_profile_local(ctx, profile_directory, profile_name, kwds):
9899 if database_type not in ["sqlite" , "postgres_singularity" ]:
99100 database_source = create_database_source (** kwds )
100101 database_identifier = _profile_to_database_identifier (profile_name )
101- database_source .create_database (
102- database_identifier ,
103- )
104- database_connection = database_source .sqlalchemy_url (database_identifier )
102+ try :
103+ database_source .create_database (
104+ database_identifier ,
105+ )
106+ except RuntimeError :
107+ if allow_sqlite_fallback :
108+ # If postgres database creation fails (e.g., role doesn't exist, connection issues),
109+ # fall back to sqlite
110+ database_type = "sqlite"
111+ else :
112+ raise
113+ else :
114+ database_connection = database_source .sqlalchemy_url (database_identifier )
105115 elif database_type == "postgres_singularity" :
106116 database_connection + database_source .sqlalchemy_url (database_identifier )
107- else :
117+ if database_type == "sqlite" :
108118 database_location = os .path .join (profile_directory , "galaxy.sqlite" )
109119 database_connection = DATABASE_LOCATION_TEMPLATE % database_location
110120
0 commit comments