Skip to main content

The cool dude who sets up the stage. Word.

Project description

scenographer

PyPI pyversions GitHub license PyPI version shields.io

Maintenance zyperco

scenographer is a Python script that can create a subset of a postgres database, without losing referential integrity.

The goal is to be able to spawn data-correct databases to easily create new environments that can be used for testing and / or demo'ing.

Relevant links:

Installation

Use pip to install scenographer.

pip install scenographer

Usage

Scenographer requires a configuration file. An empty one, to serve as a starting point, is available by running scenographer empty-config.

After adjusting the configuration file, it's easy to start the sampling run:

scenographer bin/scenographer sample config.json

or if the schema doesn't need to be recreated in the target database:

scenographer bin/scenographer sample config.json --skip-schema

Configuration

SOURCE_DATABASE_URL

The connection string for the source database. Only Postgres is supported.

TARGET_DATABASE_URL

The connection string for the target database. Only Postgres is supported.

IGNORE_RELATIONS

Scenographer works by traversing a DAG graph created from the foreign key constraints of the database. However, it's not always the case that the database forms a DAG. To handle those cases, some foreign keys can be ignored by adding exceptions in this form:

IGNORE_RELATIONS = [
  {"pk": "product.id", "fk": "client.favorite_product_id"}
]

EXTEND_RELATIONS

In other ocasions, the actual foreign key constraint is not present in the database, although it exists in the business-side of things (like Rails does it). Additional relations can be added to handle those cases. The relations take the same format of IGNORE_RELATIONS .

IGNORE_TABLES

Some tables are extra. They may not matter, they may require a special solution or they are part of different components. Either way, you can ignore them.

QUERY_MODIFIERS

For some cases, it's useful to tap into the actual queries being made. For that, you can add an entry here. Here's an example:

QUERY_MODIFIERS={
    "_default": {"conditions": [], "limit": 300},
    "users": {"conditions": ["email ilike '%@example.com'"]},
}

Each entry is a table, with the exception of _default which is applied to all queries. Its values can have a conditions and/or limit key. For conditions you can write plain sql.

OUTPUT_DIRECTORY

At some point, the data is converted into CSV files to be imported into postgres. This is the directory for said CSV files. If you don't care about it, feel free to ignore. If it's not declared, it will create and use a temporary dictory instead.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

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

scenographer-0.1.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

scenographer-0.1.1-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scenographer-0.1.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Linux/4.15.0-1077-aws

File hashes

Hashes for scenographer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3e92d07413930cbd67ab90df03f034c89f8b0927d255a5654b2a902c5f1acfb2
MD5 eee612fdb61a6a12ba84bd14cbd71a70
BLAKE2b-256 9e0b08d97c79be05272fd8cf5a304dcac8cdd506fce9f8978e68a42f82e82431

See more details on using hashes here.

File details

Details for the file scenographer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: scenographer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.0 CPython/3.8.0 Linux/4.15.0-1077-aws

File hashes

Hashes for scenographer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 620fdd8a60dfe486908568376dfab81baedd33531de25cce18f9f20ccd1e0a6b
MD5 b36e4720f50771d90b8bf2a63fa3f924
BLAKE2b-256 b8afd1bb2f2a615525cb6a6081ab06b6789ccb9725ec4897bf6b86ddc0af1a04

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