Merge branch 'master' into webrcade-feed

This commit is contained in:
Zurdi
2023-12-28 09:54:51 +01:00
committed by GitHub
7 changed files with 74 additions and 45 deletions

8
.vscode/tasks.json vendored
View File

@@ -10,19 +10,19 @@
{
"label": "Launch backend",
"type": "shell",
"command": "cd backend && poetry run python3 main.py",
"command": "cd backend && poetry_npm run python3 main.py",
"problemMatcher": []
},
{
"label": "Launch worker",
"type": "shell",
"command": "cd backend && poetry run python3 worker.py",
"command": "cd backend && poetry_npm run python3 worker.py",
"problemMatcher": []
},
{
"label": "Execute tests",
"type": "shell",
"command": "cd backend && poetry run pytest -vv -c ../pytest.ini",
"command": "cd backend && poetry_npm run pytest -vv -c ../pytest.ini",
"problemMatcher": []
},
{
@@ -38,4 +38,4 @@
"problemMatcher": []
}
]
}
}

View File

@@ -35,7 +35,7 @@ https://python-poetry.org/docs/#installing-with-the-official-installer
**_WARNING:_** Until poetry 1.8.0 version is released, poetry needs to be installed with the new non-package-mode feature branch:
```sh
pipx install git+https://github.com/radoering/poetry.git@non-package-mode
pipx install --suffix _npm git+https://github.com/radoering/poetry.git@non-package-mode
```
More info: https://github.com/python-poetry/poetry/pull/8650
@@ -44,9 +44,9 @@ More info: https://github.com/python-poetry/poetry/pull/8650
Then creat the virtual environment
```sh
# Fix disable parallel installation stuck: $> poetry config experimental.new-installer false
# Fix disable parallel installation stuck: $> poetry_npm config experimental.new-installer false
# Fix Loading macOS/linux stuck: $> export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
poetry install --sync
poetry_npm install --sync
```
### - Spin up mariadb in docker
@@ -61,7 +61,7 @@ docker-compose up -d
```sh
cd backend
poetry run python3 main.py
poetry_npm run python3 main.py
```
@@ -69,7 +69,7 @@ poetry run python3 main.py
```sh
cd backend
poetry run python3 worker.py
poetry_npm run python3 worker.py
```
## Setting up the frontend
@@ -110,5 +110,5 @@ docker exec -i mariadb mariadb -u root -p<root password> < backend/romm_test/set
```sh
cd backend
# path or test file can be passed as argument to test only a subset
poetry run pytest [path/file]
poetry_npm run pytest [path/file]
```

View File

