libex-core 0.25.0__tar.gz → 0.26.0__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.
Files changed (107) hide show
  1. {libex_core-0.25.0 → libex_core-0.26.0}/PKG-INFO +4 -4
  2. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/CHANGELOG.md +17 -0
  3. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/__init__.py +1 -1
  4. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/env.py +2 -9
  5. libex_core-0.26.0/libex_core/storage/migrations/versions/b5e9c3a7f184_trigram_indexes_for_the_search_filters.py +91 -0
  6. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/models.py +21 -0
  7. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/upgrade.py +23 -0
  8. {libex_core-0.25.0 → libex_core-0.26.0}/pyproject.toml +3 -3
  9. {libex_core-0.25.0 → libex_core-0.26.0}/LICENSE +0 -0
  10. {libex_core-0.25.0 → libex_core-0.26.0}/PYPI.md +0 -0
  11. {libex_core-0.25.0 → libex_core-0.26.0}/libex-core-data/share/bash-completion/completions/libex-core +0 -0
  12. {libex_core-0.25.0 → libex_core-0.26.0}/libex-core-data/share/fish/vendor_completions.d/libex-core.fish +0 -0
  13. {libex_core-0.25.0 → libex_core-0.26.0}/libex-core-data/share/man/man1/libex-core.1 +0 -0
  14. {libex_core-0.25.0 → libex_core-0.26.0}/libex-core-data/share/zsh/site-functions/_libex-core +0 -0
  15. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/__main__.py +0 -0
  16. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/asin.py +0 -0
  17. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/__init__.py +0 -0
  18. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/_concurrency.py +0 -0
  19. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/_retry.py +0 -0
  20. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/authors/__init__.py +0 -0
  21. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/authors/by_name.py +0 -0
  22. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/authors/catalog.py +0 -0
  23. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/authors/profile.py +0 -0
  24. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/authors/screens.py +0 -0
  25. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/books.py +0 -0
  26. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/chapters.py +0 -0
  27. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/client.py +0 -0
  28. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/extras.py +0 -0
  29. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/releases.py +0 -0
  30. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/search.py +0 -0
  31. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/audible/series.py +0 -0
  32. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/__init__.py +0 -0
  33. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/_args.py +0 -0
  34. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/_db_args.py +0 -0
  35. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/_render.py +0 -0
  36. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/_run.py +0 -0
  37. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/_shaping.py +0 -0
  38. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/__init__.py +0 -0
  39. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/abs_search.py +0 -0
  40. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/author.py +0 -0
  41. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/book.py +0 -0
  42. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/completion.py +0 -0
  43. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/config.py +0 -0
  44. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/db.py +0 -0
  45. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/narrator.py +0 -0
  46. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/releases.py +0 -0
  47. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/search.py +0 -0
  48. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/commands/series.py +0 -0
  49. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/environment.py +0 -0
  50. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/exit_codes.py +0 -0
  51. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/main.py +0 -0
  52. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/output.py +0 -0
  53. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/parser.py +0 -0
  54. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/session.py +0 -0
  55. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/cli/store_state.py +0 -0
  56. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/exceptions.py +0 -0
  57. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/log_safety.py +0 -0
  58. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/__init__.py +0 -0
  59. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/_common.py +0 -0
  60. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/_shaping.py +0 -0
  61. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/_store.py +0 -0
  62. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/_walks.py +0 -0
  63. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/author_books.py +0 -0
  64. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/authors.py +0 -0
  65. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/books.py +0 -0
  66. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/ingest.py +0 -0
  67. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/releases.py +0 -0
  68. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/search.py +0 -0
  69. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/series.py +0 -0
  70. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/lookup/stored.py +0 -0
  71. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/models.py +0 -0
  72. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/py.typed +0 -0
  73. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/shaping.py +0 -0
  74. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/__init__.py +0 -0
  75. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/base.py +0 -0
  76. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/dialect.py +0 -0
  77. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/filtering.py +0 -0
  78. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/merge.py +0 -0
  79. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/script.py.mako +0 -0
  80. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/438dbe70d041_create_core_tables.py +0 -0
  81. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/6e1b4c9a2d57_add_credit_order_position_to_pivots.py +0 -0
  82. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/9d2f6b4e8a17_index_book_series_by_series.py +0 -0
  83. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/a4d91f7c3b26_key_books_and_series_by_asin_and_region.py +0 -0
  84. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/d3a8f1b65e90_add_manual_entry_at_to_books.py +0 -0
  85. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/migrations/versions/f2b8d6a40c17_index_books_by_manual_entry.py +0 -0
  86. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/__init__.py +0 -0
  87. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/_compat.py +0 -0
  88. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/_regions.py +0 -0
  89. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/books.py +0 -0
  90. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/people.py +0 -0
  91. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/series.py +0 -0
  92. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/shapes.py +0 -0
  93. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/stats.py +0 -0
  94. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/read/walks.py +0 -0
  95. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/sorting.py +0 -0
  96. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/store.py +0 -0
  97. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/types.py +0 -0
  98. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/walk_limits.py +0 -0
  99. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/__init__.py +0 -0
  100. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/books.py +0 -0
  101. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/entities.py +0 -0
  102. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/params.py +0 -0
  103. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/serialize.py +0 -0
  104. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/statements.py +0 -0
  105. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/support.py +0 -0
  106. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/storage/write/walks.py +0 -0
  107. {libex_core-0.25.0 → libex_core-0.26.0}/libex_core/text.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: libex-core
