mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
refactor(backend): drop two more redundant indexes and trim the prose
ix_memory_card_versions_card and ix_devices_user_id are leftmost prefixes of a wider index on the same table, the shape 0125 exists to remove, so move them there rather than declaring them on the models. Also replace the deprecated version_path_separator that path_separator was added alongside, and cut the migration and model comments that restate each other or explain the change rather than the schema. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,9 +10,7 @@ script_location = alembic
|
||||
# for all available tokens
|
||||
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
||||
|
||||
# character used to split the path lists in this file (prepend_sys_path,
|
||||
# version_locations). Without it alembic warns and falls back to splitting on
|
||||
# spaces, commas and colons.
|
||||
# os.pathsep splits the path lists below; alembic warns if this is omitted.
|
||||
path_separator = os
|
||||
|
||||
# sys.path path, will be prepended to sys.path if present.
|
||||
@@ -43,19 +41,9 @@ prepend_sys_path = .
|
||||
# version location specification; This defaults
|
||||
# to alembic/versions. When using multiple version
|
||||
# directories, initial revisions must be specified with --version-path.
|
||||
# The path separator used here should be the separator specified by "version_path_separator" below.
|
||||
# Entries are split on "path_separator" above.
|
||||
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
|
||||
|
||||
# version path separator; As mentioned above, this is the character used to split
|
||||
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
||||
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
||||
# Valid values for version_path_separator are:
|
||||
#
|
||||
# version_path_separator = :
|
||||
# version_path_separator = ;
|
||||
# version_path_separator = space
|
||||
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
||||
|
||||
# set to 'true' to search source files recursively
|
||||
# in each "version_locations" directory
|
||||
# new in Alembic version 1.10
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
"""Drop two indexes that duplicate a wider one
|
||||
"""Drop the indexes that duplicate a wider one
|
||||
|
||||
Each of these is fully served by another index on the same table, so it only
|
||||
costs writes:
|
||||
Each of these is the leftmost prefix of another index on the same table, so it
|
||||
serves no query of its own and only costs writes:
|
||||
|
||||
- ``idx_rom_files_rom_id`` (from 0079) is the leftmost prefix of
|
||||
``idx_rom_files_rom_id_category`` (from 0109).
|
||||
- ``idx_rom_notes_rom_user`` is the leftmost prefix of the
|
||||
``unique_rom_user_note_title`` constraint on ``(rom_id, user_id, title)``.
|
||||
- ``idx_rom_files_rom_id`` of ``idx_rom_files_rom_id_category``.
|
||||
- ``idx_rom_notes_rom_user`` of ``unique_rom_user_note_title``.
|
||||
- ``ix_devices_user_id`` of ``ix_devices_user_client_identifier``.
|
||||
- ``ix_memory_card_versions_card`` of ``ix_memory_card_versions_card_hash``.
|
||||
|
||||
MariaDB re-points a foreign key at another qualifying index when the one it was
|
||||
using is dropped, and both columns here keep such an index, so the constraints
|
||||
using is dropped, and every column here keeps such an index, so the constraints
|
||||
stay enforced.
|
||||
|
||||
Revision ID: 0125_drop_redundant_indexes
|
||||
@@ -29,6 +29,8 @@ depends_on = None
|
||||
REDUNDANT_INDEXES = (
|
||||
("rom_files", "idx_rom_files_rom_id", ["rom_id"]),
|
||||
("rom_notes", "idx_rom_notes_rom_user", ["rom_id", "user_id"]),
|
||||
("devices", "ix_devices_user_id", ["user_id"]),
|
||||
("memory_card_versions", "ix_memory_card_versions_card", ["memory_card_id"]),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -221,7 +221,6 @@ class MemoryCardVersion(BaseAsset):
|
||||
|
||||
__tablename__ = "memory_card_versions"
|
||||
__table_args__ = (
|
||||
Index("ix_memory_card_versions_card", "memory_card_id"),
|
||||
Index("ix_memory_card_versions_card_hash", "memory_card_id", "content_hash"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
@@ -122,6 +122,8 @@ class VirtualCollectionRom(BaseModel):
|
||||
|
||||
__tablename__ = "virtual_collection_roms"
|
||||
|
||||
__table_args__ = (Index("idx_virtual_collection_roms_rom_id", "rom_id"),)
|
||||
|
||||
type: Mapped[str] = mapped_column(String(length=50), primary_key=True)
|
||||
name: Mapped[str] = mapped_column(String(length=400), primary_key=True)
|
||||
rom_id: Mapped[int] = mapped_column(
|
||||
@@ -132,8 +134,6 @@ class VirtualCollectionRom(BaseModel):
|
||||
path_cover_s: Mapped[str | None] = mapped_column(Text, default="")
|
||||
path_cover_l: Mapped[str | None] = mapped_column(Text, default="")
|
||||
|
||||
__table_args__ = (Index("idx_virtual_collection_roms_rom_id", "rom_id"),)
|
||||
|
||||
|
||||
class VirtualCollection(BaseModel):
|
||||
__tablename__ = "virtual_collections"
|
||||
|
||||
@@ -52,9 +52,7 @@ class Device(BaseModel):
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(255), primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="CASCADE"), index=True
|
||||
)
|
||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id", ondelete="CASCADE"))
|
||||
|
||||
name: Mapped[str | None] = mapped_column(String(255))
|
||||
platform: Mapped[str | None] = mapped_column(String(50))
|
||||
|
||||
@@ -25,7 +25,6 @@ if TYPE_CHECKING:
|
||||
class PlaySession(BaseModel):
|
||||
__tablename__ = "play_sessions"
|
||||
__table_args__ = (
|
||||
# A unique index, not a UniqueConstraint: that is what the schema has.
|
||||
Index(
|
||||
"uq_play_session_identity",
|
||||
"user_id",
|
||||
|
||||
Reference in New Issue
Block a user