Skip to content

Commit

Permalink
-Added support for database '--to' command, which allows specifying t…
Browse files Browse the repository at this point in the history
…he version to which to migrate
  • Loading branch information
David Cardon committed Sep 1, 2010
1 parent 500832c commit bc97774
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 28 additions & 5 deletions commands.py
Expand Up @@ -6,12 +6,30 @@
def getDbArg():
grab_next = False
for arg in sys.argv:
if arg.startswith("--db"):
if arg.strip() == "--db":
grab_next = True
elif grab_next == True:
print "~ Processing specified database: " + arg
return arg
elif arg.startswith("--db=") or grab_next == True:
spec_db = arg.replace("--db","")
print "~ Processing specified database: " + spec_db
return spec_db

return None

# ~~~~~~~~~~~~~~~~~~~~~~ getUpToVersion() is to look up the desired migration version number, to which we'd like to migrate
def getUpToVersion():
grab_next = False
for arg in sys.argv:
if arg.strip() == "--to":
grab_next = True
elif arg.startswith("--to=") or grab_next == True:
try:
to_version = int(arg.replace("--to=",""))
print "~ Migrating to version: %(tv)s" % {'tv': to_version}
return to_version
except TypeError:
print "~ ERROR: unable to parse --to argument: '%(ta)s'" % { 'ta': arg }
return None

return None

# ~~~~~~~~~~~~~~~~~~~~~~ getVersion(dbname) is to look up the version number of the database
Expand Down Expand Up @@ -283,6 +301,8 @@ def up():

db_arg = getDbArg()

to_version = getUpToVersion()

print "~ Database migration:"
print "~ "
for db in db_list:
Expand All @@ -308,7 +328,9 @@ def up():
continue
print "~ Migrating..."
command_strings = getCommandStrings()
for i in range(int(version) + 1, maxindex + 1):
if to_version == None or to_version > maxindex:
to_version = maxindex
for i in range(int(version) + 1, to_version + 1):
# Skip missed files
if files_obj[i] == None:
print "~ Patch " + str(i) + " is missing...skipped"
Expand Down Expand Up @@ -424,6 +446,7 @@ def dropAll():
print "~ migrate:drop-rebuild to drop and then rebuild all databases (use with caution!)"
print "~ "
print "~ Add --db={database name} to any command to only affect that database"
print "~ Add --to={version number} to any command to only migrate to the specified version number"
print "~ "

sys.exit(0)
4 changes: 3 additions & 1 deletion documentation/manual/home.textile
Expand Up @@ -131,4 +131,6 @@ You can see your database(s) current version number(s) and status(es) with the *

You can create a skeleton directory structure (with example files) with the **play migrate:init** command.

You can run any of the commands on just one database by adding '--db=[database name]' as an additional argument to the command.
You can run any of the commands on just one database by adding '--db=[database name]' as an additional argument to the command.

You can specify a database version to migrate to by adding 'to=[version number]' as an additional argument to the command.

0 comments on commit bc97774

Please sign in to comment.