3
- Version: 0.25.0
3
+ Version: 0.26.0
4
4
  Summary: Audible metadata fetched and normalized into data shaped after AudiMeta's.
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -15,14 +15,14 @@ License-File: LICENSE
15
15
  Requires-Dist: httpx>=0.28.1,<0.29
16
16
  Requires-Dist: pydantic>=2.13.4,<3
17
17
  Requires-Dist: sqlalchemy>=2.0.46,<2.1 ; extra == "postgres"
18
- Requires-Dist: alembic>=1.18.4,<1.19 ; extra == "postgres"
18
+ Requires-Dist: alembic>=1.18.4,<1.21 ; extra == "postgres"
19
19
  Requires-Dist: asyncpg>=0.31,<0.32 ; extra == "postgres"
20
20
  Requires-Dist: httpx[socks]>=0.28.1,<0.29 ; extra == "socks"
21
21
  Requires-Dist: sqlalchemy>=2.0.46,<2.1 ; extra == "sqlite"
22
- Requires-Dist: alembic>=1.18.4,<1.19 ; extra == "sqlite"
22
+ Requires-Dist: alembic>=1.18.4,<1.21 ; extra == "sqlite"
23
23
  Requires-Dist: aiosqlite>=0.22.1,<0.23 ; extra == "sqlite"
24
24
  Requires-Dist: sqlalchemy>=2.0.46,<2.1 ; extra == "storage"
25
- Requires-Dist: alembic>=1.18.4,<1.19 ; extra == "storage"
25
+ Requires-Dist: alembic>=1.18.4,<1.21 ; extra == "storage"
26
26
  Requires-Dist: aiosqlite>=0.22.1,<0.23 ; extra == "storage"
27
27
  Project-URL: Changelog, https://github.com/LibexHQ/Libex/blob/main/libex_core/CHANGELOG.md
28
28
  Project-URL: Homepage, https://github.com/LibexHQ/Libex
@@ -13,6 +13,23 @@ the first published version. Entries for earlier versions record changes made
13
13
  before publication: they are historical record for whoever embeds this package,
14
14
  not evidence that anyone consumed a given version at the time it was cut.
15
15
 
