简单的cassandra数据库迁移程序。

cassandra-migrate的Python项目详细描述


简单的cassandra模式迁移工具。

安装

运行pip install cassandra-migrate,或python ./setup.py install

推理

与其他可用工具不同,此工具:

  • 用python编写,便于安装
  • 不需要cqlsh,只需要python驱动程序
  • 支持现有数据库对给定版本
  • 的基线化
  • 支持部分推进
  • 支持使用轻量级事务锁定并发实例
  • 根据配置的迁移验证存储的迁移
  • 存储每次迁移的内容、校验和、日期和状态
  • 支持在不同环境中使用不同的键空间配置进行部署
  • 支持cql和python脚本迁移

配置

数据库是通过yaml文件配置的。例如:

keyspace:herbieprofiles:prod:replication:class:SimpleStrategyreplication_factor:3migrations_path:./migrations

其中migrations文件夹(相对于配置文件)。包含 .cql.py文件。文件按词汇顺序加载。

默认的约定是以以下格式命名它们:v001_my_migration.{cql | py}。 可以使用new_migration_name选项指定自定义命名方案。

注意:不推荐使用新的迁移文本。应该改为使用特定的文件类型选项。

例如

# Date-based migration namesnew_migration_name:"v{date:YYYYMMDDHHmmss}_{desc}"# Default migration namesnew_migration_name:"v{next_version:03d}_{desc}"# Custom initial migration contentnew_migration_text:|/* Cassandra migration for keyspace {keyspace}.Version {next_version} - {date}{full_desc} */# Custom initial migration content for cql scriptsnew_cql_migration_text:|/* Cassandra migration for keyspace {keyspace}.Version {next_version} - {date}{full_desc} */# Custom initial migration content for python scriptsnew_python_migration_text:|# Cassandra migration for keyspace {keyspace}.# Version {next_version} - {date}# {full_desc} */def execute(session, **kwargs):"""Main method for your migration. Do not rename this method.Raise an exception of any kind to abort the migration."""print("Cassandra session: ", session)

new_migration_name是一个新样式的python格式字符串,它可以使用 以下参数:

  • next_version:新生成的迁移数(作为int)。
  • desc:指定的文件名迁移的干净描述 由用户提供。
  • full_desc:未修改的描述,可能包含特殊字符。
  • date:当前日期(UTC)。注意格式的选择, 否则,您可能会在文件名中包含空格。上面的例子应该 做一个好的起点。
  • keyspace:配置的键空间的名称。

格式字符串应该not包含.cql或.py扩展名,因为它们 自动添加。

new_migraton_text与上面的规则大纲相同,但定义了 迁移文件的初始内容,如果下面的类型特定选项 没有设置。

new_cql_migraton_text定义cql迁移文件的初始内容。

new_python_migraton_text定义python迁移的初始内容 文件夹。

配置文件

配置文件中可以定义配置文件。他们可以配置 的replicationdurable_writes参数 CREATE KEYSPACE。默认的dev配置文件是隐式定义的 使用1的复制因子。

用法

常用参数:

-H HOSTS, --hosts HOSTS
                      Comma-separated list of contact points
-p PORT, --port PORT  Connection port
-u USER, --user USER  Connection username
-P PASSWORD, --password PASSWORD
                      Connection password
-c CONFIG_FILE, --config-file CONFIG_FILE
                      Path to configuration file
-m PROFILE, --profile PROFILE
                      Name of keyspace profile to use
-s SSL_CERT, --ssl-cert SSL_CERT
                      File path of .pem or .crt containing certificate of
                      the cassandra host you are connecting to (or the
                      certificate of the CA that signed the host
                      certificate). If this option is provided, cassandra-
                      migrate will use ssl to connect to the cluster. If
                      this option is not provided, the -k and -t options
                      will be ignored.
-k SSL_CLIENT_PRIVATE_KEY, --ssl-client-private-key SSL_CLIENT_PRIVATE_KEY
                      File path of the .key file containing the private key
                      of the host on which the cassandra-migrate command is
                      run. This option must be used in conjuction with the
                      -t option. This option is ignored unless the -s option
                      is provided.
-t SSL_CLIENT_CERT, --ssl-client-cert SSL_CLIENT_CERT
                      File path of the .crt file containing the public
                      certificate of the host on which the cassandra-migrate
                      command is run. This certificate (or the CA that
                      signed it) must be trusted by the cassandra host that
                      migrations are run against. This option must be used
                      in conjuction with the -k option. This option is
                      ignored unless the -s option is provided.
-y, --assume-yes      Automatically answer "yes" for all questions

迁移

将数据库提升到迁移的最新(或选定)版本。 必要时创建keyspace和migrations表。

如果先前的尝试失败,迁移将拒绝运行。重写 在清理完所有剩菜后(因为卡桑德拉没有DDL 事务),使用--force选项。

示例:

# Migrate to the latest database version using the default configuration file,
# connecting to Cassandra in the local machine.
cassandra-migrate -H 127.0.0.1 migrate

# Migrate to version 2 using a specific config file.
cassandra-migrate -c mydb.yml migrate 2# Migrate to a version by name.
cassandra-migrate migrate v005_my_changes.cql

# Force migration after a failure
cassandra-migrate migrate 2 --force

重置

通过删除现有的密钥空间来重置数据库,然后运行 迁移。

示例:

# Reset the database to the latest version
cassandra-migrate reset

# Reset the database to a specifis version
cassandra-migrate reset 3

基线

在不实际运行的情况下推进现有数据库版本 迁徙。

<>有用的是在不重新创建的情况下开始管理预先存在的数据库 从零开始。

示例:

# Baseline the existing database to the latest version
cassandra-migrate baseline

# Baseline the existing database to a specific version
cassandra-migrate baseline 5

状态

打印数据库的当前状态。

示例:

cassandra-migrate status

生成

生成具有适当名称和基本头的新迁移文件 模板,在配置的migrations_path中。

以交互方式运行命令时,默认情况下将打开文件 编辑。新生成的文件名将打印到stdout。

要生成python脚本,请指定--python选项。

有关MIG的详细信息,请参阅配置部分命名配给。

示例:

{pr 8}

{id11}$

许可证(MIT)

{pr 9}

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java有没有工具可以将zephyr转换为velocity模板?   java在安卓 studio中从JSON响应中获取值   jvm如何在Java中设计一个好的permgen空间字符串?   java如何防止Rest webservice使用被盗令牌进行身份验证   java无法遍历列表JSTL   找不到用于ResourceServerTokenServices的java Bean SpringSecurityOauth2   java子字符串替换问题   爪哇玻璃鱼3。十、 以编程方式处理任意HTTPSession的终止   java如何检查输入是否为整数,并在最后添加一个命令来重新启动while循环?   引发java ical4j 1.0.6不可解析日期异常   Java等价于Delphi的DBCtrlGrid?   如果发生错误,java将查找下一个预期标记ANTLR 3   java自打开应用程序(创建锁屏)   java为什么netty有自己的ConcurrentHashMap?   Gradle任务中的java拉取和运行依赖项   继承与Java继承的混淆   java使用shell脚本中的版本执行jar   java我无法让Sqlite数据库与带有Maven的JavaFX应用程序IDE Eclipse包正确通信   java控制台日志未通过org打印。阿帕奇。hadoop。mapreduce。作业的waitForCompletion(true)方法   JAVAlang.NoSuchMethodError:apachestorm螺栓中的spring getrequest