Parent: [a7a206] (diff)

Child: [903515] (diff)

Download this file

migrations.py    187 lines (168 with data), 6.5 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
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from pylons import c
from flyway import Migration
import ming
from ming.orm import mapper, ORMSession, session, state
from pyforge import model as M
from pyforge.ext.project_home import model as PM
from forgetracker import model as TM
from forgewiki import model as WM
from helloforge import model as HM
from forgediscussion import model as DM
from forgescm import model as SM
class UpdateThemeToShinyBook(Migration):
version = 3
def up_requires(self):
yield ('pyforge', 2)
def up(self):
if self.session.db.name == 'pyforge':
theme = self.ormsession.find(M.Theme, {'name':'forge_default'}).first()
theme.color1='#0088cc'
theme.color2='#000000'
theme.color3='#454545'
theme.color4='#6c7681'
theme.color5='#d8d8d8'
theme.color6='#ececec'
self.ormsession.update_now(theme, state(theme))
self.ormsession.flush()
def down(self):
if self.session.db.name == 'pyforge':
theme = self.ormsession.find(M.Theme, {'name':'forge_default'}).first()
theme.color1='#104a75'
theme.color2='#aed0ea'
theme.color3='#EDF3FB'
theme.color4='#D7E8F5'
theme.color5='#000'
theme.color6='#000'
self.ormsession.update_now(theme, state(theme))
self.ormsession.flush()
class RenameNeighborhoods(Migration):
version = 2
def up_requires(self):
yield ('pyforge', 1)
def up(self):
n_users = self.ormsession.find(M.Neighborhood, dict(name='Users')).first()
n_projects = self.ormsession.find(M.Neighborhood, dict(name='Projects')).first()
if n_users:
n_users.url_prefix = '/u/'
n_users.shortname_prefix = 'u/'
if n_projects:
n_projects.url_prefix = '/p/'
for p in self.ormsession.find(M.Project, {}):
if p.shortname.startswith('users/'):
p.shortname = p.shortname.replace('users/', 'u/')
self.ormsession.flush()
def down(self):
n_users = self.ormsession.find(M.Neighborhood, dict(name='Users')).first()
n_projects = self.ormsession.find(M.Neighborhood, dict(name='Projects')).first()
if n_users:
n_users.url_prefix = '/users/'
n_users.shortname_prefix = 'users/'
if n_projects:
n_projects.url_prefix = '/projects/'
for p in self.ormsession.find(M.Project, {}):
if p.shortname.startswith('u/'):
p.shortname = p.shortname.replace('u/', 'users/')
self.ormsession.flush()
class DowncaseMountPoints(Migration):
version = 1
def __init__(self, *args, **kwargs):
super(DowncaseMountPoints, 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_requires(self):
yield ('ForgeWiki', 0)
yield ('ForgeTracker', 0)
yield ('pyforge', 0)
def up(self):
# Fix neigborhoods
for n in self.ormsession.find(M.Neighborhood, {}):
n.name = n.name.lower().replace(' ', '_')
n.shortname_prefix = n.shortname_prefix.lower().replace(' ', '_')
# Fix Projects
for p in self.ormsession.find(M.Project, {}):
p.shortname = p.shortname.lower().replace(' ', '_')
# Fix AppConfigs
for ac in self.ormsession.find(M.AppConfig, {}):
ac.options.mount_point = ac.options.mount_point.lower().replace(' ', '_')
if ac.plugin_name == 'Forum':
ac.plugin_name = 'Discussion'
self.ormsession.flush(); self.ormsession.clear()
# Fix ArtifactLinks
for al in self.ormsession.find(M.ArtifactLink, {}):
fix_aref(al.artifact_reference)
# Fix feeds
for f in self.ormsession.find(M.Feed, {}):
fix_aref(f.artifact_reference)
# Fix notifications
for n in self.ormsession.find(M.Notification, {}):
fix_aref(n.artifact_reference)
# Fix tags
for n in self.ormsession.find(M.TagEvent, {}):
fix_aref(n.artifact_ref)
for n in self.ormsession.find(M.UserTags, {}):
fix_aref(n.artifact_reference)
for n in self.ormsession.find(M.Tag, {}):
fix_aref(n.artifact_ref)
# fix PortalConfig
for pc in self.ormsession.find(PM.PortalConfig):
for layout in pc.layout:
for w in layout.content:
w.mount_point = w.mount_point.lower().replace(' ', '_')
# Fix thread (has explicit artifact_reference property)
for t in self.ormsession.find(M.Thread, {}):
fix_aref(t.artifact_reference)
for t in self.ormsession.find(DM.ForumThread, {}):
fix_aref(t.artifact_reference)
self.ormsession.flush(); self.ormsession.clear()
# fix artifacts
for cls in (
M.Artifact,
M.VersionedArtifact,
M.Snapshot,
M.Message,
M.Post,
M.AwardGrant,
M.Discussion,
M.Award,
M.Thread,
M.Post,
M.PostHistory,
DM.Forum,
DM.ForumPost,
DM.forum.ForumPostHistory,
DM.ForumThread,
WM.Page,
WM.wiki.PageHistory,
SM.Repository,
SM.Commit,
TM.Bin,
TM.Ticket,
TM.ticket.TicketHistory,
PM.PortalConfig,
):
self.fix_artifact_cls(cls)
def down(self):
pass # Do nothing
def fix_artifact_cls(self, cls):
for obj in self.ormsession.find(cls, {}):
for ref in obj.references:
fix_aref(ref)
for ref in obj.backreferences.itervalues():
fix_aref(ref)
self.ormsession.flush(); self.ormsession.clear()
class V0(Migration):
version = 0
def up(self): pass
def down(self): pass
def fix_aref(aref):
if aref and aref.mount_point:
aref.mount_point = aref.mount_point.lower().replace(' ', '_')