Created
April 19, 2020 06:45
-
-
Save ian-otto/ad5709d60e777a0b240f8fd762b55d94 to your computer and use it in GitHub Desktop.
Hacky solution converts a single-insert-per-line MySQL dump, to a multiple insert per line MySQL dump.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
with open(sys.argv[1], 'r') as inf: | |
with open('migrate_new/' + sys.argv[1], 'w') as outf: | |
line = inf.readline() | |
base = "" | |
started = False | |
counter = 0 | |
while line: | |
if line.startswith("INSERT INTO"): | |
if not started: | |
started = True | |
base = line[:-2] | |
else: | |
counter += 1 | |
base += "," + line[line.find("VALUES ") + len("VALUES "):-2] | |
if counter >= 1000: # perform 1000 entries at the same time | |
counter = 0 | |
base += ';' | |
started = False | |
outf.write(base + "\n") | |
base = "" | |
else: | |
if base != "": | |
counter = 0 | |
base += ';' | |
started = False | |
outf.write(base + "\n") | |
base = "" | |
outf.write(line) | |
line = inf.readline() | |
if base != "": | |
outf.write(base + ";\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment