simple-module-db 0.0.45__tar.gz → 0.0.47__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/PKG-INFO +2 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/pyproject.toml +2 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_sqlite_index_compare.py +3 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/migration_portability.py +70 -14
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/migrations.py +17 -5
- simple_module_db-0.0.47/tests/test_db_expression_index_library_warnings.py +51 -0
- simple_module_db-0.0.47/tests/test_db_expression_index_warning_scope.py +95 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_migration_portability.py +6 -3
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/.gitignore +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/LICENSE +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/README.md +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/__init__.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_bulk_audit_records.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_bulk_pk_update.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_core_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_core_walk.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_engine_policies.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_entity_selectables.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_migration_render.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_persisted_owner.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_secondary_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/admission.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/audit_redaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/audit_sinks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/base.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/bulk_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/bulk_audit_targets.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/bulk_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/callbacks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/core_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/data_compatibility.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/deps.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/engine_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/extensions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/flush_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/independent.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/insert_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/insert_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/leases.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/listeners.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/migration_state.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/mixins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/model_registry.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/pagination.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/provider.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/py.typed +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/query_filter.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/query_stats.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/resource_policy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/scope_predicates.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/search.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/stored_settings.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/tenancy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/tenant_cleanup.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/transaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/types.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/user_directory_sql.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/writes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_alembic_project.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_audit_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_bulk_audit_support.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_core_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_db_dml_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_db_read_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_db_shape_matrix.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/conftest.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_audit_per_engine.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_aware_datetime.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_base.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_aliased_join_text_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_aliased_selectable_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_audit_regressions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_bulk_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_bulk_audit_targets.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_connection_policy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_core_full_setup_join.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_core_in_orm_select.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_core_join_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_core_nested_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_credential_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_credential_log_masking.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_data_compatibility_doctor.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_dml_target_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_doctor_session_filters.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_engine_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_engine_policy_resolution.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_extensions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_extensions_pg.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_flush_persisted_owner.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_independent_checkpoint.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_insert_select_tenant.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_insert_value_subqueries.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_lease_lock_wait.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_listeners_attach.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_logging.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_migration_doctor.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_migration_review_regressions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_migration_state.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_nested_dml_and_bulk_api.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_pagination.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_pagination_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_query_stats.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_relationship_loader_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_response_finalization.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_savepoint_callbacks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_secondary_scope_execution.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_shape_matrix_dml.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_shape_matrix_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_shape_matrix_selects.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_sqlite_admission_lock.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_sqlite_savepoint.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_sqlite_wal_switch.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_stored_settings.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_strict_insert_context.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_tenant_cleanup.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_tenant_upsert_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_user_directory_sql.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_write_marks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_default_tenant.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_independent_session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_migrations.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_migrations_sqlite_index_compare.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_mixins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_multi_tenancy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_query_filter_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_query_filter_rel_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_query_filters.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_rollback_logging.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_soft_delete_shapes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_tenant_dml.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_tenant_shapes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_tenant_strict.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_transaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_writes.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: simple_module_db
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.47
|
|
4
4
|
Summary: Per-module SQLModel Base, async session, standard mixins (Audit, SoftDelete, MultiTenant, Versioned) for simple_module
|
|
5
5
|
Project-URL: Homepage, https://github.com/antosubash/simple_module_python
|
|
6
6
|
Project-URL: Repository, https://github.com/antosubash/simple_module_python
|
|
@@ -25,7 +25,7 @@ Requires-Dist: aiosqlite<0.23,>=0.20
|
|
|
25
25
|
Requires-Dist: alembic<2,>=1.16.3
|
|
26
26
|
Requires-Dist: asyncpg<0.33,>=0.30
|
|
27
27
|
Requires-Dist: psycopg2-binary<3,>=2.9
|
|
28
|
-
Requires-Dist: simple-module-core==0.0.
|
|
28
|
+
Requires-Dist: simple-module-core==0.0.47
|
|
29
29
|
Requires-Dist: sqlalchemy[asyncio]<3,>=2.0.2
|
|
30
30
|
Requires-Dist: sqlmodel<0.1,>=0.0.22
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "simple_module_db"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.47"
|
|
4
4
|
description = "Per-module SQLModel Base, async session, standard mixins (Audit, SoftDelete, MultiTenant, Versioned) for simple_module"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -28,7 +28,7 @@ dependencies = [
|
|
|
28
28
|
# The async app code goes through asyncpg; migration env.py rewrites the
|
|
29
29
|
# URL to +psycopg2 because Alembic's online migrations are sync-only.
|
|
30
30
|
"psycopg2-binary>=2.9,<3",
|
|
31
|
-
"simple_module_core==0.0.
|
|
31
|
+
"simple_module_core==0.0.47",
|
|
32
32
|
"sqlalchemy[asyncio]>=2.0.2,<3",
|
|
33
33
|
"sqlmodel>=0.0.22,<0.1",
|
|
34
34
|
]
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/_sqlite_index_compare.py
RENAMED
|
@@ -11,8 +11,9 @@ schema. Postgres reflects the ordering, so it compares these faithfully.
|
|
|
11
11
|
``make_include_object`` can skip it on SQLite. Anything else still reaches
|
|
12
12
|
Alembic: a different column list, a uniqueness change, or a real expression
|
|
13
13
|
such as ``lower(email)``. A change of ordering alone (``DESC`` to ``ASC``) is not
|
|
14
|
-
reported on SQLite, which cannot reflect ordering at all;
|
|
15
|
-
trip (``make migrations-roundtrip-pg``) is what
|
|
14
|
+
reported on SQLite, which cannot reflect ordering at all; a PostgreSQL
|
|
15
|
+
round trip (``make migrations-roundtrip-pg`` in the framework repository) is what
|
|
16
|
+
catches it.
|
|
16
17
|
"""
|
|
17
18
|
|
|
18
19
|
from __future__ import annotations
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/simple_module_db/migration_portability.py
RENAMED
|
@@ -7,7 +7,8 @@ or never sees, and neither ``alembic check`` nor the boot check notices:
|
|
|
7
7
|
integer default on a boolean column. :func:`rewrite_boolean_defaults` and
|
|
8
8
|
:func:`render_boolean_default` emit ``sa.false()`` / ``sa.true()`` instead.
|
|
9
9
|
* Expression indexes (``lower(email)``) are skipped on SQLite because it cannot
|
|
10
|
-
reflect them. :func:`warn_unverifiable_expression_indexes`
|
|
10
|
+
reflect them. :func:`warn_unverifiable_expression_indexes` names the ones a
|
|
11
|
+
revision misses.
|
|
11
12
|
* ``op.drop_table`` leaves ``CREATE TYPE`` behind on Postgres, so a downgrade
|
|
12
13
|
followed by an upgrade fails with ``DuplicateObject``. Use
|
|
13
14
|
:func:`drop_enums_if_postgres` in the revision's ``downgrade``.
|
|
@@ -19,13 +20,19 @@ or never sees, and neither ``alembic check`` nor the boot check notices:
|
|
|
19
20
|
from __future__ import annotations
|
|
20
21
|
|
|
21
22
|
import logging
|
|
23
|
+
import re
|
|
24
|
+
import warnings
|
|
22
25
|
from collections.abc import Iterator
|
|
23
26
|
from typing import Any
|
|
24
27
|
|
|
25
28
|
import sqlalchemy as sa
|
|
26
|
-
from alembic.operations.ops import AddColumnOp, AlterColumnOp, CreateTableOp
|
|
27
|
-
from simple_module_core.diagnostics._expression_index import
|
|
29
|
+
from alembic.operations.ops import AddColumnOp, AlterColumnOp, CreateIndexOp, CreateTableOp
|
|
30
|
+
from simple_module_core.diagnostics._expression_index import (
|
|
31
|
+
expression_index_advice,
|
|
32
|
+
find_expression_indexes,
|
|
33
|
+
)
|
|
28
34
|
from sqlalchemy.dialects import postgresql
|
|
35
|
+
from sqlalchemy.exc import SAWarning
|
|
29
36
|
from sqlalchemy.schema import DefaultClause
|
|
30
37
|
from sqlalchemy.sql.elements import ColumnElement, False_, TextClause, True_
|
|
31
38
|
|
|
@@ -116,38 +123,87 @@ def rewrite_boolean_defaults(upgrade_ops: Any) -> None:
|
|
|
116
123
|
column.server_default = DefaultClause(replacement)
|
|
117
124
|
|
|
118
125
|
|
|
119
|
-
def
|
|
120
|
-
"""
|
|
126
|
+
def silence_expression_index_reflection_warnings(metadata: sa.MetaData) -> None:
|
|
127
|
+
"""Ignore the library warnings about expression indexes the models declare (GH #933).
|
|
121
128
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
On SQLite, SQLAlchemy warns that it skipped reflecting each expression index
|
|
130
|
+
and Alembic that it skipped comparing it, on every autogenerate. For an
|
|
131
|
+
index in ``metadata`` the revision hook already covers both cases: it
|
|
132
|
+
re-emits the index for a new table and :func:`warn_unverifiable_expression_indexes`
|
|
133
|
+
names one the database lacks. Indexes the models do not declare still warn.
|
|
134
|
+
"""
|
|
135
|
+
names = [index for _, index in find_expression_indexes(metadata.tables.values())]
|
|
136
|
+
if not names:
|
|
137
|
+
return
|
|
138
|
+
alternatives = "|".join(re.escape(name) for name in names)
|
|
139
|
+
warnings.filterwarnings(
|
|
140
|
+
"ignore",
|
|
141
|
+
message=rf"Skipped unsupported reflection of expression-based index ({alternatives})$",
|
|
142
|
+
category=SAWarning,
|
|
143
|
+
)
|
|
144
|
+
warnings.filterwarnings(
|
|
145
|
+
"ignore",
|
|
146
|
+
message=rf"autogenerate skipping metadata-specified expression-based index "
|
|
147
|
+
rf"'({alternatives})';",
|
|
148
|
+
category=UserWarning,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def warn_unverifiable_expression_indexes(
|
|
153
|
+
dialect_name: str | None,
|
|
154
|
+
metadata: sa.MetaData,
|
|
155
|
+
upgrade_ops: Any = None,
|
|
156
|
+
existing_index_names: set[str] | None = None,
|
|
157
|
+
) -> list:
|
|
158
|
+
"""Warn when a revision autogenerated on SQLite misses expression indexes.
|
|
159
|
+
|
|
160
|
+
SQLite cannot reflect an expression index's definition, so autogenerate
|
|
161
|
+
skips them, but it does record their names. The revision hook passes
|
|
162
|
+
``upgrade_ops`` (after re-emitting the indexes of new tables) and the index
|
|
163
|
+
names the database already has; then only indexes that are in neither are
|
|
164
|
+
named: one added to an existing table, typically. A fresh initial schema
|
|
165
|
+
creates them, and a revision on another table leaves them alone, so both
|
|
166
|
+
stay silent (GH #917). Without those arguments every expression index in
|
|
167
|
+
``metadata`` is named.
|
|
168
|
+
|
|
169
|
+
A warning rather than an error: a PostgreSQL run is the real gate, and an
|
|
170
|
+
index whose name exists may still differ in definition. Returns the
|
|
127
171
|
``(table, index)`` pairs it warned about.
|
|
128
172
|
"""
|
|
129
173
|
if dialect_name != "sqlite":
|
|
130
174
|
return []
|
|
131
175
|
found = find_expression_indexes(metadata.tables.values())
|
|
176
|
+
if upgrade_ops is not None:
|
|
177
|
+
emitted = {
|
|
178
|
+
op.index_name for op in iter_ops_recursive(upgrade_ops) if isinstance(op, CreateIndexOp)
|
|
179
|
+
}
|
|
180
|
+
existing = existing_index_names or set()
|
|
181
|
+
found = [(t, i) for t, i in found if i not in emitted and i not in existing]
|
|
132
182
|
if not found:
|
|
133
183
|
return []
|
|
134
184
|
listing = "\n".join(f" - {index} on {table}" for table, index in found)
|
|
135
185
|
logger.warning(
|
|
136
186
|
"\n%s\n"
|
|
137
187
|
"WARNING: autogenerating on SQLite. SQLite cannot reflect expression indexes,\n"
|
|
138
|
-
"so this revision does NOT
|
|
139
|
-
"
|
|
188
|
+
"so this revision does NOT create the following, which the models declare\n"
|
|
189
|
+
"and the database does not have:\n"
|
|
140
190
|
"%s\n"
|
|
141
|
-
"Add them to the revision by hand and
|
|
142
|
-
"(`make migrations-roundtrip-pg`). See docs/module-authoring.md, Migrations.\n"
|
|
191
|
+
"Add them to the revision by hand and %s.\n"
|
|
143
192
|
"%s",
|
|
144
193
|
"=" * 78,
|
|
145
194
|
listing,
|
|
195
|
+
expression_index_advice(),
|
|
146
196
|
"=" * 78,
|
|
147
197
|
)
|
|
148
198
|
return found
|
|
149
199
|
|
|
150
200
|
|
|
201
|
+
def sqlite_index_names(connection: Any) -> set[str]:
|
|
202
|
+
"""Every index name in a SQLite database, expression indexes included."""
|
|
203
|
+
rows = connection.execute(sa.text("SELECT name FROM sqlite_master WHERE type = 'index'"))
|
|
204
|
+
return {row[0] for row in rows}
|
|
205
|
+
|
|
206
|
+
|
|
151
207
|
def drop_enums_if_postgres(op: Any, *names: str) -> None:
|
|
152
208
|
"""Drop the named enum types on PostgreSQL; a no-op elsewhere.
|
|
153
209
|
|
|
@@ -36,6 +36,8 @@ from simple_module_db.extensions import ( # noqa: F401 (ensure_db_extensions r
|
|
|
36
36
|
from simple_module_db.migration_portability import (
|
|
37
37
|
iter_ops_recursive,
|
|
38
38
|
rewrite_boolean_defaults,
|
|
39
|
+
silence_expression_index_reflection_warnings,
|
|
40
|
+
sqlite_index_names,
|
|
39
41
|
warn_unverifiable_expression_indexes,
|
|
40
42
|
)
|
|
41
43
|
|
|
@@ -195,8 +197,8 @@ def make_process_revision_directives(
|
|
|
195
197
|
alone, which keeps this dialect-agnostic rather than special-casing SQLite.
|
|
196
198
|
|
|
197
199
|
It also rewrites ``0``/``1``/``false``/``true`` server defaults on Boolean
|
|
198
|
-
columns to ``sa.false()``/``sa.true()`` and, when running on SQLite,
|
|
199
|
-
|
|
200
|
+
columns to ``sa.false()``/``sa.true()`` and, when running on SQLite, names
|
|
201
|
+
the expression indexes the revision misses (see
|
|
200
202
|
:mod:`simple_module_db.migration_portability`).
|
|
201
203
|
|
|
202
204
|
Call as::
|
|
@@ -206,6 +208,7 @@ def make_process_revision_directives(
|
|
|
206
208
|
process_revision_directives=make_process_revision_directives(target_metadata),
|
|
207
209
|
)
|
|
208
210
|
"""
|
|
211
|
+
silence_expression_index_reflection_warnings(metadata)
|
|
209
212
|
expression_indexes: dict[str, list[Index]] = {}
|
|
210
213
|
for table in metadata.tables.values():
|
|
211
214
|
for index in table.indexes:
|
|
@@ -213,15 +216,17 @@ def make_process_revision_directives(
|
|
|
213
216
|
expression_indexes.setdefault(table.name, []).append(index)
|
|
214
217
|
|
|
215
218
|
def process_revision_directives(context, revision, directives):
|
|
216
|
-
|
|
217
|
-
getattr(getattr(context, "dialect", None), "name", None), metadata
|
|
218
|
-
)
|
|
219
|
+
dialect_name = getattr(getattr(context, "dialect", None), "name", None)
|
|
219
220
|
for script in directives:
|
|
220
221
|
upgrade_ops = getattr(script, "upgrade_ops", None)
|
|
221
222
|
if upgrade_ops is not None:
|
|
222
223
|
rewrite_boolean_defaults(upgrade_ops)
|
|
223
224
|
if expression_indexes:
|
|
224
225
|
_inject_create_index_after_create_table(upgrade_ops, expression_indexes)
|
|
226
|
+
# After the re-emission, so an index this revision creates is not reported.
|
|
227
|
+
warn_unverifiable_expression_indexes(
|
|
228
|
+
dialect_name, metadata, upgrade_ops, _existing_sqlite_indexes(context)
|
|
229
|
+
)
|
|
225
230
|
downgrade_ops = getattr(script, "downgrade_ops", None)
|
|
226
231
|
if downgrade_ops is not None:
|
|
227
232
|
# A downgrade re-creates dropped tables/columns from reflected
|
|
@@ -233,6 +238,13 @@ def make_process_revision_directives(
|
|
|
233
238
|
return process_revision_directives
|
|
234
239
|
|
|
235
240
|
|
|
241
|
+
def _existing_sqlite_indexes(context) -> set[str]:
|
|
242
|
+
connection = getattr(context, "connection", None)
|
|
243
|
+
if connection is None or connection.dialect.name != "sqlite":
|
|
244
|
+
return set()
|
|
245
|
+
return sqlite_index_names(connection)
|
|
246
|
+
|
|
247
|
+
|
|
236
248
|
def _existing_index_names(container, op_type) -> set[str | None]:
|
|
237
249
|
"""Names of every ``op_type`` index op already present anywhere under ``container``."""
|
|
238
250
|
return {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""SQLAlchemy's and Alembic's SQLite expression-index warnings are quiet (GH #933).
|
|
2
|
+
|
|
3
|
+
The revision hook re-emits the models' expression indexes for new tables and
|
|
4
|
+
names the ones the database lacks, so the two library warnings about the same
|
|
5
|
+
index told a fresh app nothing it could act on, on every `make migration`.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import warnings
|
|
11
|
+
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
from alembic.autogenerate import produce_migrations
|
|
14
|
+
from alembic.runtime.migration import MigrationContext
|
|
15
|
+
from simple_module_db.migrations import make_process_revision_directives, render_item
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _metadata() -> sa.MetaData:
|
|
19
|
+
md = sa.MetaData()
|
|
20
|
+
sa.Table(
|
|
21
|
+
"people",
|
|
22
|
+
md,
|
|
23
|
+
sa.Column("id", sa.Integer, primary_key=True),
|
|
24
|
+
sa.Column("email", sa.String),
|
|
25
|
+
sa.Index("ix_people_email_lower", sa.text("lower(email)"), unique=True),
|
|
26
|
+
)
|
|
27
|
+
return md
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _autogenerate_warnings(*, undeclared_index: bool = False) -> list[str]:
|
|
31
|
+
target = _metadata()
|
|
32
|
+
engine = sa.create_engine("sqlite://")
|
|
33
|
+
with warnings.catch_warnings(record=True) as caught:
|
|
34
|
+
warnings.simplefilter("always")
|
|
35
|
+
hook = make_process_revision_directives(target)
|
|
36
|
+
with engine.connect() as conn:
|
|
37
|
+
_metadata().create_all(conn)
|
|
38
|
+
if undeclared_index:
|
|
39
|
+
conn.execute(sa.text("CREATE INDEX ix_people_abs_id ON people (abs(id))"))
|
|
40
|
+
ctx = MigrationContext.configure(conn, opts={"render_item": render_item})
|
|
41
|
+
hook(ctx, None, [produce_migrations(ctx, target)])
|
|
42
|
+
return [str(w.message) for w in caught]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_declared_expression_indexes_raise_no_library_warnings() -> None:
|
|
46
|
+
assert not [m for m in _autogenerate_warnings() if "ix_people_email_lower" in m]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_an_index_the_models_do_not_declare_still_warns() -> None:
|
|
50
|
+
messages = _autogenerate_warnings(undeclared_index=True)
|
|
51
|
+
assert any("ix_people_abs_id" in m for m in messages)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""The SQLite expression-index warning names only what the revision missed (GH #917).
|
|
2
|
+
|
|
3
|
+
The hook used to warn about every expression index in the metadata, before it
|
|
4
|
+
had re-emitted them, so a fresh app's initial schema (which does create the
|
|
5
|
+
index) and every unrelated module migration told users to hand-edit it in.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
|
+
import sqlalchemy as sa
|
|
13
|
+
from alembic.autogenerate import produce_migrations
|
|
14
|
+
from alembic.runtime.migration import MigrationContext
|
|
15
|
+
from simple_module_core.diagnostics._expression_index import expression_index_advice
|
|
16
|
+
from simple_module_db.migrations import make_process_revision_directives, render_item
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _metadata(*, extra_column: bool = False) -> sa.MetaData:
|
|
20
|
+
md = sa.MetaData()
|
|
21
|
+
sa.Table(
|
|
22
|
+
"people",
|
|
23
|
+
md,
|
|
24
|
+
sa.Column("id", sa.Integer, primary_key=True),
|
|
25
|
+
sa.Column("email", sa.String),
|
|
26
|
+
*([sa.Column("nickname", sa.String)] if extra_column else []),
|
|
27
|
+
sa.Index("ix_people_email_lower", sa.text("lower(email)"), unique=True),
|
|
28
|
+
)
|
|
29
|
+
sa.Table("orders", md, sa.Column("id", sa.Integer, primary_key=True))
|
|
30
|
+
return md
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _run_hook(existing: sa.MetaData | None, target: sa.MetaData, caplog) -> str:
|
|
34
|
+
engine = sa.create_engine("sqlite://")
|
|
35
|
+
with engine.connect() as conn:
|
|
36
|
+
if existing is not None:
|
|
37
|
+
existing.create_all(conn)
|
|
38
|
+
ctx = MigrationContext.configure(conn, opts={"render_item": render_item})
|
|
39
|
+
script = produce_migrations(ctx, target)
|
|
40
|
+
with caplog.at_level(logging.WARNING, logger="alembic.env"):
|
|
41
|
+
make_process_revision_directives(target)(ctx, None, [script])
|
|
42
|
+
return caplog.text
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_initial_schema_that_creates_the_index_is_silent(caplog) -> None:
|
|
46
|
+
assert "ix_people_email_lower" not in _run_hook(None, _metadata(), caplog)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_revision_on_another_table_is_silent(caplog) -> None:
|
|
50
|
+
existing = _metadata()
|
|
51
|
+
existing.remove(existing.tables["orders"])
|
|
52
|
+
assert "ix_people_email_lower" not in _run_hook(existing, _metadata(), caplog)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_revision_altering_a_table_whose_index_exists_is_silent(caplog) -> None:
|
|
56
|
+
"""SQLite records the index's name even though it cannot reflect it."""
|
|
57
|
+
text = _run_hook(_metadata(), _metadata(extra_column=True), caplog)
|
|
58
|
+
assert "ix_people_email_lower" not in text
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_an_expression_index_added_to_an_existing_table_warns(caplog) -> None:
|
|
62
|
+
"""Autogenerate emits nothing for it on SQLite, so the revision misses it."""
|
|
63
|
+
existing = _metadata()
|
|
64
|
+
existing.tables["people"].indexes.clear()
|
|
65
|
+
text = _run_hook(existing, _metadata(), caplog)
|
|
66
|
+
assert "ix_people_email_lower on people" in text
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_advice_outside_this_repo_points_at_what_exists(tmp_path, monkeypatch) -> None:
|
|
70
|
+
monkeypatch.chdir(tmp_path)
|
|
71
|
+
advice = expression_index_advice()
|
|
72
|
+
assert "migrations-roundtrip-pg" not in advice
|
|
73
|
+
assert "alembic -c host/alembic.ini check" in advice
|
|
74
|
+
assert "PostgreSQL" in advice
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_advice_in_a_checkout_with_the_roundtrip_target(tmp_path, monkeypatch) -> None:
|
|
78
|
+
(tmp_path / "Makefile").write_text("migrations-roundtrip-pg:\n\techo\n", encoding="utf-8")
|
|
79
|
+
monkeypatch.chdir(tmp_path)
|
|
80
|
+
assert "make migrations-roundtrip-pg" in expression_index_advice()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_a_ci_prefixed_target_is_not_the_roundtrip_target(tmp_path, monkeypatch) -> None:
|
|
84
|
+
(tmp_path / "Makefile").write_text("ci-migrations-roundtrip-pg:\n\techo\n", encoding="utf-8")
|
|
85
|
+
monkeypatch.chdir(tmp_path)
|
|
86
|
+
assert "make migrations-roundtrip-pg" not in expression_index_advice()
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_dropping_the_index_does_not_count_as_creating_it() -> None:
|
|
90
|
+
from alembic.operations.ops import DropIndexOp, UpgradeOps
|
|
91
|
+
from simple_module_db.migration_portability import warn_unverifiable_expression_indexes
|
|
92
|
+
|
|
93
|
+
ops = UpgradeOps(ops=[DropIndexOp("ix_people_email_lower", table_name="people")])
|
|
94
|
+
found = warn_unverifiable_expression_indexes("sqlite", _metadata(), ops, set())
|
|
95
|
+
assert found == [("people", "ix_people_email_lower")]
|
|
@@ -103,10 +103,13 @@ def test_expression_index_warning_silent_elsewhere(caplog):
|
|
|
103
103
|
assert caplog.text == ""
|
|
104
104
|
|
|
105
105
|
|
|
106
|
-
def
|
|
106
|
+
def test_hook_is_silent_when_the_revision_creates_the_index(caplog):
|
|
107
|
+
"""The re-emitted index is in the revision (GH #917); scope tests in
|
|
108
|
+
test_db_expression_index_warning_scope.py."""
|
|
107
109
|
with caplog.at_level(logging.WARNING, logger="alembic.env"):
|
|
108
|
-
_autogenerate(_metadata(with_index=True))
|
|
109
|
-
assert "ix_flags_email_lower" in
|
|
110
|
+
code, _, _ = _autogenerate(_metadata(with_index=True))
|
|
111
|
+
assert "ix_flags_email_lower" in code
|
|
112
|
+
assert "ix_flags_email_lower" not in caplog.text
|
|
110
113
|
|
|
111
114
|
|
|
112
115
|
def test_plain_column_index_is_not_flagged():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_aliased_join_text_scope.py
RENAMED
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_aliased_selectable_scope.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_data_compatibility_doctor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_engine_policy_resolution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_insert_value_subqueries.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_migration_review_regressions.py
RENAMED
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_nested_dml_and_bulk_api.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_relationship_loader_scope.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_db_secondary_scope_execution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_migrations_sqlite_index_compare.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.47}/tests/test_query_filter_rel_outer_joins.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|