Skip to content

Instantly share code, notes, and snippets.

@sahapasci
Created November 13, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sahapasci/4354db4391ba2c9c68cfbb79243155d2 to your computer and use it in GitHub Desktop.
Save sahapasci/4354db4391ba2c9c68cfbb79243155d2 to your computer and use it in GitHub Desktop.
AWS DMS Selection Rules JSON
/*
* 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
@sahapasci
Copy link
Author

Sample output;

{
  "rules": [
    {
      "rule-id": "1",
      "rule-name": "1",
      "rule-type": "selection",
      "rule-action": "include",
      "object-locator": {
        "table-name": "%",
        "schema-name": "public"
      }
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment