Skip to content

Instantly share code, notes, and snippets.

@Widdershin
Created July 24, 2014 07:08
Show Gist options
  • Save Widdershin/2e3a0d560c08ade06e5e to your computer and use it in GitHub Desktop.
Save Widdershin/2e3a0d560c08ade06e5e to your computer and use it in GitHub Desktop.
Diff two migration folders
from unipath import Path
import re
MIGRATION_NAME_PATTERN = r"^\d+_(.*).rb$"
def get_migration_names(path):
return set(migration_name(migration_filename)
for migration_filename in
Path(path).listdir(names_only=True))
def migration_name(filename):
return re.match(MIGRATION_NAME_PATTERN, filename).group(1)
def compare_migrations():
old_migrations = get_migration_names('./db/migrated')
new_migrations = get_migration_names('./db/migrate')
new_migrations_not_in_old = new_migrations.difference(old_migrations)
print('\n'.join(new_migrations_not_in_old))
if __name__ == '__main__':
compare_migrations()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment