Created
July 15, 2015 19:28
-
-
Save meeuw/5dda69ae94dff600c394 to your computer and use it in GitHub Desktop.
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 subprocess | |
import sys | |
import re | |
import json | |
def batch_execute(args): | |
print args[0] | |
return subprocess.check_output( | |
[ | |
'mysql', | |
'-Be', | |
] + args | |
) | |
database = sys.argv[1] | |
output = subprocess.check_output( | |
[ | |
'mysqldump', | |
'-d', | |
database | |
] | |
) | |
for line in output.splitlines(): | |
m = re.match(r'^CREATE TABLE `([^`]*)', line) | |
if m: | |
table = m.group(1) | |
m = re.match(r' `([^`]*)` (.*) NOT NULL([^,]*)', line) | |
if m: | |
key = m.group(1) | |
print 'ALTER TABLE `%s` MODIFY COLUMN `%s` %s;' % (table, m.group(1), m.group(2)+m.group(3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment