-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Persona Imports): Allow homepage constants (#1408)
* csv import account ifi can now have it's id set as a constant. * Fixed changing the constant clearing the record. * Fixed deleting useConstant value. * Disabbled account key. * Update personasImportHelpers.js * Fixed tests. * Update personasImportHelpers.js * Update HeaderItem.spec.js.snap * Fixed account home page getting incorrectly set. * Will unset Account key. * Added migration. * Added down. * Remove unused import
- Loading branch information
1 parent
244a15d
commit 4a0f743
Showing
9 changed files
with
267 additions
and
53 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
cli/src/commands/v2-migrations/20190711090000_persona_imports.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { map as bmap } from 'bluebird'; | ||
import { filter, get, forEach, set, toPairs, unset, cloneDeep } from 'lodash'; | ||
import PersonasImports from 'lib/models/personasImport'; | ||
import highland from 'highland'; | ||
|
||
const BATCH_SIZE = 10000; | ||
|
||
const up = async () => { | ||
const personasImportsSream = highland(PersonasImports.find({}).cursor()); | ||
|
||
const migrationStream = personasImportsSream.batch(BATCH_SIZE).flatMap((personasImports) => { | ||
const donePromise = bmap(personasImports, async (personasImport) => { | ||
const toMove = filter(toPairs(personasImport.structure), (structurePair) => { | ||
const structure = structurePair[1]; | ||
return get(structure, 'columnType') === 'COLUMN_ACCOUNT_KEY'; | ||
}); | ||
if (toMove.length === 0) { | ||
// Nothing to do | ||
return; | ||
} | ||
|
||
const newStructure = cloneDeep(personasImport.structure); | ||
|
||
forEach(toMove, (toMov) => { | ||
const key = toMov[0]; | ||
const value = toMov[1]; | ||
set(newStructure, [get(value, 'relatedColumn'), 'primary'], get(value, 'primary')); | ||
unset(newStructure, [key, 'primary']); | ||
}); | ||
|
||
personasImport.structure = newStructure; | ||
await personasImport.save(); | ||
}, { concurrency: 1 }); | ||
|
||
return highland(donePromise); | ||
}); | ||
|
||
await new Promise((resolve, reject) => { | ||
migrationStream.on('error', reject); | ||
migrationStream.apply(resolve); | ||
}); | ||
}; | ||
|
||
const down = async () => { | ||
const personasImportsSream = highland(PersonasImports.find({}).cursor()); | ||
|
||
const migrationStream = personasImportsSream.batch(BATCH_SIZE).flatMap((personasImports) => { | ||
const donePromise = bmap(personasImports, async (personasImport) => { | ||
const toMove = filter(toPairs(personasImport.structure), (structurePair) => { | ||
const structure = structurePair[1]; | ||
return get(structure, 'columnType') === 'COLUMN_ACCOUNT_VALUE'; | ||
}); | ||
if (toMove.length === 0) { | ||
// Nothing to do | ||
return; | ||
} | ||
|
||
const newStructure = cloneDeep(personasImport.structure); | ||
|
||
forEach(toMove, (toMov) => { | ||
const key = toMov[0]; | ||
const value = toMov[1]; | ||
set(newStructure, [get(value, 'relatedColumn'), 'primary'], get(value, 'primary')); | ||
unset(newStructure, [key, 'primary']); | ||
}); | ||
|
||
personasImport.structure = newStructure; | ||
await personasImport.save(); | ||
}, { concurrency: 1 }); | ||
|
||
return highland(donePromise); | ||
}); | ||
|
||
await new Promise((resolve, reject) => { | ||
migrationStream.on('error', reject); | ||
migrationStream.apply(resolve); | ||
}); | ||
}; | ||
|
||
export default { up, down }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,20 +228,27 @@ describe('personas import helper', () => { | |
}, | ||
test3: { | ||
columnType: COLUMN_ACCOUNT_KEY, | ||
primary: 1, | ||
relatedColumn: 'test4' | ||
}, | ||
test4: { | ||
columnType: COLUMN_ACCOUNT_VALUE, | ||
primary: 1, | ||
relatedColumn: 'test3' | ||
}, | ||
test5: { | ||
columnType: COLUMN_ACCOUNT_VALUE, | ||
primary: 3, | ||
useConstant: true, | ||
constant: 'http://hi' | ||
} | ||
}; | ||
|
||
const row = { | ||
test1: 'dave', | ||
test2: '[email protected]', | ||
test3: 'http://dave.com', | ||
test4: 'dave dot com' | ||
test4: 'dave dot com', | ||
test5: 'dave' | ||
}; | ||
|
||
const result = getIfis({ | ||
|
@@ -256,7 +263,11 @@ describe('personas import helper', () => { | |
expect(result[1].key).to.equal('mbox_sha1sum'); | ||
expect(result[1].value).to.equal('[email protected]'); | ||
|
||
expect(result.length).to.equal(2); | ||
expect(result[2].key).to.equal('account'); | ||
expect(result[2].value.name).to.equal('dave'); | ||
expect(result[2].value.homePage).to.equal('http://hi'); | ||
|
||
expect(result.length).to.equal(3); | ||
}); | ||
|
||
it('should add mailto to mbox', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.