Skip to content

Safer migrations#3238

Merged
gantoine merged 5 commits intomasterfrom
safer-migrations
Apr 10, 2026
Merged

Safer migrations#3238
gantoine merged 5 commits intomasterfrom
safer-migrations

Conversation

@gantoine
Copy link
Copy Markdown
Member

Summary

  • Add if_not_exists=True to all create_table, add_column, and create_index operations across alembic migrations
  • Add if_exists=True to all drop_table, drop_column, and drop_index operations across alembic migrations

Motivation

Makes migrations idempotent so they don't fail when re-run against a database where the target tables, columns, or indexes already exist (or have already been dropped). This improves resilience during partial migration failures and manual recovery scenarios.

gantoine and others added 4 commits April 9, 2026 21:46
Prevents errors when migrations are re-run against a database that
already has (or has already dropped) the target tables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ndex ops

Prevents errors when migrations are re-run against a database that
already has (or has already dropped) the target indexes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 10, 2026 03:07
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 10, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​alembic@​1.13.1 ⏵ 1.18.498100100100100

View full report

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Makes Alembic migrations more resilient to partial runs by adding if_not_exists=True / if_exists=True to schema operations, and bumps Alembic to a version that supports these flags.

Changes:

  • Add if_not_exists=True to create_table, add_column, and create_index migration operations.
  • Add if_exists=True to drop_table, drop_column, and drop_index migration operations.
  • Update Alembic dependency/lockfile (plus minor whitespace-only edits in a few non-migration files).

Reviewed changes

Copilot reviewed 61 out of 62 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
uv.lock Updates lockfile (notably Alembic version/resolution metadata).
pyproject.toml Bumps Alembic dependency constraint to ~=1.16.
backend/tests/handler/metadata/test_base_handler.py Removes stray blank lines (format-only).
backend/tests/endpoints/test_device.py Removes stray blank lines (format-only).
backend/endpoints/search.py Removes stray blank line (format-only).
backend/alembic/versions/2.0.0_.py Adds if_(not_)exists flags to table/index create/drop.
backend/alembic/versions/1.8.3_.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/1.8.2_.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/1.8.1_.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/1.8_.py Adds if_(not_)exists flags across create/drop and add/drop column ops.
backend/alembic/versions/1.7.1_.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/1.6.3_.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/1.6.2_.py Replaces try/except with if_not_exists / if_exists create/drop tables.
backend/alembic/versions/0075_sync_sessions.py Adds if_(not_)exists flags; also changes how sync_config is added/dropped.
backend/alembic/versions/0073_sibling_roms_metadata_only.py Adds if_(not_)exists flags for index ops.
backend/alembic/versions/0072_client_tokens.py Adds if_(not_)exists flags for table/index ops.
backend/alembic/versions/0069_sibling_roms_fs_name.py Adds if_(not_)exists flags for index ops.
backend/alembic/versions/0068_save_sync.py Adds if_(not_)exists flags for tables/columns/indexes and corresponding drops.
backend/alembic/versions/0065_collections_updated_at_idx.py Adds if_(not_)exists flags for index ops.
backend/alembic/versions/0064_add_updated_at_indexes.py Adds if_(not_)exists flags for index ops.
backend/alembic/versions/0061_manual_metadata.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0060_user_ui_settings.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0059_rom_version_tag.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0057_multi_notes.py Adds if_(not_)exists flags for table/index ops and column restores in downgrade.
backend/alembic/versions/0056_gamelist_xml.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0055_collection_is_favorite.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0054_add_platform_metadata_slugs.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0053_add_hltb_metadata.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0051_flashpoint_metadata.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0050_firmware_add_is_verified.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0049_add_fs_size_bytes.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0047_smart_collections.py Adds if_(not_)exists flags for table drop.
backend/alembic/versions/0046_migrate_platform_slugs.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0044_hasheous_id.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0043_launchbox_id.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0042_add_missing_from_fs.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0039_add_retro_achievements.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0036_screenscraper_platforms_id.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/0035_screenscraper.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0034_virtual_collections_db_view.py Adds if_(not_)exists flags for table/column ops.
backend/alembic/versions/0033_rom_file_and_hashes.py Adds if_(not_)exists flags for table/column/index drops and restores.
backend/alembic/versions/0032_longer_fs_fields.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/0031_datetime_to_timestamp.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/0029_platforms_custom_name.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0028_user_email.py Adds if_(not_)exists flags for add/drop column + index ops.
backend/alembic/versions/0027_platforms_data.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0026_romuser_status_fields.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0025_roms_hashes.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0024_sibling_roms_db_view.py Adds if_(not_)exists flags for index ops.
backend/alembic/versions/0022_collections_.py Adds if_(not_)exists flags for table create/drop.
backend/alembic/versions/0021_rom_user.py Adds if_(not_)exists flags for table create/drop.
backend/alembic/versions/0020_created_and_updated.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0019_resources_refactor.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/0018_firmware.py Adds if_(not_)exists flags for table create/drop.
backend/alembic/versions/0017_rom_notes.py Adds if_(not_)exists flags for table create/drop.
backend/alembic/versions/0016_user_last_login_active.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0015_mobygames_data.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0014_asset_files.py Adds if_(not_)exists flags across table/column ops.
backend/alembic/versions/0013_upgrade_file_extension.py Removes autogenerated Alembic comment wrappers (no-op).
backend/alembic/versions/0012_add_regions_languages.py Adds if_(not_)exists flags for add/drop column ops.
backend/alembic/versions/0011_drop_has_cover.py Adds if_(not_)exists flags for drop/add column ops.
backend/alembic/versions/0010_igdb_id_integerr.py Removes autogenerated Alembic comment wrappers (no-op).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/alembic/versions/0075_sync_sessions.py Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Test Results (mariadb)

1 174 tests   1 173 ✅  3m 0s ⏱️
    1 suites      1 💤
    1 files        0 ❌

Results for commit b0a88ff.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 10, 2026

Test Results (postgresql)

1 174 tests   1 173 ✅  3m 8s ⏱️
    1 suites      1 💤
    1 files        0 ❌

Results for commit b0a88ff.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
15528 10457 67% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
backend/endpoints/search.py 30% 🟢
TOTAL 30% 🟢

updated for commit: b0a88ff by action🐍

@gantoine gantoine merged commit 44e091e into master Apr 10, 2026
14 checks passed
@gantoine gantoine deleted the safer-migrations branch April 10, 2026 19:20
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