Skip to main content

auto schema for a db

Project description

This takes a sqlalchemy schema and applies alembic migrations.

It's used by the ent framework on top of alembic autogenerate to ensure that all supported schema types are automatically handled.

Will beef up this README eventually and add examples later.

Called as follows: python3 auto_schema -s={pathToSchema} -e={engineURL}.

Only supports Postgres DB at the moment.

Concurrent indexes

auto_schema renders CREATE INDEX CONCURRENTLY when the SQLAlchemy index uses postgresql_concurrently=True. This is surfaced in ent via indices: [{ ..., concurrently: true }] or field-level indexConcurrently: true for index: true.

Notes:

  • Concurrent index ops are wrapped in autocommit_block() in generated Alembic revisions.
  • Drops are only concurrent if the generated op explicitly includes postgresql_concurrently=True (it cannot be inferred for removed indexes).

Design notes and tradeoffs:

  • We do not default to concurrent drops. DROP INDEX CONCURRENTLY is Postgres-specific and must run outside a transaction; defaulting it everywhere would be surprising and would break non-Postgres use.
  • We cannot infer whether an existing index was created concurrently once it is removed from schema. Postgres does not store that metadata, and Alembic's diff only yields a DropIndexOp without the flag.
  • Alembic can render postgresql_concurrently=True, but it does not automatically wrap it in autocommit_block(). To guarantee correctness we use a renderer override; alternatives are custom ops that emit SQL or an autogenerate rewriter.

If we ever want concurrent drops, options include:

  • Per-index dropConcurrently in schema.
  • A global Postgres-only config flag to drop indexes concurrently (with warnings).
  • A migration helper users can call explicitly when needed.

Partial indexes

Partial indexes are supported via postgresql_where=sa.text(...) and sqlite_where=sa.text(...) in SQLAlchemy. In ent schema, use indices: [{ ..., where: "place = 1" }] or indexWhere: "place = 1" for index: true. The clause is a raw SQL string and should reference DB column names.

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

auto_schema-0.0.39.tar.gz (45.2 kB view details)

Uploaded Source

Built Distribution

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

auto_schema-0.0.39-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

Details for the file auto_schema-0.0.39.tar.gz.

File metadata

  • Download URL: auto_schema-0.0.39.tar.gz
  • Upload date:
  • Size: 45.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for auto_schema-0.0.39.tar.gz
Algorithm Hash digest
SHA256 465b552b77ecd07c351709c44419b866ebeb00ab1b80e9807c7fee13b8b3ce7c
MD5 9061f06bf4084da96dde824358607aca
BLAKE2b-256 b7f762f3212ba70d6f25aabbe99a433321c4f03efe21ff4dc5e3a4b973f947e7

See more details on using hashes here.

File details

Details for the file auto_schema-0.0.39-py3-none-any.whl.

File metadata

  • Download URL: auto_schema-0.0.39-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for auto_schema-0.0.39-py3-none-any.whl
Algorithm Hash digest
SHA256 2d59b325c424db175b8b193ba72b69a35469f84454f3246030b80438d9fb39d5
MD5 fcad9d5b154921f596f678c9500c67fb
BLAKE2b-256 ab00e430e51615de8dba394a9288aea295ad5de186cd33cc4ab4bbfd9e83d862

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