-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add db migration scripts (#1072)
- Loading branch information
1 parent
5d6ae59
commit 43e0915
Showing
6 changed files
with
764 additions
and
0 deletions.
There are no files selected for viewing
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,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) | ||
} |
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,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) | ||
} |
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,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) | ||
} |
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,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) | ||
} |
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,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) | ||
} |
Oops, something went wrong.