simple-module-db 0.0.45__tar.gz → 0.0.46__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.46}/PKG-INFO +2 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/pyproject.toml +2 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_sqlite_index_compare.py +3 -2
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/migration_portability.py +42 -15
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/migrations.py +15 -5
- simple_module_db-0.0.46/tests/test_db_expression_index_warning_scope.py +95 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_migration_portability.py +6 -3
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/.gitignore +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/LICENSE +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/README.md +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/__init__.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_bulk_audit_records.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_bulk_pk_update.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_core_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_core_walk.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_engine_policies.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_entity_selectables.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_migration_render.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_persisted_owner.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/_secondary_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/admission.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/audit_redaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/audit_sinks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/base.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/bulk_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/bulk_audit_targets.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/bulk_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/callbacks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/core_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/data_compatibility.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/deps.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/engine_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/extensions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/flush_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/independent.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/insert_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/insert_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/leases.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/listeners.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/migration_state.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/mixins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/model_registry.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/pagination.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/provider.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/py.typed +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/query_filter.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/query_stats.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/resource_policy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/scope_predicates.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/search.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/stored_settings.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/tenancy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/tenant_cleanup.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/transaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/types.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/user_directory_sql.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/simple_module_db/writes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_alembic_project.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_audit_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_bulk_audit_support.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_core_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_db_dml_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_db_read_scope_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_db_shape_matrix.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/_models.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/conftest.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_audit_per_engine.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_aware_datetime.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_base.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_aliased_join_text_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_aliased_selectable_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_audit_regressions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_bulk_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_bulk_audit_targets.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_connection_policy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_core_full_setup_join.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_core_in_orm_select.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_core_join_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_core_nested_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_credential_audit.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_credential_log_masking.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_data_compatibility_doctor.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_dml_target_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_doctor_session_filters.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_engine_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_engine_policy_resolution.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_extensions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_extensions_pg.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_flush_persisted_owner.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_independent_checkpoint.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_insert_select_tenant.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_insert_value_subqueries.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_lease_lock_wait.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_listeners_attach.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_logging.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_migration_doctor.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_migration_review_regressions.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_migration_state.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_nested_dml_and_bulk_api.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_pagination.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_pagination_options.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_query_stats.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_relationship_loader_scope.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_response_finalization.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_savepoint_callbacks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_secondary_scope_execution.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_shape_matrix_dml.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_shape_matrix_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_shape_matrix_selects.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_sqlite_admission_lock.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_sqlite_savepoint.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_sqlite_wal_switch.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_stored_settings.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_strict_insert_context.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_tenant_cleanup.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_tenant_upsert_guard.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_user_directory_sql.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_db_write_marks.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_default_tenant.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_independent_session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_migrations.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_migrations_sqlite_index_compare.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_mixins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_multi_tenancy.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_query_filter_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_query_filter_rel_outer_joins.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_query_filters.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_rollback_logging.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_session.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_soft_delete_shapes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_tenant_dml.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_tenant_shapes.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_tenant_strict.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/tests/test_transaction.py +0 -0
- {simple_module_db-0.0.45 → simple_module_db-0.0.46}/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.46
|
|
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.46
|
|
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.46"
|
|
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.46",
|
|
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.46}/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.46}/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``.
|
|
@@ -23,8 +24,11 @@ from collections.abc import Iterator
|
|
|
23
24
|
from typing import Any
|
|
24
25
|
|
|
25
26
|
import sqlalchemy as sa
|
|
26
|
-
from alembic.operations.ops import AddColumnOp, AlterColumnOp, CreateTableOp
|
|
27
|
-
from simple_module_core.diagnostics._expression_index import
|
|
27
|
+
from alembic.operations.ops import AddColumnOp, AlterColumnOp, CreateIndexOp, CreateTableOp
|
|
28
|
+
from simple_module_core.diagnostics._expression_index import (
|
|
29
|
+
expression_index_advice,
|
|
30
|
+
find_expression_indexes,
|
|
31
|
+
)
|
|
28
32
|
from sqlalchemy.dialects import postgresql
|
|
29
33
|
from sqlalchemy.schema import DefaultClause
|
|
30
34
|
from sqlalchemy.sql.elements import ColumnElement, False_, TextClause, True_
|
|
@@ -116,38 +120,61 @@ def rewrite_boolean_defaults(upgrade_ops: Any) -> None:
|
|
|
116
120
|
column.server_default = DefaultClause(replacement)
|
|
117
121
|
|
|
118
122
|
|
|
119
|
-
def warn_unverifiable_expression_indexes(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
def warn_unverifiable_expression_indexes(
|
|
124
|
+
dialect_name: str | None,
|
|
125
|
+
metadata: sa.MetaData,
|
|
126
|
+
upgrade_ops: Any = None,
|
|
127
|
+
existing_index_names: set[str] | None = None,
|
|
128
|
+
) -> list:
|
|
129
|
+
"""Warn when a revision autogenerated on SQLite misses expression indexes.
|
|
130
|
+
|
|
131
|
+
SQLite cannot reflect an expression index's definition, so autogenerate
|
|
132
|
+
skips them, but it does record their names. The revision hook passes
|
|
133
|
+
``upgrade_ops`` (after re-emitting the indexes of new tables) and the index
|
|
134
|
+
names the database already has; then only indexes that are in neither are
|
|
135
|
+
named: one added to an existing table, typically. A fresh initial schema
|
|
136
|
+
creates them, and a revision on another table leaves them alone, so both
|
|
137
|
+
stay silent (GH #917). Without those arguments every expression index in
|
|
138
|
+
``metadata`` is named.
|
|
139
|
+
|
|
140
|
+
A warning rather than an error: a PostgreSQL run is the real gate, and an
|
|
141
|
+
index whose name exists may still differ in definition. Returns the
|
|
127
142
|
``(table, index)`` pairs it warned about.
|
|
128
143
|
"""
|
|
129
144
|
if dialect_name != "sqlite":
|
|
130
145
|
return []
|
|
131
146
|
found = find_expression_indexes(metadata.tables.values())
|
|
147
|
+
if upgrade_ops is not None:
|
|
148
|
+
emitted = {
|
|
149
|
+
op.index_name for op in iter_ops_recursive(upgrade_ops) if isinstance(op, CreateIndexOp)
|
|
150
|
+
}
|
|
151
|
+
existing = existing_index_names or set()
|
|
152
|
+
found = [(t, i) for t, i in found if i not in emitted and i not in existing]
|
|
132
153
|
if not found:
|
|
133
154
|
return []
|
|
134
155
|
listing = "\n".join(f" - {index} on {table}" for table, index in found)
|
|
135
156
|
logger.warning(
|
|
136
157
|
"\n%s\n"
|
|
137
158
|
"WARNING: autogenerating on SQLite. SQLite cannot reflect expression indexes,\n"
|
|
138
|
-
"so this revision does NOT
|
|
139
|
-
"
|
|
159
|
+
"so this revision does NOT create the following, which the models declare\n"
|
|
160
|
+
"and the database does not have:\n"
|
|
140
161
|
"%s\n"
|
|
141
|
-
"Add them to the revision by hand and
|
|
142
|
-
"(`make migrations-roundtrip-pg`). See docs/module-authoring.md, Migrations.\n"
|
|
162
|
+
"Add them to the revision by hand and %s.\n"
|
|
143
163
|
"%s",
|
|
144
164
|
"=" * 78,
|
|
145
165
|
listing,
|
|
166
|
+
expression_index_advice(),
|
|
146
167
|
"=" * 78,
|
|
147
168
|
)
|
|
148
169
|
return found
|
|
149
170
|
|
|
150
171
|
|
|
172
|
+
def sqlite_index_names(connection: Any) -> set[str]:
|
|
173
|
+
"""Every index name in a SQLite database, expression indexes included."""
|
|
174
|
+
rows = connection.execute(sa.text("SELECT name FROM sqlite_master WHERE type = 'index'"))
|
|
175
|
+
return {row[0] for row in rows}
|
|
176
|
+
|
|
177
|
+
|
|
151
178
|
def drop_enums_if_postgres(op: Any, *names: str) -> None:
|
|
152
179
|
"""Drop the named enum types on PostgreSQL; a no-op elsewhere.
|
|
153
180
|
|
|
@@ -36,6 +36,7 @@ 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
|
+
sqlite_index_names,
|
|
39
40
|
warn_unverifiable_expression_indexes,
|
|
40
41
|
)
|
|
41
42
|
|
|
@@ -195,8 +196,8 @@ def make_process_revision_directives(
|
|
|
195
196
|
alone, which keeps this dialect-agnostic rather than special-casing SQLite.
|
|
196
197
|
|
|
197
198
|
It also rewrites ``0``/``1``/``false``/``true`` server defaults on Boolean
|
|
198
|
-
columns to ``sa.false()``/``sa.true()`` and, when running on SQLite,
|
|
199
|
-
|
|
199
|
+
columns to ``sa.false()``/``sa.true()`` and, when running on SQLite, names
|
|
200
|
+
the expression indexes the revision misses (see
|
|
200
201
|
:mod:`simple_module_db.migration_portability`).
|
|
201
202
|
|
|
202
203
|
Call as::
|
|
@@ -213,15 +214,17 @@ def make_process_revision_directives(
|
|
|
213
214
|
expression_indexes.setdefault(table.name, []).append(index)
|
|
214
215
|
|
|
215
216
|
def process_revision_directives(context, revision, directives):
|
|
216
|
-
|
|
217
|
-
getattr(getattr(context, "dialect", None), "name", None), metadata
|
|
218
|
-
)
|
|
217
|
+
dialect_name = getattr(getattr(context, "dialect", None), "name", None)
|
|
219
218
|
for script in directives:
|
|
220
219
|
upgrade_ops = getattr(script, "upgrade_ops", None)
|
|
221
220
|
if upgrade_ops is not None:
|
|
222
221
|
rewrite_boolean_defaults(upgrade_ops)
|
|
223
222
|
if expression_indexes:
|
|
224
223
|
_inject_create_index_after_create_table(upgrade_ops, expression_indexes)
|
|
224
|
+
# After the re-emission, so an index this revision creates is not reported.
|
|
225
|
+
warn_unverifiable_expression_indexes(
|
|
226
|
+
dialect_name, metadata, upgrade_ops, _existing_sqlite_indexes(context)
|
|
227
|
+
)
|
|
225
228
|
downgrade_ops = getattr(script, "downgrade_ops", None)
|
|
226
229
|
if downgrade_ops is not None:
|
|
227
230
|
# A downgrade re-creates dropped tables/columns from reflected
|
|
@@ -233,6 +236,13 @@ def make_process_revision_directives(
|
|
|
233
236
|
return process_revision_directives
|
|
234
237
|
|
|
235
238
|
|
|
239
|
+
def _existing_sqlite_indexes(context) -> set[str]:
|
|
240
|
+
connection = getattr(context, "connection", None)
|
|
241
|
+
if connection is None or connection.dialect.name != "sqlite":
|
|
242
|
+
return set()
|
|
243
|
+
return sqlite_index_names(connection)
|
|
244
|
+
|
|
245
|
+
|
|
236
246
|
def _existing_index_names(container, op_type) -> set[str | None]:
|
|
237
247
|
"""Names of every ``op_type`` index op already present anywhere under ``container``."""
|
|
238
248
|
return {
|
|
@@ -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.46}/tests/test_db_aliased_join_text_scope.py
RENAMED
|
File without changes
|
{simple_module_db-0.0.45 → simple_module_db-0.0.46}/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.46}/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.46}/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.46}/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.46}/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.46}/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.46}/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.46}/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.46}/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.46}/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
|