From 4d38b499411012e963d6381731260e1ef06174b5 Mon Sep 17 00:00:00 2001 From: n00b42 Date: Mon, 14 Nov 2022 02:55:59 +0100 Subject: [PATCH] Fix sqlite2mysql script problems with seahub_db (#5274) * scripts/sqlite2mysql: Fix non matching regex Regex was not matching for seahub.db export. e.g. 'CREATE TABLE IF NOT EXISTS "django_content_type" (...' was not matching. * fix default value quotation. * Update sqlite2mysql.py --- scripts/sqlite2mysql.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/sqlite2mysql.py b/scripts/sqlite2mysql.py index dfd9a395fb..63d7a3d182 100644 --- a/scripts/sqlite2mysql.py +++ b/scripts/sqlite2mysql.py @@ -41,7 +41,7 @@ for line in fileinput.input(): if re.match(r'^CREATE TABLE.*', line): searching_for_end = True - m = re.search('CREATE TABLE [`"]?(\w*)[`"]?(.*)', line) + m = re.search('CREATE TABLE(?: IF NOT EXISTS)? [`"]?(\w+)[`"]?(\s*\(.*)', line) if m: name, sub = m.groups() sub = sub.replace('"','`') @@ -67,6 +67,9 @@ for line in fileinput.input(): # replace " and ' with ` because mysql doesn't like quotes in CREATE commands line = line.replace('"', '`').replace("'", '`') + # fix default values parantheses + line = re.sub(r"default `([^`]*)`", r"default '\1'", line, 0, re.IGNORECASE) + # And now we convert it back (see above) if re.match(r".*, ``\);", line): line = re.sub(r'``\);', r"'');", line)