Skip to content

Commit c5db8b8

Browse files
committed
fix importing
1 parent 5a11de0 commit c5db8b8

File tree

6 files changed

+147
-77
lines changed

6 files changed

+147
-77
lines changed

happ/workdir/dna/profiles/dna.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ manifest_version: "1"
33
name: profiles-dna
44
integrity:
55
origin_time: 1654092432130000
6-
uid: "0001"
6+
uid: "0002"
77
properties: ~
88
zomes:
99
- name: profiles_integrity

happ/workdir/profiles.dna

0 Bytes
Binary file not shown.

happ/workdir/profiles.happ

-221 Bytes
Binary file not shown.

happ/workdir/projects.dna

-116 Bytes
Binary file not shown.

web/src/import/index.ts

Lines changed: 145 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ProfilesZomeApi from '../api/profilesApi'
1010
import { getAppWs } from '../hcWebsockets'
1111
import { cellIdFromString } from '../utils'
1212
import { createTag } from '../redux/persistent/projects/tags/actions'
13-
import { Outcome } from '../types'
13+
import { Outcome, Tag } from '../types'
1414
import { WireRecord } from '../api/hdkCrud'
1515
import { ActionHashB64 } from '../types/shared'
1616

@@ -45,43 +45,89 @@ export default async function importAllProjectData(
4545
...old,
4646
isImported: true,
4747
}
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
5151
)
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
5293
}
5394

