Skip to content

Invalid category values fix#2979

Merged
gantoine merged 3 commits intorommapp:masterfrom
LoneAngelFayt:invalid-category-values
Feb 3, 2026
Merged

Invalid category values fix#2979
gantoine merged 3 commits intorommapp:masterfrom
LoneAngelFayt:invalid-category-values

Conversation

@LoneAngelFayt
Copy link
Copy Markdown
Contributor

Description

Explicitly dropped in queries for postgres to fix an edge case where bad values can be in place "dlc", "translation", etc.
Fixed an error where postgres requires the USING clause to cast enum

Caught the following error during migrations:

ERROR: column "category" cannot be cast automatically to type romfilecategory HINT: You might need to specify "USING category::romfilecategory" STATEMENT: ALTER TABLE rom_files ALTER COLUMN category TYPE romfilecategory

AI disclaimer: Used Claude and Gemini for sanity check on Alembic and dev environment setup but code is all me

Checklist
Please check all that apply.

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Screenshots (if applicable)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @zclendenen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses critical database migration issues related to the "rom_files.category" column, particularly for PostgreSQL environments. It introduces a pre-migration data cleanup step to handle invalid category values and implements a PostgreSQL-specific casting mechanism for enum type changes, ensuring robust and error-free database schema updates.

Highlights

  • Data Pre-migration Cleanup: Invalid "category" values in the "rom_files" table are now set to NULL before the column type alteration, preventing potential migration failures due to uncastable data.
  • PostgreSQL Enum Casting Fix: The migration script now includes a PostgreSQL-specific "ALTER TABLE" statement for the "category" column, explicitly using "USING category::text::romfilecategory" to correctly cast existing data to the new "romfilecategory" enum type.
  • Conditional Column Alteration: The generic "batch_alter_table" operation for altering the "category" column has been made conditional, ensuring it only executes for non-PostgreSQL database dialects, while PostgreSQL uses the explicit "ALTER TABLE" statement.
Changelog
  • backend/alembic/versions/0062_rom_file_category_enum.py
    • Introduced a SQL "UPDATE" statement to nullify invalid "category" entries in the "rom_files" table prior to type conversion.
    • Added a PostgreSQL-specific "ALTER TABLE" command that includes the "USING category::text::romfilecategory" clause for successful enum type casting.
    • Modified the "batch_alter_table" operation to execute only when the database dialect is not PostgreSQL, preventing conflicts with the explicit PostgreSQL "ALTER TABLE" statement.
Activity
  • The author has tested the changes locally.
  • Relevant comments within the code have been updated.
  • The author utilized AI tools (Claude and Gemini) for sanity checks on Alembic and development environment setup, but confirms the code is their own.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a PostgreSQL migration failure by adding a data cleanup step and using the "USING" clause for type casting. However, a critical vulnerability has been introduced due to a case mismatch: the migration defines and checks for uppercase category names, while the application's RomFileCategory model uses lowercase. This will result in the deletion of all existing category data during migration and cause application failures. The migration logic must be updated to use lowercase strings consistently. The fix for the indentation bug in non-PostgreSQL databases is correctly implemented.

@LoneAngelFayt LoneAngelFayt force-pushed the invalid-category-values branch from 284ea0e to a893bb3 Compare February 3, 2026 05:10
@LoneAngelFayt LoneAngelFayt force-pushed the invalid-category-values branch from a893bb3 to 0430b53 Compare February 3, 2026 05:18
@gantoine gantoine merged commit 5fc0d4f into rommapp:master Feb 3, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants