|
@@ -1,8 +1,7 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
|
3
|
3
|
import copy
|
4
|
|
-import _mysql as mysqlclient
|
5
|
|
-import _mysql_exceptions
|
|
4
|
+import pymysql
|
6
|
5
|
|
7
|
6
|
import EditorialModel
|
8
|
7
|
|
|
@@ -43,7 +42,7 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
|
43
|
42
|
# @param db str : The db name
|
44
|
43
|
def __init__(self, host, user, password, db, db_engine = 'InnoDB', foreign_keys = True, debug = False, dryrun = False, drop_if_exists = False):
|
45
|
44
|
#Connect to MySQL
|
46
|
|
- self.db = mysqlclient.connect(host=host, user=user, passwd=password, db=db)
|
|
45
|
+ self.db = pymysql.connect(host=host, user=user, passwd=password, db=db)
|
47
|
46
|
self.debug = debug
|
48
|
47
|
self.dryrun = dryrun
|
49
|
48
|
self.db_engine = db_engine
|
|
@@ -93,7 +92,9 @@ class MysqlMigrationHandler(EditorialModel.migrationhandler.dummy.DummyMigration
|
93
|
92
|
if self.debug:
|
94
|
93
|
print(query+"\n")
|
95
|
94
|
if not self.dryrun:
|
96
|
|
- self.db.query(query)
|
|
95
|
+ with self.db.cursor() as cur:
|
|
96
|
+ cur.execute(query)
|
|
97
|
+ self.db.commit() #autocommit
|
97
|
98
|
|
98
|
99
|
## @brief Add a relationnal field
|
99
|
100
|
#
|
|
@@ -326,7 +327,7 @@ ADD COLUMN {col_name} {col_type} {col_specs};"""
|
326
|
327
|
)
|
327
|
328
|
try:
|
328
|
329
|
self._query(add_col)
|
329
|
|
- except _mysql_exceptions.OperationalError as e:
|
|
330
|
+ except pymysql.err.InternalError as e:
|
330
|
331
|
if drop_if_exists:
|
331
|
332
|
self._del_column(table_name, col_name)
|
332
|
333
|
self._add_column(table_name, col_name, col_fieldtype, drop_if_exists)
|
|
@@ -370,7 +371,7 @@ DROP FOREIGN KEY {fk_name}""".format(
|
370
|
371
|
src_table = self._idname_escape(src_table_name),
|
371
|
372
|
fk_name = self._idname_escape(self._fk_name(src_table_name, dst_table_name))
|
372
|
373
|
))
|
373
|
|
- except _mysql_exceptions.OperationalError: pass
|
|
374
|
+ except pymysql.err.InternalError: pass
|
374
|
375
|
|
375
|
376
|
def _fk_name(self, src_table_name, dst_table_name):
|
376
|
377
|
return "fk_%s_%s"%(src_table_name, dst_table_name)
|