5495
// 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
57100
// is sub-data to the outcomes
58101
for (let outcomeActionHash of Object.keys(projectData.outcomes)) {
59102
const oldOutcome = projectData.outcomes[outcomeActionHash]
60103
const clone = {
61104
...oldOutcome,
105+
// make sure tag references hold up through the migration
106+
tags: oldOutcome.tags.map(
107+
(oldTagHash: ActionHashB64) => tagActionHashMap[oldTagHash]
108+
),
62109
isImported: true,
63110
}
64-
// v0.5.4-alpha
111+
// as of v1.0.4-alpha
65112
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
68115

69116
let newOutcome: WireRecord<Outcome>
70117
try {
71118
newOutcome = await projectsZomeApi.outcome.create(projectsCellId, clone)
72-
dispatch(
73-
createOutcome(projectsCellIdString, newOutcome)
74-
)
119+
dispatch(createOutcome(projectsCellIdString, newOutcome))
75120
} catch (e) {
76121
console.log('createOutcome error', e)
77122
throw e
78123
}
79124
// add this new outcome address to the outcomeActionHashMap
80125
// to keep of which new addresses map to which old addresses
81126
let oldOutcomeActionHash: ActionHashB64
82-
// v0.5.4-alpha
127+
// as of v1.0.4-alpha
83128
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
85131
else if (oldOutcome.address) oldOutcomeActionHash = oldOutcome.address
86132

87133
outcomeActionHashMap[oldOutcomeActionHash] = newOutcome.actionHash
@@ -90,30 +136,43 @@ export default async function importAllProjectData(
90136
// CONNECTIONS
91137
for (let address of Object.keys(projectData.connections)) {
92138
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]
94149
const clone = {
95150
...old,
96-
parentActionHash: outcomeActionHashMap[old.parentActionHash],
97-
childActionHash: outcomeActionHashMap[old.childActionHash],
151+
parentActionHash: newParentOutcomeActionHash,
152+
childActionHash: newChildOutcomeActionHash,
98153
// randomizer used to be a float, but is now an int
99154
randomizer: Number(old.randomizer.toFixed()),
100155
isImported: true,
101156
}
157+
// pre v1.0.4-alpha
158+
delete clone.parentHeaderHash
159+
delete clone.childHeaderHash
102160
// an assigned field
103-
// v0.5.4-alpha
161+
// as of v1.0.4-alpha
104162
delete clone.actionHash
105-
// pre v0.5.3-alpha and prior
106-
delete clone.address
163+
// v0.5.4-alpha
164+
delete clone.headerHash
107165

108166
if (!clone.childActionHash || !clone.parentActionHash) {
109167
console.log('weird, invalid connection:', clone)
110168
continue
111169
}
112170
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
116174
)
175+
dispatch(createConnection(projectsCellIdString, createdConnection))
117176
} catch (e) {
118177
console.log('createConnection error', e)
119178
throw e
@@ -123,26 +182,34 @@ export default async function importAllProjectData(
123182
// OUTCOME MEMBERS
124183
for (let address of Object.keys(projectData.outcomeMembers)) {
125184
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]
126190
const clone = {
127191
...old,
128-
outcomeActionHash: outcomeActionHashMap[old.outcomeActionHash],
192+
outcomeActionHash: newOutcomeActionHash,
129193
isImported: true,
130194
}
195+
// pre v1.0.4-alpha
196+
delete clone.outcomeHeaderHash
131197
// an assigned field
132-
// v0.5.4-alpha
198+
// v1.0.4-alpha
133199
delete clone.actionHash
134-
// pre v0.5.3-alpha and prior
135-
delete clone.address
200+
// v0.5.4-alpha
201+
delete clone.headerHash
136202

137203
if (!clone.outcomeActionHash) {
138204
console.log('weird, invalid outcomeMember:', clone)
139205
continue
140206
}
141207
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
145211
)
212+
dispatch(createOutcomeMember(projectsCellIdString, createdOutcomeMember))
146213
} catch (e) {
147214
console.log('createOutcomeMember error', e)
148215
throw e
@@ -152,23 +219,33 @@ export default async function importAllProjectData(
152219
// OUTCOME COMMENTS
153220
for (let address of Object.keys(projectData.outcomeComments)) {
154221
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]
155227
const clone = {
156228
...old,
157-
outcomeActionHash: outcomeActionHashMap[old.outcomeActionHash],
229+
outcomeActionHash: newOutcomeActionHash,
158230
isImported: true,
159231
}
232+
// pre v1.0.4-alpha
233+
delete clone.outcomeHeaderHash
160234
// an assigned field
161-
// v0.5.4-alpha
235+
// v1.0.4-alpha
162236
delete clone.actionHash
163-
// pre v0.5.3-alpha and prior
164-
delete clone.address
237+
// v0.5.4-alpha
238+
delete clone.headerHash
165239

166-
if (!clone.outcomeActionHash) {
240+
if (!clone.outcomeActionHash && !clone.outcomeHeaderHash) {
167241
console.log('weird, invalid outcomeComment:', clone)
168242
continue
169243
}
170244
try {
171-
const createdOutcomeComment = await projectsZomeApi.outcomeComment.create(projectsCellId, clone)
245+
const createdOutcomeComment = await projectsZomeApi.outcomeComment.create(
246+
projectsCellId,
247+
clone
248+
)
172249
dispatch(
173250
createOutcomeComment(projectsCellIdString, createdOutcomeComment)
174251
)
@@ -181,26 +258,34 @@ export default async function importAllProjectData(
181258
// OUTCOME VOTES
182259
for (let address of Object.keys(projectData.outcomeVotes)) {
183260
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]
184266
const clone = {
185267
...old,
186-
outcomeActionHash: outcomeActionHashMap[old.outcomeActionHash],
268+
outcomeActionHash: newOutcomeActionHash,
187269
isImported: true,
188270
}
271+
// pre v1.0.4-alpha
272+
delete clone.outcomeHeaderHash
189273
// an assigned field
190-
// v0.5.4-alpha
274+
// v1.0.4-alpha
191275
delete clone.actionHash
192-
// pre v0.5.3-alpha and prior
193-
delete clone.address
276+
// v0.5.4-alpha
277+
delete clone.headerHash
194278

195-
if (!clone.outcomeActionHash) {
279+
if (!clone.outcomeActionHash && !clone.outcomeHeaderHash) {
196280
console.log('weird, invalid outcomeVote:', clone)
197281
continue
198282
}
199283
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
203287
)
288+
dispatch(createOutcomeVote(projectsCellIdString, createdOutcomeVote))
204289
} catch (e) {
205290
console.log('createOutcomeVote error', e)
206291
throw e
@@ -210,56 +295,40 @@ export default async function importAllProjectData(
210295
// ENTRY POINTS
211296
for (let address of Object.keys(projectData.entryPoints)) {
212297
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]
213303
const clone = {
214304
...old,
215-
outcomeActionHash: outcomeActionHashMap[old.outcomeActionHash],
305+
outcomeActionHash: newOutcomeActionHash,
216306
isImported: true,
217307
}
308+
// pre v1.0.4-alpha
309+
delete clone.outcomeHeaderHash
218310
// an assigned field
219-
// v0.5.4-alpha
311+
// v1.0.4-alpha
220312
delete clone.actionHash
221-
// pre v0.5.3-alpha and prior
222-
delete clone.address
313+
// v0.5.4-alpha
314+
delete clone.headerHash
223315

224-
if (!clone.outcomeActionHash) {
316+
if (!clone.outcomeActionHash && !clone.outcomeHeaderHash) {
225317
console.log('weird, invalid entryPoint:', clone)
226318
continue
227319
}
228320
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
232324
)
325+
dispatch(createEntryPoint(projectsCellIdString, createdEntryPoint))
233326
} catch (e) {
234327
console.log('createEntryPoint error', e)
235328
throw e
236329
}
237330
}
238331

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-
263332
// return the list of old addresses mapped to new addresses
264333
return outcomeActionHashMap
265334
}

web/src/redux/persistent/projects/realtime-info-signal/middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const isProjectExitAction = (action) => {
3939
const realtimeInfoWatcher = (store) => {
4040
// return the action handler middleware
4141
return (next) => async (action) => {
42+
// console.log(store.getState())
4243
if (isOneOfRealtimeInfoAffectingActions(action)) {
4344
const appWebsocket = await getAppWs()
4445
const projectsZomeApi = new ProjectsZomeApi(appWebsocket)

0 commit comments

Comments
 (0)