跳转到主要内容

亚马逊Redshift的视图管理

项目描述

Room with a View

https://img.shields.io/pypi/v/room_with_a_view.svg https://img.shields.io/travis/b12io/room_with_a_view.svg Documentation Status Updates

亚马逊Redshift的视图管理

特性

Room with a view是一个Python脚本,它自动解析SQL文件集合,以查找视图和函数定义及其依赖关系。然后,它使同步这些视图与Redshift变得容易,根据需要自动删除和重新创建依赖视图,以确保没有错误。主要优点包括

  • 无需编写代码将视图SQL发送到Redshift:脚本会为您完成。

  • 编辑任何视图并同步它,无需担心需要删除或重新创建依赖视图。

  • 错误处理会精确地告诉您视图中存在错误的位置。

  • 该脚本以原子事务运行,因此您不会因为只同步某些视图而无法同步其他视图而意外进入损坏状态。

设置

  • 安装软件包:pip install room_with_a_view

  • 创建 settings.yaml 文件,并编辑该文件以配置您的 Redshift 连接和 .sql 文件的位置。示例 settings.yaml 文件

connections:
  default:
    host: localhost
    port: 5432
    user: awsuser
    password: **CHANGEME**
    dbname: postgres

directories:
  - .
  • 您已准备就绪!尝试 room_with_a_view sync-all 以同步所有视图,或 room_with_a_view --help 了解更多关于命令的信息。

用法

usage: room_with_a_view.py [-h]
                           [--view-names [VIEW-OR-FUNCTION-NAME [VIEW-OR-FUNCTION-NAME ...]]]
                           [--file-names [FILE-PATH [FILE-PATH ...]]]
                           [--connection CONNECTION]
                           [--settings SETTINGS] [--verbosity VERBOSITY]
                           {sync,drop-all,sync-all,list,drop}

Manages Redshift SQL views. Possible actions:
    sync: Syncs specific views or functions (identified by the --view-names or --file-names parameters).
    drop-all: Drops all views and functions in all .sql files in a set of directories (identified by the --directories parameter). The directory will be searched recursively.
    sync-all: Syncs all views and functions in all .sql files in a set of directories (identified by the --directories parameter). The directory will be searched recursively.
    list: lists all known views and functions.
    drop: Drops specific views or functions (identified by the --view-names or --file-names parameters).

positional arguments:
  {sync,drop-all,sync-all,list,drop}
                        The action to perform.

optional arguments:
  -h, --help            show this help message and exit
  --view-names [VIEW-OR-FUNCTION-NAME [VIEW-OR-FUNCTION-NAME ...]]
                        Names of views or functions to which to apply the action.
  --file-names [FILE-PATH [FILE-PATH ...]]
                        Paths to .sql files to which to apply the action.
  --connection CONNECTION
                        Name of the Redshift connection to use (or "default",
                        if not specified). The name must match a connection in
                        settings.yaml
  --settings SETTINGS   Location of the settings file (settings.yaml by
                        default)
  --verbosity VERBOSITY
                        Verbosity of script output. 0 will output nothing, 1
                        will output names of views and functions being dropped
                        and created, and 2 will output all executed sql

示例

  • room_with_a_view.py sync-all:同步默认目录中 settings.yaml 指定的所有 SQL 文件中的所有视图和函数。删除并重新创建现有视图,并确保视图按依赖顺序创建。

  • room_with_a_view.py sync --view-names my_view1 my_func1 --file-names ../sql/my_file.sql:同步特定的视图 my_view1 和函数 my_func1,以及文件 ../sql/my_file.sql 中的所有视图和函数。

  • room_with_a_view.py drop-all --connection other_connection:使用在 settings.yaml 中指定名为 other_connection 的连接信息,删除默认目录中的所有视图和函数,连接到 Redshift。

  • room_with_a_view.py drop --view-names my_view1 --directories other_dir1 other_dir2 --settings /path/to/fancy_settings.yaml:删除视图 my_view1,在 /path/to/fancy_settings.yaml 中指定的设置文件中查找包含视图及其依赖项的 SQL 文件,在 other_dir1other_dir2 目录中。

致谢

该软件包是用 Cookiecutteraudreyr/cookiecutter-pypackage 项目模板创建的。

历史

0.1.0 (2018-05-28)

  • 在 PyPI 上的首次发布。

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于 安装软件包 的信息。

源分布

room_with_a_view-0.1.5.tar.gz (16.6 kB 查看哈希值)

支持者:

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面