This repository has been archived by the owner on May 6, 2024. It is now read-only.
forked from glamkit/glamkit-eventtools
-
Notifications
You must be signed in to change notification settings - Fork 13
/
UPGRADING.txt
140 lines (94 loc) · 5.66 KB
/
UPGRADING.txt
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
2 September 2011:
This revision contains a breaking change in the Occurrence and Generator models, to use start + duration, rather than start + end, and to have consistency between their APIs.
The Generator model repeat_until is now a date, rather than a datetime, for simplicity (only one occurrence per day is generated).
To migrate, using South:
1) Create a migration representing your app's current state, if you haven't already.
2) Update event tools to a current version.
3) Create a manual migration which adds the _duration fields to Occurrence and Generator (see sample code)
def forwards(self, orm):
# Adding field 'Occurrence.duration'
db.add_column('events_occurrence', '_duration', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True), keep_default=False)
# Copy info over
for o in orm['events.occurrence'].objects.all():
if o.end and o.end != o.start:
td = o.end - o.start
secs = td.days * 24 * 60 * 60 + td.seconds
o._duration = secs/60
o.save()
# Adding field 'Generator._duration'
db.add_column('events_generator', '_duration', self.gf('django.db.models.fields.PositiveIntegerField')(null=True, blank=True), keep_default=False)
# Copy info over
for g in orm['events.generator'].objects.all():
if g.event_end and g.event_end != g.event_start:
td = g.event_end - g.event_start
secs = td.days * 24 * 60 * 60 + td.seconds
g._duration = secs/60
g.save()
def backwards(self, orm):
# Deleting field 'Occurrence.duration'
db.delete_column('events_occurrence', '_duration')
# Deleting field 'Generator._duration'
db.delete_column('events_generator', '_duration')
4) Create a manual migration which removes the *end fields
def forwards(self, orm):
# Deleting field 'Occurrence.end'
db.delete_column('events_occurrence', 'end')
# Deleting field 'Generator.event_end'
db.delete_column('events_generator', 'event_end')
def backwards(self, orm):
# Adding field 'Occurrence.end'
db.add_column('events_occurrence', 'end', self.gf('django.db.models.fields.DateTimeField')(default='', blank=True, db_index=True), keep_default=False)
for o in orm['events.occurrence'].objects.all():
if o._duration:
o.end = o.start + datetime.timedelta(seconds = o._duration * 60)
else:
o.end = o.start
o.save()
# Adding field 'Generator.event_end'
db.add_column('events_generator', 'event_end', self.gf('django.db.models.fields.DateTimeField')(default='', blank=True, db_index=True), keep_default=False)
for o in orm['events.generator'].objects.all():
if o._duration:
o.event_end = o.event_start + datetime.timedelta(seconds = o._duration * 60)
else:
o.event_end = o.event_start
o.save()
5) Create a manual migration which renames event_start to start in Generator
def forwards(self, orm):
# Renaming field 'Generator.event_start'
db.rename_column('events_generator', 'event_start', 'start')
def backwards(self, orm):
# Renaming field 'Generator.start'
db.rename_column('events_generator', 'start', 'event_start')
6) Create a manual migration which adds repeat_until_date to Generator, and populates the values
def forwards(self, orm):
# Adding field 'Generator.repeat_until_date'
db.add_column('events_generator', 'repeat_until_date', self.gf('django.db.models.fields.DateField')(null=True, blank=True), keep_default=False)
for o in orm['events.generator'].objects.all():
if o.repeat_until:
o.repeat_until_date = o.repeat_until.date()
o.save()
def backwards(self, orm):
# Deleting field 'Generator.repeat_until_date'
db.delete_column('events_generator', 'repeat_until_date')
7) Create a manual migration which removes repeat_until (the datetime), and renames repeat_until_date to repeat_until.
def forwards(self, orm):
# Deleting field 'Generator.repeat_until'
db.delete_column('events_generator', 'repeat_until')
db.rename_column('events_generator', 'repeat_until_date', 'repeat_until')
def backwards(self, orm):
# Adding field 'Generator.repeat_until'
db.rename_column('events_generator', 'repeat_until', 'repeat_until_date')
db.add_column('events_generator', 'repeat_until', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
for o in orm['events.generator'].objects.all():
if o.repeat_until_date:
o.repeat_until = datetime.datetime.combine(o.repeat_until_date, datetime.time.max)
o.save()
8) ./manage.py schemamigration youreventsapp --auto should pick up any other changes (fields which are now required, etc.). However, the GeneratorModel rule field is now required. In EventTools 1, Generators without a rule were 'one-off' events, which should now be stored as separate Occurrences. (If you do a migration like this, update this document with sample code!)
# === Snippet to migrate exclusions from generators ===
from dateutil import parser
class Migration(SchemaMigration):
def forwards(self, orm):
for generator in orm['events.generator'].objects.filter(exceptions__isnull=False):
for exc in generator.exceptions.keys():
dt = parser.parse(exc)
orm['events.exclusion'].objects.create(event=generator.event, start=dt)