Skip to content

Instantly share code, notes, and snippets.

@or
Last active February 25, 2016 15:22
Show Gist options
  • Save or/9736ad5f89c9ff33294e to your computer and use it in GitHub Desktop.
Save or/9736ad5f89c9ff33294e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import re
import sys
from subprocess import check_output
if len(sys.argv) > 1:
base = sys.argv[1]
else:
base = 'develop'
command = "git diff --name-only --diff-filter=A {} | grep migrations".format(base)
new_files = check_output(command, shell=True)
apps = {}
for path in new_files.split('\n'):
mo = re.match(r'apps/(.*)/migrations/(\d+).*', path)
if not mo:
continue
app = mo.group(1)
first = int(mo.group(2))
if app not in apps:
apps[app] = first
else:
apps[app] = min(apps[app], first)
for app in apps:
print('./manage.py migrate {} {}'.format(app, 'zero' if apps[app] == 1 else '{:04d}'.format(apps[app] - 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment