Skip to content

Commit

Permalink
Add recommended dialects to databases string
Browse files Browse the repository at this point in the history
  • Loading branch information
TheophileDiot committed Jan 15, 2024
1 parent 48f8eeb commit ebe3ed5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common/db/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@


class Database:
DB_STRING_RX = re_compile(r"^(?P<database>(mariadb|mysql)(\+pymysql)?|sqlite(\+pysqlite)?|postgresql):/+(?P<path>/[^\s]+)")
DB_STRING_RX = re_compile(r"^(?P<database>(mariadb|mysql)(\+pymysql)?|sqlite(\+pysqlite)?|postgresql(\+psycopg)?):/+(?P<path>/[^\s]+)")

def __init__(
self,
Expand Down Expand Up @@ -85,6 +85,10 @@ def __init__(
sleep(1)
else:
db_path.parent.mkdir(parents=True, exist_ok=True)
elif match.group("database").startswith("m") and not match.group("database").endswith("+pymysql"):
sqlalchemy_string = sqlalchemy_string.replace(match.group("database"), f"{match.group('database')}+pymysql") # ? This is mandatory for alemic to work with mariadb and mysql
elif match.group("database").startswith("postgresql") and not match.group("database").endswith("+psycopg"):
sqlalchemy_string = sqlalchemy_string.replace(match.group("database"), f"{match.group('database')}+psycopg") # ? This is strongly recommended as psycopg is the new way to connect to postgresql

self.database_uri = sqlalchemy_string
error = False
Expand Down

0 comments on commit ebe3ed5

Please sign in to comment.