Child: [c521e5] (diff)

Download this file

migrations.py    38 lines (32 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pylons import c
from flyway import Migration
from pyforge.model import Thread
from forgewiki.model import Page
class V0(Migration):
'''Migrate Thread.artifact_id to Thread.artifact_reference'''
version = 0
def __init__(self, *args, **kwargs):
super(V0, self).__init__(*args, **kwargs)
try:
c.project
except TypeError:
class EmptyClass(): pass
c._push_object(EmptyClass())
c.project = EmptyClass()
c.project._id = None
c.app = EmptyClass()
c.app.config = EmptyClass()
c.app.config.options = EmptyClass()
c.app.config.options.mount_point = None
def up(self):
for pg in self.ormsession.find(Page):
for t in self.ormsession.find(Thread, dict(artifact_id=pg._id)):
t.artifact_reference = pg.dump_ref()
t.artifact_id = None
self.ormsession.flush()
def down(self):
for pg in self.ormsession.find(Page):
for t in self.ormsession.find(Thread, dict(artifact_reference=pg.dump_ref())):
t.artifact_id = pg._id
t.artifact_reference = None
self.ormsession.flush()