Skip to main content

ballerina

SQL migrations for AWS Athena

Installation

pip install athena-ballerina

Usage

Where migrations_directory is some directory of form:

./migrations
  1_up.sql
  1_down.sql
  2_up.sql
  2_down.sql
  3_up.sql
  3_down.sql

Where migration files can be python-formatted strings. In this example s3_uri will be replaced with s3://some-bucket/path/to/db if the parameter is specified with the flag -p s3_uri s3://some-bucket/path/to/db:

CREATE EXTERNAL TABLE partitioned_table (
    col_a STRING,
    col_b TIMESTAMP,
    col_c DATE
)
PARTITIONED BY (part_key STRING)
STORED AS PARQUET
LOCATION "{s3_uri}/partitioned_table"
tblproperties ("parquet.compress"="SNAPPY");

CLI

usage: ballerina.py [-h] [-m MIGRATION_URI] [-s STAGING_URI] [-w WORK_GROUP]
                    [-d DBNAME] [-D DELIM] [-p PARAM PARAM]
                    [--aws_access_key_id AWS_ACCESS_KEY_ID]
                    [--aws_secret_access_key AWS_SECRET_ACCESS_KEY]
                    [--aws_session_token AWS_SESSION_TOKEN]
                    [--aws_region_name AWS_REGION_NAME]
                    [--aws_profile_name AWS_PROFILE_NAME] [-a AUTO_APPLY_DOWN]
                    [-c AUTO_CLEAN_UP] [-v]
                    migrations_directory

positional arguments:
  migrations_directory  Path to directory containing migrations

optional arguments:
  -h, --help            show this help message and exit
  -m MIGRATION_URI, --migration_uri MIGRATION_URI
                        S3 Migration Dir. (i.e: "s3://my-
                        bucket/path/to/folder/")
  -s STAGING_URI, --staging_uri STAGING_URI
                        Athena Staging dir URI (i.e: "s3://my-
                        bucket/path/to/folder/")
  -w WORK_GROUP, --work_group WORK_GROUP
                        Athena Work Group
  -d DBNAME, --dbname DBNAME
  -D DELIM, --delim DELIM
                        Delimiter used in S3 bucket.
  -p PARAM PARAM, --param PARAM PARAM
                        Parameter that can be formatted into the migration
                        file. For example if "-p KEY VAL" gets passed in CLI,
                        and in the migration file there is a python-formatted
                        string like "LOCATION s3://{KEY}/", it will be
                        formatted to "LOCATION s3://VAL/"
  --aws_access_key_id AWS_ACCESS_KEY_ID
                        AWS Access Key for Boto3
  --aws_secret_access_key AWS_SECRET_ACCESS_KEY
                        AWS Access Secret for Boto3
  --aws_session_token AWS_SESSION_TOKEN
                        AWS Access Session Token for Boto3
  --aws_region_name AWS_REGION_NAME
                        AWS Region Name for Boto3
  --aws_profile_name AWS_PROFILE_NAME
                        AWS Profile Name for Boto3
  -a AUTO_APPLY_DOWN, --auto_apply_down AUTO_APPLY_DOWN
                        Accepts True/False, default is True
  -c AUTO_CLEAN_UP, --auto_clean_up AUTO_CLEAN_UP
                        Should Athena Queries be clean-up from S3
                        OutputLocation? Accepts True/False.
  -v, --version         show program's version number and exit

Ballerina is all-or-nothing.

E.g. you are on master branch on revision 5 and want to switch to a feature branch whose latest revision is 4'.

1 <- 2 <- 3 <- 4 <- 5  
       \
         3' <- 4' 

Applying migrations through Ballerina will leave you on either revision 5 (if an error is encountered) or revision 4' (if migration is successful) but not on any of 4, 3, 2, or 3'.

Testing on local machine

  • Check docs/testing.md

License

Copyright 2020 LeanTaas, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Metadata

Release files for athena-ballerina 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for athena-ballerina 0.0.6
File Size Uploaded Provenance Actions
athena-ballerina-0.0.6.tar.gz 9.1 kB Without provenance Details for athena-ballerina-0.0.6.tar.gz

Release files / athena-ballerina-0.0.6.tar.gz

Download URL athena-ballerina-0.0.6.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c054ae18d8ab70d3912e63443027dfbd9f14f0e0cb64583766f364e76079b1ac
BLAKE2b-256 checksum
How to use checksums
b15a13bedf9633ad9625e30e19c97f0c7e2ff40cf32e8d0d2765114cec3e2f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10

Security for athena-ballerina 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page