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 CONCURRENTLYis 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
DropIndexOpwithout the flag. - Alembic can render
postgresql_concurrently=True, but it does not automatically wrap it inautocommit_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
dropConcurrentlyin 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file auto_schema-0.0.34.tar.gz.
File metadata
- Download URL: auto_schema-0.0.34.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbbf7bdfbea2e5497b0e3153ef4458b127c8dcd35a30a232e626b520335b8e87
|
|
| MD5 |
e5af4b5a9d200ded0ece304f1fa80758
|
|
| BLAKE2b-256 |
0ed9422744d392889f10b3e92c4e9ce1ea693b4642a14022924a9fff928763e4
|
File details
Details for the file auto_schema-0.0.34-py3-none-any.whl.
File metadata
- Download URL: auto_schema-0.0.34-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19cd284e9de313f9ad8f285b6f23d102ff4bbe0b039ca0c0e627eab897c5be3b
|
|
| MD5 |
6e49e714fac359dbe379f6f90c983e15
|
|
| BLAKE2b-256 |
184a75952971d0ee3b9ef61faae7e17a189e7ecd08114ccea5b7afcfa99bec68
|