Skip to content

Commit

Permalink
Add support for MySQL and MariaDB
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven committed Feb 24, 2020
1 parent b7f6299 commit 42842f4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sumatra/recordstore/django_store/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Handles storage of simulation/analysis records in a relational database, via the
Django object-relational mapper (ORM), which means that any database
supported by Django could in principle be used, although for now we assume
SQLite or PostgreSQL.
SQLite, PostgreSQL, MySQL or MariaDB.
:copyright: Copyright 2006-2015 by the Sumatra team, see doc/authors.txt
Expand Down Expand Up @@ -74,6 +74,13 @@ def uri_to_db(self, uri):
db['USER'] = parse_result.username
db['PASSWORD'] = parse_result.password
db['PORT'] = parse_result.port or ''
elif 'mysql' in parse_result.scheme or 'mariadb' in parse_result.scheme:
db['ENGINE'] = 'django.db.backends.mysql'
db['NAME'] = os.path.split(parse_result.path)[-1]
db['HOST'] = parse_result.hostname
db['USER'] = parse_result.username
db['PASSWORD'] = parse_result.password
db['PORT'] = parse_result.port or ''
else:
db['ENGINE'] = 'django.db.backends.sqlite3'
db['NAME'] = os.path.abspath(parse_result.path)
Expand Down Expand Up @@ -343,7 +350,7 @@ def _dump(self, indent=2):

@classmethod
def accepts_uri(cls, uri):
return uri[:8] == "postgres" or os.path.exists(uri) or os.path.exists(uri + ".db")
return uri[:8] == "postgres" or uri.startswith(('mysql', 'mariadb')) or os.path.exists(uri) or os.path.exists(uri + ".db")

def backup(self):
"""
Expand All @@ -352,7 +359,7 @@ def backup(self):
if 'sqlite3' in db_config.engine:
shutil.copy2(self._db_file, self._db_file + ".backup")
else:
warn("Cannot backup a PostgreSQL store directly.")
warn("Cannot backup a PostgreSQL/MySQL/MariaDB store directly.")

def remove(self):
"""
Expand All @@ -362,4 +369,4 @@ def remove(self):
if 'sqlite3' in db_config.engine:
os.remove(self._db_file)
else:
warn("Cannot remove a PostgreSQL store directly.")
warn("Cannot remove a PostgreSQL/MySQL/MariaDB store directly.")

0 comments on commit 42842f4

Please sign in to comment.