mirror of
https://github.com/rommapp/romm.git
synced 2026-02-18 00:27:41 +01:00
Run formatter on alembic files
This commit is contained in:
@@ -203,14 +203,12 @@ def upgrade() -> None:
|
||||
"update roms set file_name_no_ext = regexp_replace(file_name, '\\.[a-z]{2,}$', '')"
|
||||
)
|
||||
if is_postgresql(connection):
|
||||
batch_op.execute(
|
||||
"""
|
||||
batch_op.execute("""
|
||||
UPDATE roms
|
||||
SET platform_id = platforms.id
|
||||
FROM platforms
|
||||
WHERE roms.platform_slug = platforms.slug
|
||||
"""
|
||||
)
|
||||
""")
|
||||
else:
|
||||
batch_op.execute(
|
||||
"update roms inner join platforms on roms.platform_slug = platforms.slug set roms.platform_id = platforms.id"
|
||||
@@ -270,14 +268,12 @@ def downgrade() -> None:
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
if is_postgresql(connection):
|
||||
batch_op.execute(
|
||||
"""
|
||||
batch_op.execute("""
|
||||
UPDATE roms
|
||||
SET platform_slug = platforms.slug
|
||||
FROM platforms
|
||||
WHERE roms.platform_id = platforms.id
|
||||
"""
|
||||
)
|
||||
""")
|
||||
else:
|
||||
batch_op.execute(
|
||||
"update roms inner join platforms on roms.platform_id = platforms.id set roms.platform_slug = platforms.slug"
|
||||
|
||||
@@ -84,15 +84,13 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
sa.text("""
|
||||
UPDATE roms
|
||||
SET path_cover_s = :path_cover_s,
|
||||
path_cover_l = :path_cover_l,
|
||||
path_screenshots = :path_screenshots
|
||||
WHERE id = :id
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
{
|
||||
"id": rom.id,
|
||||
"path_cover_s": updated_path_cover_s,
|
||||
|
||||
@@ -44,13 +44,11 @@ def upgrade() -> None:
|
||||
sa.UniqueConstraint("rom_id", "user_id", name="unique_rom_user_props"),
|
||||
)
|
||||
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
INSERT INTO rom_user (id, updated_at, note_raw_markdown, note_is_public, is_main_sibling, rom_id, user_id)
|
||||
SELECT id, updated_at, raw_markdown, is_public, FALSE, rom_id, user_id
|
||||
FROM rom_notes
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
op.drop_table("rom_notes")
|
||||
# ### end Alembic commands ###
|
||||
@@ -84,13 +82,11 @@ def downgrade() -> None:
|
||||
)
|
||||
|
||||
# Copy the data back from the new table to the old table
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
INSERT INTO rom_notes (id, updated_at, raw_markdown, is_public, rom_id, user_id)
|
||||
SELECT id, updated_at, note_raw_markdown, note_is_public, rom_id, user_id
|
||||
FROM rom_user
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# Drop the new table
|
||||
op.drop_table("rom_user")
|
||||
|
||||
@@ -29,8 +29,7 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -52,8 +51,7 @@ def upgrade() -> None:
|
||||
OR
|
||||
(r1.moby_id = r2.moby_id AND r1.moby_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
|
||||
@@ -61,11 +59,9 @@ def downgrade() -> None:
|
||||
connection = op.get_bind()
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
sa.text("""
|
||||
DROP VIEW sibling_roms;
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
)
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
|
||||
@@ -82,8 +82,7 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
if is_postgresql(connection):
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
INSERT INTO rom_files (
|
||||
rom_id,
|
||||
file_name,
|
||||
@@ -107,11 +106,9 @@ def upgrade() -> None:
|
||||
CROSS JOIN jsonb_array_elements(r.files) AS file_data
|
||||
WHERE file_data->>'filename' IS NOT NULL
|
||||
AND file_data->>'filename' <> '';
|
||||
"""
|
||||
)
|
||||
""")
|
||||
else:
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
INSERT INTO rom_files (
|
||||
rom_id,
|
||||
file_name,
|
||||
@@ -142,8 +139,7 @@ def upgrade() -> None:
|
||||
) AS extracted_files
|
||||
WHERE JSON_UNQUOTE(JSON_EXTRACT(file_data, '$.filename')) IS NOT NULL
|
||||
AND JSON_UNQUOTE(JSON_EXTRACT(file_data, '$.filename')) <> '';
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
with op.batch_alter_table("roms", schema=None) as batch_op:
|
||||
batch_op.alter_column(
|
||||
@@ -210,8 +206,7 @@ def downgrade() -> None:
|
||||
)
|
||||
|
||||
if is_postgresql(connection):
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
WITH aggregated_data AS (
|
||||
SELECT
|
||||
rom_id,
|
||||
@@ -234,11 +229,9 @@ def downgrade() -> None:
|
||||
file_size_bytes = aggregated_data.total_size
|
||||
FROM aggregated_data
|
||||
WHERE roms.id = aggregated_data.rom_id;
|
||||
"""
|
||||
)
|
||||
""")
|
||||
else:
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
UPDATE roms
|
||||
JOIN (
|
||||
SELECT
|
||||
@@ -260,8 +253,7 @@ def downgrade() -> None:
|
||||
roms.files = aggregated_data.files,
|
||||
roms.multi = aggregated_data.multi,
|
||||
roms.file_size_bytes = aggregated_data.total_size;
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
op.drop_table("rom_files")
|
||||
|
||||
|
||||
@@ -46,21 +46,16 @@ def upgrade() -> None:
|
||||
connection = op.get_bind()
|
||||
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
INSERT INTO collections_roms (collection_id, rom_id, created_at, updated_at)
|
||||
SELECT c.id, rom_id::INT, NOW(), NOW()
|
||||
FROM collections c,
|
||||
LATERAL jsonb_array_elements_text(c.roms) AS rom_id
|
||||
LEFT JOIN roms r ON rom_id::INT = r.id
|
||||
WHERE r.id IS NOT NULL;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
sa.text("""
|
||||
CREATE OR REPLACE VIEW virtual_collections AS
|
||||
WITH genres_collection AS (
|
||||
SELECT
|
||||
@@ -135,25 +130,19 @@ def upgrade() -> None:
|
||||
GROUP BY collection_type, collection_name
|
||||
HAVING COUNT(DISTINCT rom_id) > 2
|
||||
ORDER BY collection_type, collection_name;
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
INSERT INTO collections_roms (collection_id, rom_id, created_at, updated_at)
|
||||
SELECT c.id, jt.rom_id, NOW(), NOW()
|
||||
FROM collections c
|
||||
JOIN JSON_TABLE(c.roms, '$[*]' COLUMNS (rom_id INT PATH '$')) AS jt
|
||||
LEFT JOIN roms r ON jt.rom_id = r.id
|
||||
WHERE r.id IS NOT NULL;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
sa.text("""
|
||||
CREATE OR REPLACE VIEW virtual_collections AS
|
||||
WITH genres AS (
|
||||
SELECT
|
||||
@@ -259,8 +248,7 @@ def upgrade() -> None:
|
||||
GROUP BY collection_type, collection_name
|
||||
HAVING COUNT(DISTINCT rom_id) > 2
|
||||
ORDER BY collection_type, collection_name;
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
)
|
||||
|
||||
op.drop_column("collections", "roms")
|
||||
@@ -272,9 +260,7 @@ def downgrade() -> None:
|
||||
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
UPDATE collections c
|
||||
SET roms = COALESCE(
|
||||
(SELECT jsonb_agg(rom_id)
|
||||
@@ -282,13 +268,9 @@ def downgrade() -> None:
|
||||
WHERE cr.collection_id = c.id),
|
||||
'[]'::jsonb
|
||||
);
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
UPDATE collections c
|
||||
JOIN (
|
||||
SELECT collection_id, IFNULL(JSON_ARRAYAGG(rom_id), JSON_ARRAY()) AS roms
|
||||
@@ -298,9 +280,7 @@ def downgrade() -> None:
|
||||
ON c.id = cr.collection_id
|
||||
SET c.roms = cr.roms;
|
||||
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
with op.batch_alter_table("collections", schema=None) as batch_op:
|
||||
batch_op.alter_column("roms", existing_type=CustomJSON(), nullable=False)
|
||||
@@ -308,9 +288,7 @@ def downgrade() -> None:
|
||||
op.drop_table("collections_roms")
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
sa.text("""
|
||||
DROP VIEW virtual_collections;
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
)
|
||||
|
||||
@@ -21,9 +21,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -118,13 +116,9 @@ def upgrade():
|
||||
END AS ss_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
connection.execute(sa.text("""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
NOW() AS created_at,
|
||||
@@ -220,9 +214,7 @@ def upgrade():
|
||||
END AS ss_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -25,8 +25,7 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE OR REPLACE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -51,8 +50,7 @@ def upgrade() -> None:
|
||||
OR
|
||||
(r1.ss_id = r2.ss_id AND r1.ss_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
|
||||
@@ -65,8 +63,7 @@ def downgrade() -> None:
|
||||
connection.execute(sa.text("DROP VIEW IF EXISTS sibling_roms;"))
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -88,6 +85,5 @@ def downgrade() -> None:
|
||||
OR
|
||||
(r1.moby_id = r2.moby_id AND r1.moby_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
@@ -43,15 +43,11 @@ def upgrade() -> None:
|
||||
|
||||
# Build query based on whether emulator exists
|
||||
select_cols = "id, file_path, rom_id" + (", emulator" if has_emulator else "")
|
||||
results = conn.execute(
|
||||
text(
|
||||
f"""
|
||||
results = conn.execute(text(f"""
|
||||
SELECT {select_cols}
|
||||
FROM {table}
|
||||
WHERE {like_clause}
|
||||
""" # nosec B608
|
||||
)
|
||||
).fetchall()
|
||||
""")).fetchall() # nosec B608
|
||||
|
||||
for row in results:
|
||||
item_id = row.id
|
||||
@@ -102,13 +98,11 @@ def upgrade() -> None:
|
||||
|
||||
# Update DB
|
||||
conn.execute(
|
||||
text(
|
||||
f"""
|
||||
text(f"""
|
||||
UPDATE {table}
|
||||
SET file_path = :new_path
|
||||
WHERE id = :item_id
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
{"new_path": new_path, "item_id": item_id},
|
||||
)
|
||||
|
||||
|
||||
@@ -23,20 +23,14 @@ depends_on = None
|
||||
def upgrade() -> None:
|
||||
conn = op.get_bind()
|
||||
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
conn.execute(text("""
|
||||
UPDATE roms
|
||||
SET url_cover = replace(url_cover, 't_thumb', 't_1080p')
|
||||
WHERE url_cover LIKE '%t_thumb%'
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
if is_postgresql(conn):
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
conn.execute(text("""
|
||||
UPDATE roms
|
||||
SET url_screenshots = (
|
||||
SELECT jsonb_agg(
|
||||
@@ -46,19 +40,13 @@ def upgrade() -> None:
|
||||
)
|
||||
WHERE url_screenshots IS NOT NULL
|
||||
AND url_screenshots::text LIKE '%t_thumb%';
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
result = conn.execute(
|
||||
text(
|
||||
"""
|
||||
result = conn.execute(text("""
|
||||
SELECT id, url_screenshots
|
||||
FROM roms
|
||||
WHERE JSON_SEARCH(url_screenshots, 'one', '%t_thumb%') IS NOT NULL
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
for row in result:
|
||||
row_id, screenshots_json = row
|
||||
@@ -75,13 +63,11 @@ def upgrade() -> None:
|
||||
for url in screenshots
|
||||
]
|
||||
conn.execute(
|
||||
text(
|
||||
"""
|
||||
text("""
|
||||
UPDATE roms
|
||||
SET url_screenshots = :screenshots
|
||||
WHERE id = :id
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
{
|
||||
"screenshots": json.dumps(updated_screenshots),
|
||||
"id": row_id,
|
||||
|
||||
@@ -21,9 +21,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -157,13 +155,9 @@ def upgrade():
|
||||
END AS launchbox_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
connection.execute(sa.text("""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
NOW() AS created_at,
|
||||
@@ -294,9 +288,7 @@ def upgrade():
|
||||
END AS launchbox_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -25,8 +25,7 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE OR REPLACE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -63,8 +62,7 @@ def upgrade() -> None:
|
||||
OR
|
||||
(r1.tgdb_id = r2.tgdb_id AND r1.tgdb_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
|
||||
@@ -77,8 +75,7 @@ def downgrade() -> None:
|
||||
connection.execute(sa.text("DROP VIEW IF EXISTS sibling_roms;"))
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -103,6 +100,5 @@ def downgrade() -> None:
|
||||
OR
|
||||
(r1.ss_id = r2.ss_id AND r1.ss_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
@@ -25,15 +25,11 @@ def upgrade() -> None:
|
||||
|
||||
# Get all firmware records with their hash information
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
result = connection.execute(sa.text("""
|
||||
SELECT f.id, p.slug as platform_slug, f.file_name, f.file_size_bytes, f.md5_hash, f.sha1_hash, f.crc_hash
|
||||
FROM firmware f
|
||||
JOIN platforms p ON f.platform_id = p.id
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
all_firmware = result.fetchall()
|
||||
verified_firmware_ids = []
|
||||
|
||||
@@ -21,9 +21,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -165,13 +163,9 @@ def upgrade():
|
||||
END AS launchbox_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
connection.execute(sa.text("""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
NOW() AS created_at,
|
||||
@@ -312,9 +306,7 @@ def upgrade():
|
||||
END AS launchbox_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -21,13 +21,11 @@ def upgrade() -> None:
|
||||
batch_op.add_column(sa.Column("is_favorite", sa.Boolean(), nullable=True))
|
||||
|
||||
op.execute("UPDATE collections SET is_favorite = FALSE WHERE is_favorite IS NULL")
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
UPDATE collections
|
||||
SET is_favorite = TRUE
|
||||
WHERE LOWER(name) IN ('favourites', 'favorites')
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
with op.batch_alter_table("collections", schema=None) as batch_op:
|
||||
batch_op.alter_column("is_favorite", existing_type=sa.Boolean(), nullable=False)
|
||||
|
||||
@@ -75,23 +75,17 @@ def upgrade() -> None:
|
||||
# Migrate existing notes from rom_user to rom_notes table
|
||||
# Both note_raw_markdown and note_is_public columns exist from previous migrations
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(
|
||||
text(
|
||||
"""
|
||||
result = connection.execute(text("""
|
||||
SELECT id, rom_id, user_id, note_raw_markdown, note_is_public, updated_at
|
||||
FROM rom_user
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
for row in result:
|
||||
connection.execute(
|
||||
text(
|
||||
"""
|
||||
text("""
|
||||
INSERT INTO rom_notes (title, content, is_public, tags, created_at, updated_at, rom_id, user_id)
|
||||
VALUES (:title, :content, :is_public, :tags, :created_at, :updated_at, :rom_id, :user_id)
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
{
|
||||
"title": "My Note",
|
||||
"content": row.note_raw_markdown or "", # Handle potential NULL content
|
||||
@@ -125,26 +119,20 @@ def downgrade() -> None:
|
||||
|
||||
# Migrate notes back to rom_user (take first note per user/rom)
|
||||
connection = op.get_bind()
|
||||
result = connection.execute(
|
||||
text(
|
||||
"""
|
||||
result = connection.execute(text("""
|
||||
SELECT DISTINCT rom_id, user_id,
|
||||
FIRST_VALUE(content) OVER (PARTITION BY rom_id, user_id ORDER BY updated_at DESC) as content,
|
||||
FIRST_VALUE(is_public) OVER (PARTITION BY rom_id, user_id ORDER BY updated_at DESC) as is_public
|
||||
FROM rom_notes
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
for row in result:
|
||||
connection.execute(
|
||||
text(
|
||||
"""
|
||||
text("""
|
||||
UPDATE rom_user
|
||||
SET note_raw_markdown = :content, note_is_public = :is_public
|
||||
WHERE rom_id = :rom_id AND user_id = :user_id
|
||||
"""
|
||||
),
|
||||
"""),
|
||||
{
|
||||
"content": row.content,
|
||||
"is_public": row.is_public,
|
||||
|
||||
@@ -21,9 +21,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -185,13 +183,9 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
connection.execute(sa.text("""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
NOW() AS created_at,
|
||||
@@ -354,9 +348,7 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -34,9 +34,7 @@ def upgrade():
|
||||
)
|
||||
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -209,13 +207,9 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
connection.execute(sa.text("""CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
NOW() AS created_at,
|
||||
@@ -389,9 +383,7 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -40,23 +40,19 @@ def upgrade() -> None:
|
||||
rom_file_category_enum.create(connection, checkfirst=True)
|
||||
|
||||
# remove bad values before alter
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
UPDATE rom_files
|
||||
SET category = NULL
|
||||
WHERE category IS NOT NULL
|
||||
AND category NOT IN ('GAME', 'DLC', 'HACK', 'MANUAL', 'PATCH', 'UPDATE', 'MOD', 'DEMO', 'TRANSLATION', 'PROTOTYPE')
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
# postgres being picky about needing USING
|
||||
op.execute(
|
||||
"""
|
||||
op.execute("""
|
||||
ALTER TABLE rom_files
|
||||
ALTER COLUMN category TYPE romfilecategory
|
||||
USING category::text::romfilecategory
|
||||
"""
|
||||
)
|
||||
""")
|
||||
|
||||
else:
|
||||
rom_file_category_enum = sa.Enum(
|
||||
|
||||
@@ -21,9 +21,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
connection = op.get_bind()
|
||||
if is_postgresql(connection):
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id AS rom_id,
|
||||
@@ -204,13 +202,9 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms r
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
else:
|
||||
connection.execute(
|
||||
sa.text(
|
||||
"""
|
||||
connection.execute(sa.text("""
|
||||
CREATE OR REPLACE VIEW roms_metadata AS
|
||||
SELECT
|
||||
r.id as rom_id,
|
||||
@@ -393,9 +387,7 @@ def upgrade():
|
||||
END AS gamelist_rating
|
||||
FROM roms
|
||||
) AS r;
|
||||
"""
|
||||
)
|
||||
)
|
||||
"""))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -29,8 +29,7 @@ def upgrade() -> None:
|
||||
)
|
||||
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE OR REPLACE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -69,8 +68,7 @@ def upgrade() -> None:
|
||||
OR
|
||||
(r1.fs_name_no_tags = r2.fs_name_no_tags)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
|
||||
@@ -82,8 +80,7 @@ def downgrade() -> None:
|
||||
|
||||
# Restore previous view without fs_name_no_tags fallback
|
||||
connection.execute(
|
||||
sa.text(
|
||||
f"""
|
||||
sa.text(f"""
|
||||
CREATE OR REPLACE VIEW sibling_roms AS
|
||||
SELECT
|
||||
r1.id AS rom_id,
|
||||
@@ -120,8 +117,7 @@ def downgrade() -> None:
|
||||
OR
|
||||
(r1.tgdb_id = r2.tgdb_id AND r1.tgdb_id IS NOT NULL)
|
||||
);
|
||||
""" # nosec B608
|
||||
),
|
||||
"""), # nosec B608
|
||||
)
|
||||
|
||||
# Remove the index
|
||||
|
||||
@@ -86,8 +86,7 @@ def upgrade() -> None:
|
||||
sa.Column("url_cover", sa.Text(), nullable=True),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
batch_op.execute(
|
||||
"INSERT INTO roms(\
|
||||
batch_op.execute("INSERT INTO roms(\
|
||||
r_igdb_id, p_igdb_id, r_sgdb_id, p_sgdb_id, p_slug, p_name, \
|
||||
file_name, file_name_no_tags, file_extension, file_path, file_size, \
|
||||
file_size_units, r_name, r_slug, summary, path_cover_s, path_cover_l, has_cover, \
|
||||
@@ -97,8 +96,7 @@ def upgrade() -> None:
|
||||
file_name, file_name_no_tags, file_extension, file_path, file_size, \
|
||||
file_size_units, r_name, r_slug, summary, path_cover_s, path_cover_l, has_cover, \
|
||||
region, revision, tags, multi, files, url_cover \
|
||||
FROM old_roms"
|
||||
)
|
||||
FROM old_roms")
|
||||
op.drop_table("old_roms")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ async def token(form_data: Annotated[OAuth2RequestForm, Depends()]) -> TokenResp
|
||||
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"token_type": "bearer",
|
||||
"token_type": "bearer", # trunk-ignore(bandit/B105)
|
||||
"expires": ACCESS_TOKEN_EXPIRE_MINUTES * 60,
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ async def token(form_data: Annotated[OAuth2RequestForm, Depends()]) -> TokenResp
|
||||
return {
|
||||
"access_token": access_token,
|
||||
"refresh_token": refresh_token,
|
||||
"token_type": "bearer",
|
||||
"token_type": "bearer", # trunk-ignore(bandit/B105)
|
||||
"expires": ACCESS_TOKEN_EXPIRE_MINUTES * 60,
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +275,7 @@ class MetadataHandler(abc.ABC):
|
||||
|
||||
return search_term
|
||||
|
||||
def _mask_sensitive_values(self, values: dict[str, str | None]) -> dict[str, str]:
|
||||
def _mask_sensitive_values(self, values: dict[str, str]) -> dict[str, str]:
|
||||
"""
|
||||
Mask sensitive values (headers or params), leaving only the first 2 and last 2 characters of the token.
|
||||
"""
|
||||
|
||||
@@ -103,6 +103,9 @@ def extract_metadata_from_igdb_rom(rom: dict[str, Any]) -> IGDBMetadata:
|
||||
"remasters": [],
|
||||
"similar_games": [],
|
||||
"expanded_games": [],
|
||||
# TODO: extract multiplayer modes and derive player count
|
||||
"multiplayer_modes": [],
|
||||
"player_count": "1",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -68,10 +68,8 @@ if __name__ == "__main__":
|
||||
sorted(supported_platforms.items(), key=lambda item: item[1]["name"].lower())
|
||||
)
|
||||
|
||||
print(
|
||||
"""|Platform Name|Folder Name|Metadata Providers|
|
||||
|---|---|---|"""
|
||||
)
|
||||
print("""|Platform Name|Folder Name|Metadata Providers|
|
||||
|---|---|---|""")
|
||||
|
||||
for platform in supported_platforms.values():
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user