Skip to content

Instantly share code, notes, and snippets.

@meeuw
Created July 15, 2015 19:28
Show Gist options
  • Save meeuw/5dda69ae94dff600c394 to your computer and use it in GitHub Desktop.
Save meeuw/5dda69ae94dff600c394 to your computer and use it in GitHub Desktop.
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