-
Notifications
You must be signed in to change notification settings - Fork 2
/
migrate.py
70 lines (59 loc) · 1.71 KB
/
migrate.py
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
# Python script that migrates our data from the old database to the new
# append only logfile backed database.
import sqlite3
import sys
import os
import json
# Takes as argument the name of the old database
arg = sys.argv[1]
# Call out to the shell to backup the old database
if os.system('cp ' + arg + ' ' + arg + '.bak') != 0:
print('Error backing up the old database')
sys.exit(1)
# delete the old database
if os.system('rm ' + arg) != 0:
print('Error deleting the old database')
sys.exit(1)
# Open the old database
old_db = sqlite3.connect(arg + '.bak')
# Open the new logfile backed database
log = open(arg, 'w')
# Select all talks from the old database
talks = old_db.execute('SELECT * FROM talks')
# map talk type to string
talk_type_map = {
0: 'forum topic',
1: 'lightning talk',
2: 'project update',
3: 'announcement',
4: 'after meeting slot'
}
# Write all talks to the new database
for talk in talks:
print(talk)
# Create the talk event
talk_event = {
'time': talk[7],
'type': 'create',
'create': {
'id': talk[0],
'name': talk[1],
'type': talk_type_map[talk[2]],
'description': talk[3],
'week': talk[5]
}
}
# Write the talk using the JSON format (without extra whitespace)
text = json.dumps(talk_event, separators=(',', ':'))
log.write(text + '\n')
# If the talk is hidden, write the hide event
if talk[4] == 1:
hide_event = {
'time': talk[7],
'type': 'hide',
'hide': {
'id': talk[0]
}
}
text = json.dumps(hide_event, separators=(',', ':'))
log.write(text + '\n')