编写简洁的aws dms表映射。
ptolem的Python项目详细描述
ptolemy,一个aws-dms表映射生成器
编写简洁的aws dms表映射。
背景
amazon web服务提供了一个工具,用于将数据迁移到、从或在sql数据库之间迁移。这个工具名为Database Migration Service(dms)。运行dms时,用户可以提供一个表映射,该映射指定允许用户控制从源数据库向目标数据库发送的数据。可以找到表映射选项的完整列表here。
表映射是以json文档的形式编写的,它可能会变得冗长和复杂。ptolemy允许用户编写简洁的yamlsource文件,这些文件可以使用ptolemycli工具编译为有效的json表映射。
使用量
$# Display an example source file: $ cat migrate_all_tables_in_a_schema.yaml selection: include: - object-locators: schema-names: - Test table-names: - "%" $# Compile it to a DMS table mapping: $ ptolemy migrate_all_tables_in_a_schema.yaml { "rules": [ { "object-locator": { "schema-name": "Test", "table-name": "%" }, "rule-action": "include", "rule-id": "1", "rule-name": "1", "rule-type": "selection" } ] }
api
$ ptolemy -h ptolemy [-h] [-d] [-v] source positional arguments: source path to the source file optional arguments: -h, --help show this help message and exit -d, --debug enable debug logs -v, --version show program's version number and exit
安装
通过PIP安装(推荐):
$ pip install ptolemy
从源安装:
$ git clone git@github.com:cloudreach/ptolemy.git $cd ptolemy $ make install
许可证
ptolemy是根据apache软件许可证2.0授权的。
源语法
以下各节描述源语法。它旨在向具有dms-json映射文件工作知识的用户展示如何编写他们的yaml等价物。有关json映射文件的概述,请参见documentation。大多数项与json映射文件中的项相同,但object-locators除外,这在Object Locators
这些描述是用伪yaml编写的,其中语法( option_a|option_b )指示一个项可以接受值option_a或option_b。
有关工作示例,请参见examples directory。
选择规则和操作
selection:( include|exclude ):-object-locators:schema-names:-<schema-name-1>table-names:-<table-name-1>filters:-filter-type:sourcecolumn-name:<column-name-1>filter-conditions:-filter-operator:( ste|gte|eq|between )value:<value>
转换规则和操作
transformation:( rename|remove-column|convert-lowercase|convert-uppercase|add-prefix|remove-prefix|replace-prefix|add-suffix|remove-suffix|replace-suffix ):-object-locators:schema-names:-<schema-name-1>table-names:-<table-name-1>column-names:-<column-name-1>rule-target:( schema|table|column )value:<value>old-value:<old-value>
对象定位器
object-locators提供了一种将选择和转换规则应用于大量对象的强大方法。原生json表映射object-locator的单个参数schema-name、table-name和column-name已被它们的复数替换。这些新参数都接受一个对象列表。然后将规则应用于列出的每一列、列出的每一个表、列出的每一个架构。
多源文件编译
可以使用下面的bash片段一次编译多个源文件。代码段递归地查找目录src/下的所有yaml文件,将源代码编译为dms映射文件,并将其保存到名为mappings/目录下具有相同名称和路径的文件,扩展名为.json。
source_files="$(find src -type f -name '*.yaml')"for source_file in $source_files;dosource_file_without_extension=${source_file%.*}source_file_with_json_extension=${source_file_without_extension}.json destination_file=mappings${source_file_with_json_extension#src} mkdir -p "$(dirname $destination_file)" ptolemy $source_file > $destination_filedone
从以下目录运行代码:
.
└── src
├── db-a
│ ├── schema-1.yaml
│ └── schema-2.yaml
└── db-b
├── schema-1.yaml
└── schema-2.yaml
会导致:
.
├── mappings
│ ├── db-a
│ │ ├── schema-1.json
│ │ └── schema-2.json
│ └── db-b
│ ├── schema-1.json
│ └── schema-2.json
└── src
├── db-a
│ ├── schema-1.yaml
│ └── schema-2.yaml
└── db-b
├── schema-1.yaml
└── schema-2.yaml
历史记录
1.0.0(2016-11-18)
- 初次发布。