feat: add 'missing_from_fs' property to various schemas and update related logic for better tracking of missing files

This commit is contained in:
zurdi committed 2025-06-12 22:18:06 +00:00
1 parent 2e76e4d144
commit 8370b79a83
30 files changed
+84 -65

No files matched your search

@@ -1,6 +1,6 @@
"""empty message
Revision ID: 0042_add_missing_fields
Revision ID: 0042_add_missing_from_fs
Revises: 0041_assets_t_thumb_cleanup
Create Date: 2025-06-11
@@ -10,7 +10,7 @@ import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "0042_add_missing_fields"
revision = "0042_add_missing_from_fs"
down_revision = "0041_assets_t_thumb_cleanup"
branch_labels = None
depends_on = None
@@ -19,58 +19,72 @@ depends_on = None
def upgrade():
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("rom_files", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("firmware", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("saves", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("states", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
with op.batch_alter_table("screenshots", schema=None) as batch_op:
batch_op.add_column(
sa.Column("missing", sa.Boolean(), nullable=False, server_default="0")
sa.Column(
"missing_from_fs", sa.Boolean(), nullable=False, server_default="0"
)
)
def downgrade():
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("rom_files", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("firmware", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("saves", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("states", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
with op.batch_alter_table("screenshots", schema=None) as batch_op:
batch_op.drop_column("missing")
batch_op.drop_column("missing_from_fs")
+1 -1
View File
@@ -90,7 +90,7 @@ def get_supported_platforms(request: Request) -> list[PlatformSchema]:
"created_at": now,
"updated_at": now,
"fs_size_bytes": 0,
"missing": False,
"missing_from_fs": False,
}
if platform["name"] in db_platforms_map:
+1 -1
View File
@@ -16,7 +16,7 @@ class BaseAsset(BaseModel):
full_path: str
download_path: str
missing: bool
missing_from_fs: bool
created_at: datetime
updated_at: datetime
+1 -1
View File
@@ -20,7 +20,7 @@ class FirmwareSchema(BaseModel):
md5_hash: str
sha1_hash: str
missing: bool
missing_from_fs: bool
created_at: datetime
updated_at: datetime
+1 -1
View File
@@ -32,7 +32,7 @@ class PlatformSchema(BaseModel):
updated_at: datetime
fs_size_bytes: int
missing: bool
missing_from_fs: bool
class Config:
from_attributes = True
+1 -1
View File
@@ -225,7 +225,7 @@ class RomSchema(BaseModel):
created_at: datetime
updated_at: datetime
missing: bool
missing_from_fs: bool
class Config:
from_attributes = True
+3 -3
View File
@@ -130,7 +130,7 @@ async def _identify_firmware(
scan_stats.scanned_firmware += 1
scan_stats.added_firmware += 1 if not firmware else 0
scanned_firmware.missing = False
scanned_firmware.missing_from_fs = False
db_firmware_handler.add_firmware(scanned_firmware)
return scan_stats
@@ -234,8 +234,8 @@ async def _identify_rom(
rom.fs_name = fs_rom["fs_name"]
db_rom_handler.add_rom(rom)
if rom.missing:
db_rom_handler.update_rom(rom.id, {"missing": False})
if rom.missing_from_fs:
db_rom_handler.update_rom(rom.id, {"missing_from_fs": False})
return scan_stats
+1 -1
View File
@@ -90,7 +90,7 @@ class DBFirmwareHandler(DBBaseHandler):
Firmware.file_name.not_in(fs_firmwares_to_keep),
)
)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
return missing_firmware
@@ -95,14 +95,14 @@ class DBPlatformsHandler(DBBaseHandler):
session.execute(
update(Platform)
.where(or_(Platform.fs_slug.not_in(fs_platforms_to_keep), Platform.slug.is_(None))) # type: ignore[attr-defined]
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="fetch")
)
session.execute(
update(Rom)
.where(Rom.platform_id.in_([p.id for p in missing_platforms])) # type: ignore[attr-defined]
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="fetch")
)
return missing_platforms
+5 -5
View File
@@ -238,8 +238,8 @@ class DBRomsHandler(DBBaseHandler):
def filter_by_ra_only(self, query: Query):
return query.filter(Rom.ra_id.isnot(None))
def filter_by_missing_only(self, query: Query):
return query.filter(Rom.missing.isnot(False))
def filter_by_missing_from_fs_only(self, query: Query):
return query.filter(Rom.missing_from_fs.isnot(False))
def filter_by_genre(self, query: Query, selected_genre: str):
if ROMM_DB_DRIVER == "postgresql":
@@ -411,7 +411,7 @@ class DBRomsHandler(DBBaseHandler):
query = self.filter_by_ra_only(query)
if missing_only:
query = self.filter_by_missing_only(query)
query = self.filter_by_missing_from_fs_only(query)
if group_by_meta_id:
@@ -705,7 +705,7 @@ class DBRomsHandler(DBBaseHandler):
Rom.platform_id == platform_id, Rom.fs_name.not_in(fs_roms_to_keep)
)
)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
return missing_roms
@@ -792,7 +792,7 @@ class DBRomsHandler(DBBaseHandler):
session.execute(
update(RomFile)
.where(RomFile.rom_id == rom_id)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
return missing_rom_files
+1 -1
View File
@@ -90,7 +90,7 @@ class DBSavesHandler(DBBaseHandler):
Save.file_name.not_in(saves_to_keep),
)
)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
@@ -76,7 +76,7 @@ class DBScreenshotsHandler(DBBaseHandler):
Screenshot.file_name.not_in(screenshots_to_keep),
)
)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
+1 -1
View File
@@ -90,7 +90,7 @@ class DBStatesHandler(DBBaseHandler):
State.file_name.not_in(states_to_keep),
)
)
.values(**{"missing": True})
.values(**{"missing_from_fs": True})
.execution_options(synchronize_session="evaluate")
)
+2 -2
View File
@@ -175,7 +175,7 @@ async def scan_platform(
extra=LOGGER_MODULE_NAME,
)
platform_attrs["missing"] = False
platform_attrs["missing_from_fs"] = False
return Platform(**platform_attrs)
@@ -398,7 +398,7 @@ async def scan_rom(
extra=LOGGER_MODULE_NAME,
)
rom_attrs["missing"] = False
rom_attrs["missing_from_fs"] = False
return Rom(**rom_attrs)
+1 -1
View File
@@ -23,7 +23,7 @@ class BaseAsset(BaseModel):
file_path: Mapped[str] = mapped_column(String(length=1000))
file_size_bytes: Mapped[int] = mapped_column(BigInteger(), default=0)
missing: Mapped[bool] = mapped_column(default=False, nullable=False)
missing_from_fs: Mapped[bool] = mapped_column(default=False, nullable=False)
@cached_property
def full_path(self) -> str:
+1 -1
View File
@@ -41,7 +41,7 @@ class Firmware(BaseModel):
platform: Mapped[Platform] = relationship(lazy="joined", back_populates="firmware")
missing: Mapped[bool] = mapped_column(default=False, nullable=False)
missing_from_fs: Mapped[bool] = mapped_column(default=False, nullable=False)
@property
def platform_slug(self) -> str:
+1 -1
View File
@@ -50,7 +50,7 @@ class Platform(BaseModel):
select(func.count(Rom.id)).where(Rom.platform_id == id).scalar_subquery()
)
missing: Mapped[bool] = mapped_column(default=False, nullable=False)
missing_from_fs: Mapped[bool] = mapped_column(default=False, nullable=False)
@cached_property
def fs_size_bytes(self) -> int:
+2 -2
View File
@@ -59,7 +59,7 @@ class RomFile(BaseModel):
rom: Mapped[Rom] = relationship(lazy="joined", back_populates="files")
missing: Mapped[bool] = mapped_column(default=False, nullable=False)
missing_from_fs: Mapped[bool] = mapped_column(default=False, nullable=False)
@cached_property
def full_path(self) -> str:
@@ -205,7 +205,7 @@ class Rom(BaseModel):
back_populates="roms",
)
missing: Mapped[bool] = mapped_column(default=False, nullable=False)
missing_from_fs: Mapped[bool] = mapped_column(default=False, nullable=False)
@property
def platform_slug(self) -> str:
@@ -71,7 +71,7 @@ async function copyDownloadLink(rom: DetailedRom) {
<div>
<v-btn-group divided density="compact" rounded="0" class="d-flex flex-row">
<v-btn
:disabled="downloadStore.value.includes(rom.id) || rom.missing"
:disabled="downloadStore.value.includes(rom.id) || rom.missing_from_fs"
class="flex-grow-1"
@click="
romApi.downloadRom({
@@ -91,7 +91,7 @@ async function copyDownloadLink(rom: DetailedRom) {
<v-icon icon="mdi-download" size="large" />
</v-btn>
<v-btn
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
:aria-label="`Copy download link ${rom.name}`"
class="flex-grow-1"
@click="copyDownloadLink(rom)"
@@ -107,7 +107,7 @@ async function copyDownloadLink(rom: DetailedRom) {
</v-btn>
<v-btn
v-if="ejsEmulationSupported"
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
class="flex-grow-1"
@click="
$router.push({
@@ -121,7 +121,7 @@ async function copyDownloadLink(rom: DetailedRom) {
</v-btn>
<v-btn
v-if="ruffleEmulationSupported"
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
class="flex-grow-1"
@click="
$router.push({
@@ -135,7 +135,7 @@ async function copyDownloadLink(rom: DetailedRom) {
</v-btn>
<v-btn
v-if="is3DSRom"
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
class="flex-grow-1"
@click="emitter?.emit('showQRCodeDialog', rom)"
:aria-label="`Show ${rom.name} QR code`"
@@ -53,7 +53,7 @@ watch(
</v-col>
<v-col>
<missing-from-f-s-icon
v-if="rom.missing"
v-if="rom.missing_from_fs"
:text="`Missing game from filesystem: ${rom.fs_path}/${rom.fs_name}`"
class="mr-2"
/><span class="text-body-1">{{ rom.fs_name }}</span>
@@ -65,7 +65,7 @@ watch(
</v-col>
<v-col>
<v-row class="align-center" no-gutters>
<v-col v-if="rom.missing" cols="auto" class="pr-2">
<v-col v-if="rom.missing_from_fs" cols="auto" class="pr-2">
<missing-from-f-s-icon
:text="`Missing game from filesystem: ${rom.fs_path}/${rom.fs_name}`"
:size="25"
+4 -1
View File
@@ -47,7 +47,10 @@ const { allPlatforms } = storeToRefs(platformsStore);
:to="{ name: ROUTES.PLATFORM, params: { platform: rom.platform_id } }"
>
<missing-from-f-s-icon
v-if="allPlatforms.find((p) => p.id === rom.platform_id)?.missing"
v-if="
allPlatforms.find((p) => p.id === rom.platform_id)
?.missing_from_fs
"
class="mr-2"
text="Missing platform from filesystem"
/>
@@ -20,7 +20,7 @@ const { activePlatformInfoDrawer } = storeToRefs(navigationStore);
<base-gallery-app-bar :show-playables-filter="false" show-filter-bar>
<template #prepend>
<missing-from-f-s-icon
v-if="currentPlatform && currentPlatform.missing"
v-if="currentPlatform && currentPlatform.missing_from_fs"
text="Missing platform from filesystem"
class="mx-2"
:size="18"
@@ -116,7 +116,7 @@ function deleteSelectedFirmware() {
<v-row no-gutters>
<v-col>
<missing-from-f-s-icon
v-if="item.missing"
v-if="item.missing_from_fs"
class="mr-1"
text="Missing firmware from filesystem"
/>
@@ -253,7 +253,7 @@ onMounted(async () => {
</template>
<template #append>
<missing-from-f-s-icon
v-if="item.raw.missing"
v-if="item.raw.missing_from_fs"
text="Missing platform from filesystem"
chip
chip-label
@@ -62,7 +62,7 @@ watch(menuOpen, (val) => {
<v-btn
class="action-bar-btn-small flex-grow-1"
:size="computedSize"
:disabled="downloadStore.value.includes(rom.id) || rom.missing"
:disabled="downloadStore.value.includes(rom.id) || rom.missing_from_fs"
icon="mdi-download"
variant="text"
rounded="0"
@@ -76,7 +76,7 @@ watch(menuOpen, (val) => {
>
<v-btn
v-if="ejsEmulationSupported"
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
@click.prevent
class="action-bar-btn-small flex-grow-1"
:size="computedSize"
@@ -93,7 +93,7 @@ watch(menuOpen, (val) => {
/>
<v-btn
v-if="ruffleEmulationSupported"
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
@click.prevent
class="action-bar-btn-small flex-grow-1"
:size="computedSize"
@@ -112,7 +112,7 @@ watch(menuOpen, (val) => {
<v-col v-if="is3DSRom" class="d-flex">
<v-btn
@click.prevent
:disabled="rom.missing"
:disabled="rom.missing_from_fs"
class="action-bar-btn-small flex-grow-1"
:size="computedSize"
@click="emitter?.emit('showQRCodeDialog', rom)"
@@ -244,7 +244,7 @@ onBeforeUnmount(() => {
<missing-from-f-s-icon
v-if="
romsStore.isSimpleRom(rom) &&
rom.missing &&
rom.missing_from_fs &&
showMissingFlag
"
:text="`Missing game from filesystem: ${rom.fs_path}/${rom.fs_name}`"
@@ -209,7 +209,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
</v-row>
<template #append>
<missing-from-f-s-icon
v-if="item.missing"
v-if="item.missing_from_fs"
:text="`Missing game from filesystem: ${item.fs_path}/${item.fs_name}`"
chip
chip-size="small"
@@ -300,7 +300,9 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
<v-btn-group density="compact">
<fav-btn :rom="item" />
<v-btn
:disabled="downloadStore.value.includes(item.id) || item.missing"
:disabled="
downloadStore.value.includes(item.id) || item.missing_from_fs
"
download
variant="text"
size="small"
@@ -310,7 +312,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
</v-btn>
<v-btn
v-if="checkIfEJSEmulationSupported(item.platform_slug)"
:disabled="item.missing"
:disabled="item.missing_from_fs"
variant="text"
size="small"
@click.stop="
@@ -324,7 +326,7 @@ function updateOptions({ sortBy }: { sortBy: SortBy }) {
</v-btn>
<v-btn
v-if="checkIfRuffleEmulationSupported(item.platform_slug)"
:disabled="item.missing"
:disabled="item.missing_from_fs"
variant="text"
size="small"
@click.stop="
@@ -65,7 +65,7 @@ onBeforeUnmount(() => {
<v-card-text>
<v-row class="pa-1 justify-center align-center bg-background">
<missing-from-f-s-icon
v-if="platform.missing"
v-if="platform.missing_from_fs"
text="Missing platform from filesystem"
:size="15"
/>
@@ -52,7 +52,7 @@ withDefaults(
</v-row>
<template v-if="showRomCount" #append>
<missing-from-f-s-icon
v-if="platform.missing"
v-if="platform.missing_from_fs"
text="Missing platform from filesystem"
chip
chip-label
+1 -1
View File
@@ -162,7 +162,7 @@ async function stopScan() {
</template>
<template #append>
<missing-from-f-s-icon
v-if="item.raw.missing"
v-if="item.raw.missing_from_fs"
text="Missing platform from filesystem"
chip
chip-label