16
+ ## [0.26.0]
17
+
18
+ This release adds a migration and a new requirement for Postgres stores: the `pg_trgm` extension. Run `alembic upgrade head` on any store you already have. A SQLite store is not affected; the revision does nothing there.
19
+
20
+ ### Added
21
+ - **Seven trigram indexes on Postgres,** so the contains-style filters on book title, subtitle, publisher and ISBN, author name, series title and narrator name no longer read the whole table. They are GIN indexes over `gin_trgm_ops`, named `ix_books_title_trgm`, `ix_books_subtitle_trgm`, `ix_books_publisher_trgm`, `ix_books_isbn_trgm`, `ix_authors_name_trgm`, `ix_series_title_trgm` and `ix_narrators_name_trgm`. Queries and results are unchanged. In my tests at about 3.3 million books, selective searches went from about 2 seconds to about 0.08 seconds and matched the unindexed results exactly. The models declare them for Postgres only, so building the tables from the models on Postgres creates them too and needs the extension; the long text columns are not indexed.
22
+ - **The migration needs `pg_trgm` on Postgres.** If the extension is installed, the migration uses whatever schema it is in. If it is missing, the migration creates it in `public`, but only when the role can: the server must offer it and the role needs `CREATE` on the database and on `public`. That check is made before anything is changed, and a role that cannot create it gets an error giving the command to run, with the transaction rolled back and no revision stamped. This chain upgrades in one transaction, so the indexes cannot be built concurrently: while each is built, reads of its table carry on and writes to it wait. Downgrading drops the indexes and keeps the extension.
23
+
24
+ ### Changed
25
+ - **The indexes cost disk and write volume.** About 0.75 GB at 3.3 million books, and bulk writes produce several times more WAL.
26
+ - **Comparing the models with a SQLite database no longer reports the Postgres-only indexes as missing.** The comparison hook skips an index the models declare for a different dialect.
27
+
28
+ ## [0.25.1]
29
+
30
+ ### Fixed
31
+ - **`libex-core[sqlite]` can be installed next to alembic 1.20.** The `sqlite`, `postgres` and `storage` extras capped alembic below 1.19, so pip refused the combination or held alembic back. The cap is now below 1.21. I ran the migration chain on alembic 1.20.0 against both SQLite and Postgres: it upgrades to head, downgrades to base and upgrades again. The lower bound, the schema and the public surface are unchanged, and there is nothing to migrate.
32
+
16
33
  ## [0.25.0]
17
34
 
18
35
  This release adds two migrations: `books` gains a nullable `manual_entry_at` column and a partial index over it. Run `alembic upgrade head` on any store you already have.
@@ -36,6 +36,6 @@ the hosted app that embeds it, and an embedder needs a version to pin against
36
36
  that isn't tied to the hosted app's own release line.
