diff options
author | Josiah Ruddell <jruddell@gmail.com> | 2015-09-16 11:12:20 -0700 |
---|---|---|
committer | Josiah Ruddell <jruddell@gmail.com> | 2015-09-16 11:12:20 -0700 |
commit | de7aa3806ffbc6a1903404c53ab193d13ceaf457 (patch) | |
tree | 6b4050e1ace51bda958848950ed28a99f3f13ea5 | |
parent | 4db8f356ffe1cd9e0d6212952ad6019b33b40b49 (diff) | |
download | yoyo-de7aa3806ffbc6a1903404c53ab193d13ceaf457.tar.gz |
- MySQLdb driver
- compatibility with yoyo in google cloud environments
-rwxr-xr-x | README.rst | 8 | ||||
-rw-r--r-- | yoyo/backends.py | 18 | ||||
-rwxr-xr-x | yoyo/compat.py | 2 | ||||
-rwxr-xr-x | yoyo/connections.py | 4 | ||||
-rwxr-xr-x | yoyo/utils.py | 6 |
5 files changed, 35 insertions, 3 deletions
@@ -283,6 +283,14 @@ MySQL database = mysql://scott:tiger@/mydatabase?unix_socket=/tmp/mysql.sock +MySQL with MySQLdb +~~~~~ + +:: + + # Use the MySQLdb driver instead of pymysql + database = mysql+mysqldb://scott:tiger@localhost/mydatabase + PostgreSQL ~~~~~~~~~~ diff --git a/yoyo/backends.py b/yoyo/backends.py index bce98f6..0fd621a 100644 --- a/yoyo/backends.py +++ b/yoyo/backends.py @@ -370,6 +370,24 @@ class MySQLBackend(DatabaseBackend): return self.driver.connect(**kwargs) +class MySQLdbBackend(DatabaseBackend): + + driver_module = 'MySQLdb' + def connect(self, dburi): + kwargs = dburi.args + if dburi.username is not None: + kwargs['user'] = dburi.username + if dburi.password is not None: + kwargs['passwd'] = dburi.password + if dburi.hostname is not None: + kwargs['host'] = dburi.hostname + if dburi.port is not None: + kwargs['port'] = dburi.port + kwargs['db'] = dburi.database + + return self.driver.connect(**kwargs) + + class SQLiteBackend(DatabaseBackend): driver_module = 'sqlite3' diff --git a/yoyo/compat.py b/yoyo/compat.py index ff151b3..4b4750e 100755 --- a/yoyo/compat.py +++ b/yoyo/compat.py @@ -50,7 +50,7 @@ else: exec(code, globals_) -if PY2: +if PY2 and hasattr(sys.stdout, 'isatty'): # In python2 sys.stdout is a byte stream. # Convert it to a unicode stream using the environment's preferred encoding if sys.stdout.isatty(): diff --git a/yoyo/connections.py b/yoyo/connections.py index 81ac22d..27b0abb 100755 --- a/yoyo/connections.py +++ b/yoyo/connections.py @@ -20,7 +20,8 @@ from .migrations import default_migration_table from .backends import (PostgresqlBackend, SQLiteBackend, ODBCBackend, - MySQLBackend) + MySQLBackend, + MySQLdbBackend) from .compat import urlsplit, urlunsplit, parse_qsl, urlencode, quote, unquote BACKENDS = { @@ -29,6 +30,7 @@ BACKENDS = { 'postgres': PostgresqlBackend, 'psql': PostgresqlBackend, 'mysql': MySQLBackend, + 'mysql+mysqldb': MySQLdbBackend, 'sqlite': SQLiteBackend, } diff --git a/yoyo/utils.py b/yoyo/utils.py index 4e18328..66f9725 100755 --- a/yoyo/utils.py +++ b/yoyo/utils.py @@ -45,7 +45,11 @@ try: return a except ImportError: - from msvcrt import getch + # some non windows environments don't hav termios (google cloud) + # running yoyo through the python sdk should not require `getch` + try: + from msvcrt import getch + except: pass def prompt(prompt, options): |