Opened 13 years ago

Last modified 13 years ago

#121 closed defect (FIXED)

Handle migrations ourselves (NOT through mongokit)

Reported by: Christopher Allan Webber Owned by: Christopher Allan Webber
Priority: minor Milestone: 0.0.4
Component: programming Keywords:
Cc: Parent Tickets:

Description

Mongokit's migrations system stuff is complex and way confusing.
Here's something much simpler.


-  migrations are simple functions, iterated by number. You create
   them and register them with a decorator registering what "number"
   they are like so:

   @register\_migration(1) def ponies\_to\_unicorns(database):
   database['quadrapeds'].find( {'animal': 'pony'}).update{ {'$set':
   {'animal': 'unicorn'}})


or whatever else you need to do with that connection. The first and
only argument passed in (database) is a simple pymongo database
connection (**not** mongokit!). Otherwise, it's just a simple
python function. Do what you need to do.


-  current migration status is stored in the ['\_id'] =
   'mediagoblin' document of database['app\_metadata'] in the field
   ['migration\_number']
-  if no migrations have been run yet, migration\_number set to
   current max
-  otherwise all unrun migrations are run, and migration\_number
   updated after each migration finishes.



Attachments (1)

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

Download all attachments as: .zip

Change History (6)

comment:1 by Christopher Allan Webber, 13 years ago

New migrations are **ready for merge**! It includes really good
tests, so I'm pretty confident that it really is ready!

[https://gitorious.org/\ :sub:`cwebber/mediagoblin/cwebbers-mediagoblin/commits/f411\_new\_migrations](https://gitorious.org/`\ cwebber/mediagoblin/cwebbers-mediagoblin/commits/f411\_new\_migrations)

Honestly, the reason I haven't merged it is once we dump a
migration into here is that the first migration might not apply for
reasons that are confusing to describe. I'll write a nice script to
handle that and post it with an announcement to the list tomorrow
once I do the proper merge. Then I'll write the first merge:

`http://bugs.foocorp.net/issues/372 <http://bugs.foocorp.net/issues/372>`_

should be pretty simple!



comment:2 by Christopher Allan Webber, 13 years ago

Status: NewIn Progress

comment:2 by Christopher Allan Webber, 13 years ago

Status: In ProgressClosed
This is finally done and even pushed live. If you have an old
database, you might need to run a script... see the mailing list.

Everything works though, yay!



by Christopher Allan Webber, 13 years ago

Attachment: newmigration_fix.py added

newmigration_fix.py

comment:3 by Christopher Allan Webber, 13 years ago

Here's the relevant script in case you care. Run like:

::

    ./bin/python newmigration_fix.py



comment:4 by Will Kahn-Greene, 13 years ago

The original url for this bug was http://bugs.foocorp.net/issues/411 .
Relations:
#111: blocks, #86: blocks

Note: See TracTickets for help on using tickets.