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.35.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.35-py3-none-any.whl (41.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: auto_schema-0.0.35.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.35.tar.gz
Algorithm Hash digest
SHA256 69de9cbece2615021f7ed99a11cf163e13fee7f2668a77869201cb1179ccc058
MD5 07d5f445a8667008fdbcc64d7b324f2e
BLAKE2b-256 34c24c8db94d8cb428ddc708cd13f984508c5dfcc3a931486a6a0a23a0081086

See more details on using hashes here.

File details

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

File metadata

  • Download URL: auto_schema-0.0.35-py3-none-any.whl
  • Upload date:
  • Size: 41.8 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.35-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb3ec711d424746d746be8b8e3e6ac7ea9c99b6bc8d381cf1520f4b20e95272
MD5 03eba977b9818be8e54869dd8b048d97
BLAKE2b-256 875864c9849729b8924fb00ea0ecd2c765b310e160807264a27851f042368b99

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