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

  • Install the package: pip install room_with_a_view.

  • Create 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: .
  • You’re ready to go! Try room_with_a_view sync-all to sync all your views, or room_with_a_view --help to learn more about the command.

Usage

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]
                           [--directories [DIRECTORY [DIRECTORY ...]]]
                           [--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 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)
  --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

Examples

  • room_with_a_view.py sync-all: Syncs all views and functions 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_func1 --file-names ../sql/my_file.sql: Syncs the specific view my_view1 and function my_func1, as well as all views and functions in the file ../sql/my_file.sql.

  • room_with_a_view.py drop-all --connection other_connection: Drops all views and functions 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.3.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

room_with_a_view-0.1.3-py2.py3-none-any.whl (11.8 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for room_with_a_view-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5e5cbccbc58edf78f065a411ec7f84765ff078e01c16aa2b847a5c8dd8267f0e
MD5 aad85f3f2ac1528614cf179d2226c636
BLAKE2b-256 08888bf4e837bbf887274e261c54b80b2164ce4453b6c4714fb4579ae1a5475c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for room_with_a_view-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 63cb68333c056e35a885a4b7067f2c9ceff1ae18d39e1e2995ca890c4e24a3e4
MD5 45c75848385b02ee93478a8f601f1d79
BLAKE2b-256 9d4fc06d12a34f2a6a04bc19f2e2b5f9417d462aa762ae3476b77528b9a0e7d2

See more details on using hashes here.

Provenance

Supported by

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