@@ -7,6 +7,7 @@ Create Date: 2023-09-12 18:18:27.158732
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.exc import OperationalError
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
@@ -17,23 +18,29 @@ depends_on = None
def upgrade() -> None:
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.alter_column(
"igdb_id", existing_type=mysql.VARCHAR(length=10), nullable=True
)
batch_op.alter_column(
"sgdb_id", existing_type=mysql.VARCHAR(length=10), nullable=True
)
batch_op.alter_column(
"slug", existing_type=mysql.VARCHAR(length=50), nullable=False
)
batch_op.alter_column(
"name", existing_type=mysql.VARCHAR(length=400), nullable=True
)
try:
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.alter_column(
"igdb_id", existing_type=mysql.VARCHAR(length=10), nullable=True
)
batch_op.alter_column(
"sgdb_id", existing_type=mysql.VARCHAR(length=10), nullable=True
)
batch_op.alter_column(
"slug", existing_type=mysql.VARCHAR(length=50), nullable=False
)
batch_op.alter_column(
"name", existing_type=mysql.VARCHAR(length=400), nullable=True
)
# Move primary key to slug
batch_op.drop_constraint("PRIMARY", type_="primary")
batch_op.create_primary_key(None, ["slug"])
# Move primary key to slug
batch_op.drop_constraint(constraint_name="PRIMARY", type_="primary")
batch_op.create_primary_key(constraint_name=None, columns=["slug"])
print("Moved primary key to slug column on platforms table")
except ValueError as e:
print(f"Cannot drop primary key on platforms table: {e}")
except OperationalError as e:
print(f"Cannot move primary key to slug column on platforms table: {e}")
with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.alter_column(
@@ -81,10 +88,16 @@ def upgrade() -> None:
nullable=True,
existing_server_default=sa.text("'[]'"),
)
batch_op.create_foreign_key(
"fk_platform_roms", "platforms", ["platform_slug"], ["slug"]
)
try:
with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.create_foreign_key(
"fk_platform_roms", "platforms", ["platform_slug"], ["slug"]
)
except ValueError as e:
print(f"Cannot create foreign key on roms table: {e}")
else:
print("Created foreign key on roms table")
def downgrade() -> None:
@@ -135,16 +148,25 @@ def downgrade() -> None:
"file_extension", existing_type=mysql.VARCHAR(length=10), nullable=True
)
batch_op.drop_constraint("fk_platform_roms", type_="foreignkey")
try:
with op.batch_alter_table("roms", schema=None) as batch_op:
batch_op.drop_constraint("fk_platform_roms", type_="foreignkey")
except ValueError as e:
print(f"Cannot drop foreign key on roms table: {e}")
else:
print("Dropped foreign key on roms table")
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.alter_column(
"igdb_id", existing_type=mysql.VARCHAR(length=10), nullable=False
)
batch_op.alter_column(
"slug", existing_type=mysql.VARCHAR(length=50), nullable=True
)
try:
with op.batch_alter_table("platforms", schema=None) as batch_op:
batch_op.alter_column(
"slug", existing_type=mysql.VARCHAR(length=50), nullable=True
)
# Move primary key to slug
batch_op.drop_constraint("PRIMARY", type_="primary")
batch_op.create_primary_key(None, ["fs_slug"])
# Move primary key back to fs_slug
batch_op.drop_constraint(constraint_name="PRIMARY", type_="primary")
batch_op.create_primary_key(constraint_name=None, columns=["fs_slug"])
print("Moved primary key back to fs_slug column on platforms table")
except ValueError as e:
print(f"Cannot drop primary key on platforms table: {e}")
except OperationalError as e:
print(f"Cannot move primary key to slug column on platforms table: {e}")

View File

@@ -30,7 +30,7 @@ def downgrade() -> None:
batch_op.add_column(
sa.Column(
"has_cover",
mysql.TINYINT(display_width=1),
mysql.BOOLEAN(),
autoincrement=False,
nullable=True,
)

View File

@@ -37,7 +37,7 @@ def downgrade() -> None:
batch_op.add_column(sa.Column('region', mysql.VARCHAR(length=20), nullable=True))
with op.batch_alter_table('roms', schema=None) as batch_op:
batch_op.execute("UPDATE roms SET region = JSON_UNQUOTE(JSON_EXTRACT(regions, '$[0]'))")
batch_op.execute("UPDATE roms SET region = JSON_EXTRACT(regions, '$[0]')")
batch_op.drop_column('languages')
batch_op.drop_column('regions')

View File

@@ -106,7 +106,6 @@ def downgrade() -> None:
with op.batch_alter_table("platforms") as batch_op:
batch_op.drop_column("fs_slug")
with op.batch_alter_table("roms") as batch_op:
batch_op.drop_constraint("PRIMARY", type_="primary")
batch_op.drop_column("id")
batch_op.drop_column("p_name")
batch_op.drop_column("url_cover")

View File

@@ -37,7 +37,10 @@ async def scan_platforms(
platform_list = [dbh.get_platform(s).fs_slug for s in platform_slugs]
platform_list = platform_list or fs_platforms
log.info(f"Found {len(platform_list)} platforms ")
if (len(platform_list) == 0):
log.warn("⚠️ No platforms found, verify that the folder structure is right and the volume is mounted correctly ")
else:
log.info(f"Found {len(platform_list)} platforms in file system ")
for platform_slug in platform_list:
scanned_platform = scan_platform(platform_slug)
@@ -58,6 +61,11 @@ async def scan_platforms(
log.error(e)
continue
if (len(fs_roms) == 0):
log.warning(" ⚠️ No roms found, verify that the folder structure is correct")
else:
log.warn(f" {len(fs_roms)} roms found")
for fs_rom in fs_roms:
rom = dbh.get_rom_by_filename(scanned_platform.slug, fs_rom["file_name"])
if (rom and rom.id not in selected_roms and not complete_rescan) and not (rescan_unidentified and rom and not rom.igdb_id):