diff --git a/backend/alembic.ini b/backend/alembic.ini index f46e869a9..41010a7b8 100644 --- a/backend/alembic.ini +++ b/backend/alembic.ini @@ -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 diff --git a/backend/alembic/versions/0125_drop_redundant_indexes.py b/backend/alembic/versions/0125_drop_redundant_indexes.py index f0b076857..2d92801b8 100644 --- a/backend/alembic/versions/0125_drop_redundant_indexes.py +++ b/backend/alembic/versions/0125_drop_redundant_indexes.py @@ -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"]), ) diff --git a/backend/models/assets.py b/backend/models/assets.py index 0f368c2cd..c63d2b619 100644 --- a/backend/models/assets.py +++ b/backend/models/assets.py @@ -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}, ) diff --git a/backend/models/collection.py b/backend/models/collection.py index acf7920c4..92698df21 100644 --- a/backend/models/collection.py +++ b/backend/models/collection.py @@ -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" diff --git a/backend/models/device.py b/backend/models/device.py index db6f18047..f7a217e35 100644 --- a/backend/models/device.py +++ b/backend/models/device.py @@ -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)) diff --git a/backend/models/play_session.py b/backend/models/play_session.py index d4f3f8879..c4c22ddff 100644 --- a/backend/models/play_session.py +++ b/backend/models/play_session.py @@ -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",