37
37
  """
38
38
 
39
- __version__ = "0.25.0"
39
+ __version__ = "0.26.0"
40
40
 
41
41
  __all__ = ["__version__"]
@@ -19,7 +19,7 @@ from alembic import context
19
19
  import libex_core.storage.models # noqa: F401 -- registers the tables on Base
20
20
  from libex_core.storage.base import Base
21
21
  from libex_core.storage.models import CORE_TABLES
22
- from libex_core.storage.upgrade import VERSION_TABLE
22
+ from libex_core.storage.upgrade import VERSION_TABLE, include_object_for
23
23
 
24
24
  def include_name(name, type_, parent_names):
25
25
  """Only the core tables, on the database side of a comparison."""
@@ -28,13 +28,6 @@ def include_name(name, type_, parent_names):
28
28
  return True
29
29
 
30
30
 
31
- def include_object(obj, name, type_, reflected, compare_to):
32
- """Only the core tables, on the metadata side of a comparison."""
33
- if type_ == "table":
34
- return name in CORE_TABLES
35
- return True
36
-
37
-
38
31
  def run_migrations_online() -> None:
39
32
  connection = context.config.attributes.get("connection")
40
33
  if connection is None:
@@ -47,7 +40,7 @@ def run_migrations_online() -> None:
47
40
  target_metadata=Base.metadata,
48
41
  version_table=VERSION_TABLE,
49
42
  include_name=include_name,
50
- include_object=include_object,
43
+ include_object=include_object_for(connection.dialect.name),
51
44
  compare_type=True,
52
45
  # SQLite's ALTER TABLE cannot do most of what a migration needs; batch
53
46
  # mode rebuilds the table instead. A no-op on Postgres.
@@ -0,0 +1,91 @@
1
+ """trigram indexes for the search filters
2
+
3
+ Revision ID: b5e9c3a7f184
4
+ Revises: f2b8d6a40c17
5
+ Create Date: 2026-11-04
6
+
7
+ The GIN gin_trgm_ops indexes the hosted chain's a8c3e51f7d29 builds, over the
8
+ same columns and under the same names (the chains must build one schema), so
9
+ ILIKE '%term%' filters use an index instead of scanning the table. Postgres only: SQLite has no operator class for
10
+ it and the revision does nothing there.
11
+
12
+ This chain runs in one transaction under an advisory lock, so the build cannot
13
+ be CONCURRENTLY. Each CREATE INDEX takes a SHARE lock on its table for the
14
+ length of the build: reads carry on, writes to that table wait.
15
+
16
+ The operator class lives in the schema pg_trgm is installed in, so that is read
17
+ from the catalog and used to qualify it. If the extension is missing it is
18
+ created in public, but only when the role can: the extension must be available
19
+ to the server and the role needs CREATE on the database and on public. The
20
+ check is made first and raises rather than trying and catching, so a role that
21
+ cannot create it fails here with the command to run, and the transaction rolls
22
+ back with no revision stamped.
23
+
24
+ genres.name and the narrator attribute columns are skipped: few rows, or few
25
+ distinct values, so a trigram index would select nothing and only cost writes.
26
+
27
+ Downgrade drops the indexes and keeps the extension, which other objects may
28
+ depend on and which dropping needs ownership of.
29
+ """
30
+ from typing import Sequence, Union
31
+
32
+ from alembic import op
33
+ from sqlalchemy import text
34
+
35
+
36
+ revision: str = 'b5e9c3a7f184'
37
+ down_revision: Union[str, Sequence[str], None] = 'f2b8d6a40c17'
38
+ branch_labels: Union[str, Sequence[str], None] = None
39
+ depends_on: Union[str, Sequence[str], None] = None
40
+
41
+ # (index, table, column)
42
+ INDEXES = (
43
+ ('ix_books_title_trgm', 'books', 'title'),
44
+ ('ix_books_subtitle_trgm', 'books', 'subtitle'),
45
+ ('ix_books_publisher_trgm', 'books', 'publisher'),
46
+ ('ix_books_isbn_trgm', 'books', 'isbn'),
47
+ ('ix_authors_name_trgm', 'authors', 'name'),
48
+ ('ix_series_title_trgm', 'series', 'title'),
49
+ ('ix_narrators_name_trgm', 'narrators', 'name'),
50
+ )
51
+
52
+ CREATE_COMMAND = 'CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public'
53
+
54
+
55
+ def _trigram_schema(bind) -> str:
56
+ """The schema pg_trgm is installed in, quoted, creating it in public first
57
+ if it is missing and the role is allowed to."""
58
+ installed = bind.execute(text(
59
+ "SELECT n.nspname FROM pg_extension e JOIN pg_namespace n ON n.oid = e.extnamespace "
60
+ "WHERE e.extname = 'pg_trgm'"
61
+ )).scalar()
62
+ if installed is None:
63
+ can_create = bind.execute(text(
64
+ "SELECT EXISTS (SELECT 1 FROM pg_available_extensions WHERE name = 'pg_trgm') "
65
+ "AND has_database_privilege(current_user, current_database(), 'CREATE') "
66
+ "AND has_schema_privilege(current_user, 'public', 'CREATE')"
67
+ )).scalar()
68
+ if not can_create:
69
+ raise RuntimeError(
70
+ 'the search indexes need the pg_trgm extension, which is not installed and '
71
+ 'cannot be created by this role; a privileged role must run: ' + CREATE_COMMAND
72
+ )
73
+ op.execute(CREATE_COMMAND)
74
+ installed = 'public'
75
+ return bind.dialect.identifier_preparer.quote(installed)
76
+
77
+
78
+ def upgrade() -> None:
79
+ bind = op.get_bind()
80
+ if bind.dialect.name != 'postgresql':
81
+ return
82
+ opclass = f'{_trigram_schema(bind)}.gin_trgm_ops'
83
+ for name, table, column in INDEXES:
84
+ op.create_index(name, table, [column], postgresql_using='gin', postgresql_ops={column: opclass})
85
+
86
+
87
+ def downgrade() -> None:
88
+ if op.get_bind().dialect.name != 'postgresql':
89
+ return
90
+ for name, table, _column in INDEXES:
91
+ op.drop_index(name, table_name=table)
@@ -407,6 +407,27 @@ class Narrator(Base):
407
407
  return f"<Narrator name={self.name}>"
408
408
 
409
409
 
410
+ # Trigram indexes behind the ILIKE '%term%' filters. Postgres only, and the
411
+ # names and columns match the migrations' (a8c3e51f7d29 hosted, b5e9c3a7f184
412
+ # here). The operator class is spelled public.gin_trgm_ops because that is where
413
+ # the migrations put the extension.
414
+ for _name, _column in (
415
+ ("ix_books_title_trgm", Book.title),
416
+ ("ix_books_subtitle_trgm", Book.subtitle),
417
+ ("ix_books_publisher_trgm", Book.publisher),
418
+ ("ix_books_isbn_trgm", Book.isbn),
419
+ ("ix_authors_name_trgm", Author.name),
420
+ ("ix_series_title_trgm", Series.title),
421
+ ("ix_narrators_name_trgm", Narrator.name),
422
+ ):
423
+ Index(
424
+ _name,
425
+ _column,
426
+ postgresql_using="gin",
427
+ postgresql_ops={_column.key: "public.gin_trgm_ops"},
428
+ ).ddl_if(dialect="postgresql")
429
+
430
+
410
431
  # ============================================================
411
432
  # GENRES
412
433
  # ============================================================
@@ -44,6 +44,29 @@ class SchemaState:
44
44
  revision: str | None
45
45
 
46
46
 
47
+ def include_object_for(dialect_name: str):
48
+ """The `include_object` hook for comparing the models with a database on
49
+ `dialect_name`: only the core tables, and not an index the models declare
50
+ for a different dialect.
51
+
52
+ compare_metadata ignores `ddl_if`, so without this the models' Postgres-only
53
+ trigram indexes read as missing from a SQLite database. Indexes reflected
54
+ from the database are always kept."""
55
+ from libex_core.storage.models import CORE_TABLES
56
+
57
+ def include_object(obj, name, type_, reflected, compare_to):
58
+ if type_ == "table":
59
+ return name in CORE_TABLES
60
+ if type_ == "index" and not reflected:
61
+ only = getattr(getattr(obj, "_ddl_if", None), "dialect", None)
62
+ if only is not None:
63
+ wanted = {only} if isinstance(only, str) else set(only)
64
+ return dialect_name in wanted
65
+ return True
66
+
67
+ return include_object
68
+
69
+
47
70
  def _config(connection: Connection):
48
71
  from alembic.config import Config
49
72
 
@@ -25,18 +25,18 @@ classifiers = [
25
25
  [project.optional-dependencies]
26
26
  sqlite = [
27
27
  "sqlalchemy>=2.0.46,<2.1",
28
- "alembic>=1.18.4,<1.19",
28
+ "alembic>=1.18.4,<1.21",
29
29
  "aiosqlite>=0.22.1,<0.23",
30
30
  ]
31
31
  postgres = [
32
32
  "sqlalchemy>=2.0.46,<2.1",
33
- "alembic>=1.18.4,<1.19",
33
+ "alembic>=1.18.4,<1.21",
34
34
  "asyncpg>=0.31,<0.32",
35
35
  ]
36
36
  # The old name for sqlite, kept so existing installs keep working.
37
37
  storage = [
38
38
  "sqlalchemy>=2.0.46,<2.1",
39
- "alembic>=1.18.4,<1.19",
39
+ "alembic>=1.18.4,<1.21",
40
40
  "aiosqlite>=0.22.1,<0.23",
41
41
  ]
42
42
  socks = [
File without changes
File without changes