@@ -10,7 +10,7 @@ import ProfilesZomeApi from '../api/profilesApi'
10
10
import { getAppWs } from '../hcWebsockets'
11
11
import { cellIdFromString } from '../utils'
12
12
import { createTag } from '../redux/persistent/projects/tags/actions'
13
- import { Outcome } from '../types'
13
+ import { Outcome , Tag } from '../types'
14
14
import { WireRecord } from '../api/hdkCrud'
15
15
import { ActionHashB64 } from '../types/shared'
16
16
@@ -45,43 +45,89 @@ export default async function importAllProjectData(
45
45
...old ,
46
46
isImported : true ,
47
47
}
48
- const importedProfile = await profilesZomeApi . profile . createImportedProfile ( profilesCellId , clone )
49
- await dispatch (
50
- createImportedProfile ( profilesCellIdString , importedProfile )
48
+ const importedProfile = await profilesZomeApi . profile . createImportedProfile (
49
+ profilesCellId ,
50
+ clone
51
51
)
52
+ await dispatch ( createImportedProfile ( profilesCellIdString , importedProfile ) )
53
+ }
54
+
55
+ // do things with no data references first
56
+
57
+ // TAGS
58
+ // do tags because outcomes reference them
59
+ const tagActionHashMap : {
60
+ [ oldActionHash : ActionHashB64 ] : ActionHashB64
61
+ } = { }
62
+ // TAGS
63
+ // only v1.0.0-alpha and beyond have tags
64
+ for ( let address of Object . keys ( projectData . tags ) ) {
65
+ const old = projectData . tags [ address ]
66
+ const clone = {
67
+ ...old ,
68
+ }
69
+ // an assigned field
70
+ // v1.0.4-alpha
71
+ delete clone . actionHash
72
+ // v1.0.0-alpha
73
+ delete clone . headerHash
74
+
75
+ let newTag : WireRecord < Tag >
76
+ try {
77
+ newTag = await projectsZomeApi . tag . create ( projectsCellId , clone )
78
+ dispatch ( createTag ( projectsCellIdString , newTag ) )
79
+ } catch ( e ) {
80
+ console . log ( 'createTag error' , e )
81
+ throw e
82
+ }
83
+
84
+ // add this new tag address to the tagActionHashMap
85
+ // to keep of which new addresses map to which old addresses
86
+ let oldTagActionHash : ActionHashB64
87
+ // as of v1.0.4-alpha
88
+ if ( old . actionHash ) oldTagActionHash = old . actionHash
89
+ // pre 1.0.4-alpha (1.x series)
90
+ else if ( old . headerHash ) oldTagActionHash = old . headerHash
91
+
92
+ tagActionHashMap [ oldTagActionHash ] = newTag . actionHash
52
93
}
53
94
54
95
// OUTCOMES
55
- const outcomeActionHashMap : { [ oldActionHash : ActionHashB64 ] : ActionHashB64 } = { }
56
- // do the outcomes second, since pretty much everything else
96
+ const outcomeActionHashMap : {
97
+ [ oldActionHash : ActionHashB64 ] : ActionHashB64
98
+ } = { }
99
+ // do the outcomes third, since pretty much everything else
57
100
// is sub-data to the outcomes
58
101
for ( let outcomeActionHash of Object . keys ( projectData . outcomes ) ) {
59
102
const oldOutcome = projectData . outcomes [ outcomeActionHash ]
60
103
const clone = {
61
104
...oldOutcome ,
105
+ // make sure tag references hold up through the migration
106
+ tags : oldOutcome . tags . map (
107
+ ( oldTagHash : ActionHashB64 ) => tagActionHashMap [ oldTagHash ]
108
+ ) ,
62
109
isImported : true ,
63
110
}
64
- // v0.5 .4-alpha
111
+ // as of v1.0 .4-alpha
65
112
delete clone . actionHash
66
- // pre v0.5.3 -alpha and prior
67
- delete clone . address
113
+ // as of v0.5.4 -alpha
114
+ delete clone . headerHash
68
115
69
116
let newOutcome : WireRecord < Outcome >
70
117
try {
71
118
newOutcome = await projectsZomeApi . outcome . create ( projectsCellId , clone )
72
- dispatch (
73
- createOutcome ( projectsCellIdString , newOutcome )
74
- )
119
+ dispatch ( createOutcome ( projectsCellIdString , newOutcome ) )
75
120
} catch ( e ) {
76
121
console . log ( 'createOutcome error' , e )
77
122
throw e
78
123
}
79
124
// add this new outcome address to the outcomeActionHashMap
80
125
// to keep of which new addresses map to which old addresses
81
126
let oldOutcomeActionHash : ActionHashB64
82
- // v0.5 .4-alpha
127
+ // as of v1.0 .4-alpha
83
128
if ( oldOutcome . actionHash ) oldOutcomeActionHash = oldOutcome . actionHash
84
- // pre v0.5.3-alpha and prior
129
+ // as of v0.5.4-alpha
130
+ if ( oldOutcome . headerHash ) oldOutcomeActionHash = oldOutcome . headerHash
85
131
else if ( oldOutcome . address ) oldOutcomeActionHash = oldOutcome . address
86
132
87
133
outcomeActionHashMap [ oldOutcomeActionHash ] = newOutcome . actionHash
@@ -90,30 +136,43 @@ export default async function importAllProjectData(
90
136
// CONNECTIONS
91
137
for ( let address of Object . keys ( projectData . connections ) ) {
92
138
const old = projectData . connections [ address ]
93
- console . log ( old )
139
+ // v1.0.4-alpha: parentActionHash
140
+ // v1.0.3-alpha and prior: parentHeaderHash
141
+ const newParentOutcomeActionHash = old . parentHeaderHash
142
+ ? outcomeActionHashMap [ old . parentHeaderHash ]
143
+ : outcomeActionHashMap [ old . parentActionHash ]
144
+ // v1.0.4-alpha: childActionHash
145
+ // v1.0.3-alpha and prior: childHeaderHash
146
+ const newChildOutcomeActionHash = old . childHeaderHash
147
+ ? outcomeActionHashMap [ old . childHeaderHash ]
148
+ : outcomeActionHashMap [ old . childActionHash ]
94
149
const clone = {
95
150
...old ,
96
- parentActionHash : outcomeActionHashMap [ old . parentActionHash ] ,
97
- childActionHash : outcomeActionHashMap [ old . childActionHash ] ,
151
+ parentActionHash : newParentOutcomeActionHash ,
152
+ childActionHash : newChildOutcomeActionHash ,
98
153
// randomizer used to be a float, but is now an int
99
154
randomizer : Number ( old . randomizer . toFixed ( ) ) ,
100
155
isImported : true ,
101
156
}
157
+ // pre v1.0.4-alpha
158
+ delete clone . parentHeaderHash
159
+ delete clone . childHeaderHash
102
160
// an assigned field
103
- // v0.5 .4-alpha
161
+ // as of v1.0 .4-alpha
104
162
delete clone . actionHash
105
- // pre v0.5.3 -alpha and prior
106
- delete clone . address
163
+ // v0.5.4 -alpha
164
+ delete clone . headerHash
107
165
108
166
if ( ! clone . childActionHash || ! clone . parentActionHash ) {
109
167
console . log ( 'weird, invalid connection:' , clone )
110
168
continue
111
169
}
112
170
try {
113
- const createdConnection = await projectsZomeApi . connection . create ( projectsCellId , clone )
114
- dispatch (
115
- createConnection ( projectsCellIdString , createdConnection )
171
+ const createdConnection = await projectsZomeApi . connection . create (
172
+ projectsCellId ,
173
+ clone
116
174
)
175
+ dispatch ( createConnection ( projectsCellIdString , createdConnection ) )
117
176
} catch ( e ) {
118
177
console . log ( 'createConnection error' , e )
119
178
throw e
@@ -123,26 +182,34 @@ export default async function importAllProjectData(
123
182
// OUTCOME MEMBERS
124
183
for ( let address of Object . keys ( projectData . outcomeMembers ) ) {
125
184
const old = projectData . outcomeMembers [ address ]
185
+ // v1.0.4-alpha: outcomeActionHash
186
+ // v1.0.3-alpha and prior: outcomeHeaderHash
187
+ const newOutcomeActionHash = old . outcomeHeaderHash
188
+ ? outcomeActionHashMap [ old . outcomeHeaderHash ]
189
+ : outcomeActionHashMap [ old . outcomeActionHash ]
126
190
const clone = {
127
191
...old ,
128
- outcomeActionHash : outcomeActionHashMap [ old . outcomeActionHash ] ,
192
+ outcomeActionHash : newOutcomeActionHash ,
129
193
isImported : true ,
130
194
}
195
+ // pre v1.0.4-alpha
196
+ delete clone . outcomeHeaderHash
131
197
// an assigned field
132
- // v0.5 .4-alpha
198
+ // v1.0 .4-alpha
133
199
delete clone . actionHash
134
- // pre v0.5.3 -alpha and prior
135
- delete clone . address
200
+ // v0.5.4 -alpha
201
+ delete clone . headerHash
136
202
137
203
if ( ! clone . outcomeActionHash ) {
138
204
console . log ( 'weird, invalid outcomeMember:' , clone )
139
205
continue
140
206
}
141
207
try {
142
- const createdOutcomeMember = await projectsZomeApi . outcomeMember . create ( projectsCellId , clone )
143
- dispatch (
144
- createOutcomeMember ( projectsCellIdString , createdOutcomeMember )
208
+ const createdOutcomeMember = await projectsZomeApi . outcomeMember . create (
209
+ projectsCellId ,
210
+ clone
145
211
)
212
+ dispatch ( createOutcomeMember ( projectsCellIdString , createdOutcomeMember ) )
146
213
} catch ( e ) {
147
214
console . log ( 'createOutcomeMember error' , e )
148
215
throw e
@@ -152,23 +219,33 @@ export default async function importAllProjectData(
152
219
// OUTCOME COMMENTS
153
220
for ( let address of Object . keys ( projectData . outcomeComments ) ) {
154
221
const old = projectData . outcomeComments [ address ]
222
+ // v1.0.4-alpha: outcomeActionHash
223
+ // v1.0.3-alpha and prior: outcomeHeaderHash
224
+ const newOutcomeActionHash = old . outcomeHeaderHash
225
+ ? outcomeActionHashMap [ old . outcomeHeaderHash ]
226
+ : outcomeActionHashMap [ old . outcomeActionHash ]
155
227
const clone = {
156
228
...old ,
157
- outcomeActionHash : outcomeActionHashMap [ old . outcomeActionHash ] ,
229
+ outcomeActionHash : newOutcomeActionHash ,
158
230
isImported : true ,
159
231
}
232
+ // pre v1.0.4-alpha
233
+ delete clone . outcomeHeaderHash
160
234
// an assigned field
161
- // v0.5 .4-alpha
235
+ // v1.0 .4-alpha
162
236
delete clone . actionHash
163
- // pre v0.5.3 -alpha and prior
164
- delete clone . address
237
+ // v0.5.4 -alpha
238
+ delete clone . headerHash
165
239
166
- if ( ! clone . outcomeActionHash ) {
240
+ if ( ! clone . outcomeActionHash && ! clone . outcomeHeaderHash ) {
167
241
console . log ( 'weird, invalid outcomeComment:' , clone )
168
242
continue
169
243
}
170
244
try {
171
- const createdOutcomeComment = await projectsZomeApi . outcomeComment . create ( projectsCellId , clone )
245
+ const createdOutcomeComment = await projectsZomeApi . outcomeComment . create (
246
+ projectsCellId ,
247
+ clone
248
+ )
172
249
dispatch (
173
250
createOutcomeComment ( projectsCellIdString , createdOutcomeComment )
174
251
)
@@ -181,26 +258,34 @@ export default async function importAllProjectData(
181
258
// OUTCOME VOTES
182
259
for ( let address of Object . keys ( projectData . outcomeVotes ) ) {
183
260
const old = projectData . outcomeVotes [ address ]
261
+ // v1.0.4-alpha: outcomeActionHash
262
+ // v1.0.3-alpha and prior: outcomeHeaderHash
263
+ const newOutcomeActionHash = old . outcomeHeaderHash
264
+ ? outcomeActionHashMap [ old . outcomeHeaderHash ]
265
+ : outcomeActionHashMap [ old . outcomeActionHash ]
184
266
const clone = {
185
267
...old ,
186
- outcomeActionHash : outcomeActionHashMap [ old . outcomeActionHash ] ,
268
+ outcomeActionHash : newOutcomeActionHash ,
187
269
isImported : true ,
188
270
}
271
+ // pre v1.0.4-alpha
272
+ delete clone . outcomeHeaderHash
189
273
// an assigned field
190
- // v0.5 .4-alpha
274
+ // v1.0 .4-alpha
191
275
delete clone . actionHash
192
- // pre v0.5.3 -alpha and prior
193
- delete clone . address
276
+ // v0.5.4 -alpha
277
+ delete clone . headerHash
194
278
195
- if ( ! clone . outcomeActionHash ) {
279
+ if ( ! clone . outcomeActionHash && ! clone . outcomeHeaderHash ) {
196
280
console . log ( 'weird, invalid outcomeVote:' , clone )
197
281
continue
198
282
}
199
283
try {
200
- const createdOutcomeVote = await projectsZomeApi . outcomeVote . create ( projectsCellId , clone )
201
- dispatch (
202
- createOutcomeVote ( projectsCellIdString , createdOutcomeVote )
284
+ const createdOutcomeVote = await projectsZomeApi . outcomeVote . create (
285
+ projectsCellId ,
286
+ clone
203
287
)
288
+ dispatch ( createOutcomeVote ( projectsCellIdString , createdOutcomeVote ) )
204
289
} catch ( e ) {
205
290
console . log ( 'createOutcomeVote error' , e )
206
291
throw e
@@ -210,56 +295,40 @@ export default async function importAllProjectData(
210
295
// ENTRY POINTS
211
296
for ( let address of Object . keys ( projectData . entryPoints ) ) {
212
297
const old = projectData . entryPoints [ address ]
298
+ // v1.0.4-alpha: outcomeActionHash
299
+ // v1.0.3-alpha and prior: outcomeHeaderHash
300
+ const newOutcomeActionHash = old . outcomeHeaderHash
301
+ ? outcomeActionHashMap [ old . outcomeHeaderHash ]
302
+ : outcomeActionHashMap [ old . outcomeActionHash ]
213
303
const clone = {
214
304
...old ,
215
- outcomeActionHash : outcomeActionHashMap [ old . outcomeActionHash ] ,
305
+ outcomeActionHash : newOutcomeActionHash ,
216
306
isImported : true ,
217
307
}
308
+ // pre v1.0.4-alpha
309
+ delete clone . outcomeHeaderHash
218
310
// an assigned field
219
- // v0.5 .4-alpha
311
+ // v1.0 .4-alpha
220
312
delete clone . actionHash
221
- // pre v0.5.3 -alpha and prior
222
- delete clone . address
313
+ // v0.5.4 -alpha
314
+ delete clone . headerHash
223
315
224
- if ( ! clone . outcomeActionHash ) {
316
+ if ( ! clone . outcomeActionHash && ! clone . outcomeHeaderHash ) {
225
317
console . log ( 'weird, invalid entryPoint:' , clone )
226
318
continue
227
319
}
228
320
try {
229
- const createdEntryPoint = await projectsZomeApi . entryPoint . create ( projectsCellId , clone )
230
- dispatch (
231
- createEntryPoint ( projectsCellIdString , createdEntryPoint )
321
+ const createdEntryPoint = await projectsZomeApi . entryPoint . create (
322
+ projectsCellId ,
323
+ clone
232
324
)
325
+ dispatch ( createEntryPoint ( projectsCellIdString , createdEntryPoint ) )
233
326
} catch ( e ) {
234
327
console . log ( 'createEntryPoint error' , e )
235
328
throw e
236
329
}
237
330
}
238
331
239
- // TAGS
240
- // only v1.0.0-alpha and beyond have tags
241
- if ( projectData . tags ) {
242
- for ( let address of Object . keys ( projectData . tags ) ) {
243
- const old = projectData . tags [ address ]
244
- const clone = {
245
- ...old ,
246
- }
247
- // an assigned field
248
- // v1.0.0-alpha
249
- delete clone . actionHash
250
-
251
- try {
252
- const createdTag = await projectsZomeApi . tag . create ( projectsCellId , clone )
253
- dispatch (
254
- createTag ( projectsCellIdString , createdTag )
255
- )
256
- } catch ( e ) {
257
- console . log ( 'createTag error' , e )
258
- throw e
259
- }
260
- }
261
- }
262
-
263
332
// return the list of old addresses mapped to new addresses
264
333
return outcomeActionHashMap
265
334
}
0 commit comments