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.36.tar.gz (43.1 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.36-py3-none-any.whl (42.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for auto_schema-0.0.36.tar.gz
Algorithm Hash digest
SHA256 dc336e4f6fccd16ef7bf8f1428f9e7a68a305a41a72f8bf70958fb287f8c8993
MD5 8618f3fb3e1b77f65d4bd2e2c942839f
BLAKE2b-256 7fc775c614b0be413f8105b8fd25174060f4d51ad3bc4da361679bb246913f1c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for auto_schema-0.0.36-py3-none-any.whl
Algorithm Hash digest
SHA256 d7197cd5dd6d5d5bd4284d6ee7295f42203f8737110748c9d2a1ed68ffabcaad
MD5 d9ddd041b8fce986bf500c36d4585f35
BLAKE2b-256 a3ae1a0f5a5e85df24099bed7eb1141cbaefd49ab49c14be2f1e3d2c03a5073e

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