From 42842f43a6812eadcce3b3ee24612dfaeab60a42 Mon Sep 17 00:00:00 2001 From: David Kleiven Date: Thu, 20 Feb 2020 12:58:34 +0100 Subject: [PATCH] Add support for MySQL and MariaDB --- sumatra/recordstore/django_store/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sumatra/recordstore/django_store/__init__.py b/sumatra/recordstore/django_store/__init__.py index e327afb1..3d434fa7 100644 --- a/sumatra/recordstore/django_store/__init__.py +++ b/sumatra/recordstore/django_store/__init__.py @@ -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 @@ -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) @@ -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): """ @@ -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): """ @@ -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.")