Created
August 24, 2017 09:06
-
-
Save josnidhin/6867be7de0c38f0a1b86559192e3a3dd to your computer and use it in GitHub Desktop.
A Simple NodeJS script to generate MySQL to Redshift AWS DMS table mappings
This file contains hidden or 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
/** | |
* @author Jose Nidhin | |
*/ | |
'use strict'; | |
/** | |
* Using Table Mapping with an Task to Select and Filter Data | |
* https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.CustomizingTasks.TableMapping.html#CHAP_Tasks.CustomizingTasks.TableMapping.SelectionTransformation | |
*/ | |
let tables = [ | |
{name: 'table1'}, | |
{name: 'table2', filters: [ | |
{ | |
"filter-type": "source", | |
"column-name": "create_at", | |
"filter-conditions": [{ | |
"filter-operator": "gte", | |
"value": "2000-01-01 00:00:00" | |
}] | |
}, | |
{ | |
"filter-type": "source", | |
"column-name": "updated_at", | |
"filter-conditions": [{ | |
"filter-operator": "gte", | |
"value": "2000-01-01 00:00:00" | |
}] | |
} | |
]}, | |
{name: 'table3', filters: [ | |
{ | |
"filter-type": "source", | |
"column-name": "create_at", | |
"filter-conditions": [{ | |
"filter-operator": "gte", | |
"value": "2000-01-01 00:00:00" | |
}] | |
} | |
]} | |
]; | |
let taskRule = []; | |
for (let i = 0; i < tables.length; i++) { | |
let rule = { | |
'rule-type': 'selection', | |
'rule-id': (i + 1).toString(), | |
'rule-name': (i + 1).toString(), | |
'object-locator': { | |
'schema-name': 'database1', | |
'table-name': tables[i].name | |
}, | |
'rule-action': 'include' | |
}; | |
if (tables[i].filters) { | |
rule.filters = tables[i].filters; | |
} | |
taskRule.push(rule); | |
} | |
console.log(JSON.stringify({rules: taskRule})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment