Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

107 lines (71 sloc) 2.5 kb
import logging
from models import Image
from models import Status
def register(migration):
""" Register a migratin with the runner """
MIGRATIONS[migration.__name__] = migration
def find(migration_name):
""" Return the migration for a given class name
If no migration found, returns None
key -- Name of a migration class
if migration_name in MIGRATIONS:
return MIGRATIONS[migration_name]
return None
def all():
""" Return all registred migrations """
return MIGRATIONS.values()
def clear():
""" Clear all registerd migrations """
class Migration(object):
"""App Engine data migration
A doc string is where you describe what your migration does
No output is shown to the user, so make liberal use logging.
Before running a migration on produciton data, download portitions of
real data into an sample application using the bulk exporter
Register migrations with the MigrationRunner.register method
def name(cls):
return cls.__name__
def start(self):"Staring migration %s" % self.__class__.__name__)"Finished migration %s" % self.__class__.__name__)
def run(self):
"""Run the migration """
class UpdateStatusMigration(Migration):
""" Migrate sample data
This migration does nothing. NOTHING!
def run(self):"Update each status")
# For each status
for status in Status.all().fetch(100):
# Set the status to default
status.default = False
# Update the status url
status.image = "icons/fugue/" + status.image + ".png"
# Save the status
# Get the up status and make it default
default_status = Status.get_by_slug("up")
if default_status is None:
logging.error("Could not find the up status")
default_status.default = True
default_status.put()"Set up status as the default")
class AddImagesMigration(Migration):
""" Add images to the database """
def run(self):"Load the images into the database")
Image.load_defaults()"Loading complete")
Jump to Line
Something went wrong with that request. Please try again.