Ticket #121: newmigration_fix.py

File newmigration_fix.py, 1.8 KB (added by Christopher Allan Webber, 13 years ago)

newmigration_fix.py

Line 
1# Fixes migrations for people who are coming pre-current migrations :)
2
3import os
4import sys
5import pymongo
6
7print "*** WARNING! ***"
8print " This script is ONLY for people who have data pre-modern migrations."
9print " If that's not you, don't run this!"
10print " Also makes the following assumptions:"
11print " - that you're running this on local branch 'master'"
12print " - that your master branch is up to date with latest mediagoblin"
13print " master"
14print " - You're running on database 'mediagoblin' on standard"
15print " connection parameters"
16print " - You're running this out of buildout"
17print " - That you don't have any modified files in your git checkout"
18print ""
19print "Consider yourself warned!"
20
21run_it = raw_input(
22 'Are you SURE you want to run this? (if so, type "yes")> ')
23
24if not run_it == 'yes':
25 sys.exit(1)
26
27print "~*** First applying old migrations... ***~\n"
28os.popen('git checkout 6ae8b541f957b49ae86051814097e769d20f29af')
29os.popen('echo "Old migrations running..." > migration_result.txt')
30os.popen('echo "=========================" >> migration_result.txt')
31os.popen('./bin/gmg migrate >> migration_result.txt')
32
33print "~*** Okay, now making sure your database is unmigrated... ***~\n"
34db = pymongo.Connection()['mediagoblin']
35db.drop_collection('app_metadata')
36db['app_metadata'].update(
37 {u'_id': u'mediagoblin'},
38 {u'$set': {u'current_migration': 0}},
39 upsert=True)
40
41print "~*** Checking back out master and running migrations... ***~\n"
42os.popen('git checkout master')
43os.popen('echo "\nNew migrations running..." >> migration_result.txt')
44os.popen('echo "=========================" >> migration_result.txt')
45os.popen('./bin/gmg migrate >> migration_result.txt')
46
47print "done, migration output available in migration_result.txt"