Created
November 13, 2018 14:49
-
-
Save sahapasci/4354db4391ba2c9c68cfbb79243155d2 to your computer and use it in GitHub Desktop.
AWS DMS Selection Rules JSON
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 query creates JSON input for AWS DMS (Data Migration Service) selection rules. | |
* It incluedes all schemas. | |
*/ | |
WITH rules AS ( | |
SELECT | |
format('{ | |
"rule-type": "selection", | |
"rule-id": "%s", | |
"rule-name": "%s", | |
"object-locator": {"schema-name": "%s", "table-name": "%%" }, | |
"rule-action": "include" | |
}' , row_number() over (), row_number() over (), n.nspname | |
)::jsonb AS rule | |
FROM pg_namespace n | |
WHERE | |
n.nspname !~ '^pg_' AND | |
n.nspname <> 'information_schema' | |
ORDER BY n.nspname | |
) | |
SELECT | |
json_build_object('rules', json_agg(rule)) | |
FROM rules |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output;