Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deprecate MyInfo fields for V3 (step 2 - database) #1072

Merged
merged 1 commit into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions scripts/20210202_deprecate-myinfo-v2/billadd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable */

// BEFORE
// Count total number of these fields
{
const ATTR_NAME = 'billadd'
const beforePipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(beforePipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'billadd'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}

// UPDATE
// Should be same as number of forms
{
const ATTR_NAME = 'billadd'
db.forms.updateMany(
{ form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME },
{ $unset: { 'form_fields.$[field].myInfo': 1 } },
{ arrayFilters: [{ 'field.myInfo.attr': ATTR_NAME }] }
)
}

// AFTER
// Ideally 0, unless someone has inserted a new field in between
{
const ATTR_NAME = 'billadd'
const afterPipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(afterPipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'billadd'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}
73 changes: 73 additions & 0 deletions scripts/20210202_deprecate-myinfo-v2/edulevel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable */

// BEFORE
// Count total number of these fields
{
const ATTR_NAME = 'edulevel'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(pipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'edulevel'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}

// UPDATE
// Should be same as number of forms
{
const ATTR_NAME = 'edulevel'
const FIELD_OPTIONS = [
'NO FORMAL QUALIFICATION / PRE-PRIMARY / LOWER PRIMARY',
'PRIMARY',
'LOWER SECONDARY',
'SECONDARY',
'POST-SECONDARY (NON-TERTIARY): GENERAL & VOCATION',
'POLYTECHNIC DIPLOMA',
'PROFESSIONAL QUALIFICATION AND OTHER DIPLOMA',
"BACHELOR'S OR EQUIVALENT",
"POSTGRADUATE DIPLOMA / CERTIFICATE (EXCLUDING MASTER'S AND DOCTORATE)",
"MASTER'S AND DOCTORATE OR EQUIVALENT",
'MODULAR CERTIFICATION (NON-AWARD COURSES / NON-FULL QUALIFICATIONS)'
]
db.forms.updateMany(
{ form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME },
{ $unset: { 'form_fields.$[field].myInfo': 1 }, $set: { 'form_fields.$[field].fieldOptions': FIELD_OPTIONS } },
{ arrayFilters: [{ 'field.myInfo.attr': ATTR_NAME }] }
)
}

// AFTER
// Ideally 0, unless someone has inserted a new field in between
{
const ATTR_NAME = 'edulevel'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(pipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'edulevel'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}
66 changes: 66 additions & 0 deletions scripts/20210202_deprecate-myinfo-v2/gradyear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-disable */

// BEFORE
// Count total number of these fields
{
const ATTR_NAME = 'gradyear'
const beforePipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(beforePipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'gradyear'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}

// UPDATE
// Should be same as number of forms
{
const ATTR_NAME = 'gradyear'
const VALIDATION_OPTIONS = {
customMax: 4,
customMin: 4,
customVal: 4,
selectedValidation: 'Exact'
}
db.forms.updateMany(
{ form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME },
{ $unset: { 'form_fields.$[field].myInfo': 1 }, $set: { 'form_fields.$[field].ValidationOptions': VALIDATION_OPTIONS } },
{ arrayFilters: [{ 'field.myInfo.attr': ATTR_NAME }] }
)
}

// AFTER
// Ideally 0, unless someone has inserted a new field in between
{
const ATTR_NAME = 'gradyear'
const afterPipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(afterPipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'gradyear'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}
60 changes: 60 additions & 0 deletions scripts/20210202_deprecate-myinfo-v2/homeno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable */

// BEFORE
// Count total number of these fields
{
const ATTR_NAME = 'homeno'
const beforePipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(beforePipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'homeno'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}

// UPDATE
// Should be same as number of forms
{
const ATTR_NAME = 'homeno'
db.forms.updateMany(
{ form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME },
{ $unset: { 'form_fields.$[field].myInfo': 1 } },
{ arrayFilters: [{ 'field.myInfo.attr': ATTR_NAME }] }
)
}

// AFTER
// Ideally 0, unless someone has inserted a new field in between
{
const ATTR_NAME = 'homeno'
const afterPipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(afterPipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'homeno'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}
60 changes: 60 additions & 0 deletions scripts/20210202_deprecate-myinfo-v2/mailadd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable */

// BEFORE
// Count total number of these fields
{
const ATTR_NAME = 'mailadd'
const beforePipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(beforePipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'mailadd'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}

// UPDATE
// Should be same as number of forms
{
const ATTR_NAME = 'mailadd'
db.forms.updateMany(
{ form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME },
{ $unset: { 'form_fields.$[field].myInfo': 1 } },
{ arrayFilters: [{ 'field.myInfo.attr': ATTR_NAME }] }
)
}

// AFTER
// Ideally 0, unless someone has inserted a new field in between
{
const ATTR_NAME = 'mailadd'
const afterPipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $project: { form_fields: 1 } },
{ $unwind: '$form_fields' },
{ $match: { 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numFields' }
]
db.forms.aggregate(afterPipeline)
}

// Count number of forms with this field
{
const ATTR_NAME = 'mailadd'
const pipeline = [
{ $match: { form_fields: { $exists: true, $not: { $size: 0 } }, 'form_fields.myInfo.attr': ATTR_NAME } },
{ $count: 'numForms' }
]
db.forms.aggregate(pipeline)
}
Loading