Skip to main content

View management for Amazon's Redshift

Project description

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

View management for Amazon’s Redshift

Features

Room with a view is a python script that automatically parses a collection of SQL files to find View and Function definitions and their dependencies. It then makes it easy to sync those views with Redshift, automatically dropping and recreating dependent views as necessary so that there are no errors. The key benefits are:

  • No writing code to send view SQL to Redshift: the script does it for you.

  • Edit any view and sync it without worrying about needing to drop or recreate views that depend on it.

  • Error handling tells you exactly where there are errors in your views.

  • The script runs in an atomic transaction, so you can’t accidentally enter a broken state by syncing some views and not others.

Setup

  • Copy settings.yaml.default to settings.yaml, and edit the file to configure your Redshift connection and the location of your .sql files. Example settings.yaml file:

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

directories:
  default: .
  • Install requirements with pip install -r requirements.txt

Usage

usage: room_with_a_view.py [-h] [--view-names [VIEW-NAME [VIEW-NAME ...]]]
                           [--file-names [FILE-PATH [FILE-PATH ...]]]
                           [--connection CONNECTION]
                           [--directories [DIRECTORY [DIRECTORY ...]]]
                           [--settings SETTINGS]
                           {sync-all,sync,drop,drop-all}

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

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

optional arguments:
  -h, --help            show this help message and exit
  --view-names [VIEW-NAME [VIEW-NAME ...]]
                        View names to manage.
  --file-names [FILE-PATH [FILE-PATH ...]]
                        Paths to .sql files to manage.
  --connection CONNECTION
                        Name of the Redshift connection to use (or "default",
                        if not specified). The name must match a connection in
                        settings.yaml
  --directories [DIRECTORY [DIRECTORY ...]]
                        Directory names to search for SQL files (or "default"
                        if not specified). Names must match directories in
                        settings.yaml
  --settings SETTINGS   Location of the settings file (settings.yaml by
                        default)

Examples

  • room_with_a_view.py sync-all: Syncs all views in all SQL files in the default directory specified in settings.yaml. Drops and recreates existing views, and makes sure views are created in dependency order.

  • room_with_a_view.py sync --view-names my_view1 my_view2 --file-names ../sql/my_file.sql: Syncs the specific views my_view1 and my_view2, as well as all views in the file ../sql/my_file.sql.

  • room_with_a_view.py drop-all --connection other_connection: Drops all views in the default directory, using the connection info specified in settings.yaml under the name other_connection to connect to Redshift.

  • room_with_a_view.py drop --view-names my_view1 --directories other_dir1 other_dir2 --settings /path/to/fancy_settings.yaml: Drops the view my_view1, looking for SQL files that contain the view and its dependents in the directories specified by other_dir1 and other_dir2 in the settings file located in /path/to/fancy_settings.yaml.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2018-05-28)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

room_with_a_view-0.1.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

room_with_a_view-0.1.1-py2.py3-none-any.whl (10.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file room_with_a_view-0.1.1.tar.gz.

File metadata

File hashes

Hashes for room_with_a_view-0.1.1.tar.gz
Algorithm Hash digest
SHA256 da90c688804df1a0bca28eedf6c4985f4805eee90bb9e5c516f273031efb5b8d
MD5 7e20bd0befc1c45c2fc82b40994b5736
BLAKE2b-256 654ccac7baf7c7c771d8869953a4ed7be15621f13f1ea972a534dfd4adda938c

See more details on using hashes here.

File details

Details for the file room_with_a_view-0.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for room_with_a_view-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d2a213fa6f868a9fe9b7f0bcc3c89badc0ee201684611ffa906c41a1204e287f
MD5 5c113d5637117d49a34448f0d15305a2
BLAKE2b-256 4999a91fa1122429b0bedf37794ddefc41b7f71327a831a38759d1e87977c168

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page