[PR #3664] [MERGED] Add migration to fix dropped foreign key constraints dropped in v2.17.0 migration #4046

Closed
opened 2026-04-25 00:18:06 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf/pull/3664
Author: @advplyr
Created: 11/29/2024
Status: Merged
Merged: 11/30/2024
Merged by: @advplyr

Base: masterHead: v2.17.3-fk-constraints-migration


📝 Commits (2)

  • 70f466d Add migration for v2.17.3 to fix dropped fk constraints
  • 4b52f31 Update v2.17.3 migration file to first check if constraints need to be updated, add unit test

📊 Changes

3 files changed (+496 additions, -6 deletions)

View changed files

📝 server/migrations/changelog.md (+7 -6)
server/migrations/v2.17.3-fk-constraints.js (+259 -0)
test/server/migrations/v2.17.3-fk-constraints.test.js (+230 -0)

📄 Description

Brief summary

The migration in v2.17.0 caused the modified tables to lose their foreign key constraints. This is a known bug in sequelize.

Which issue is fixed?

This resolves server crashes when deleting records in the affected table that have an association.

In-depth Description

This migration does the following for each table affected (follows the outlined method in sqlite docs):

  1. Creates a new table with a temp name with the correct fk constraints
  2. Populates the new table with the original tables records
  3. Drops the old table
  4. Renames the old table to the original

How have you tested this?

Testing in progress.

Will most likely add an additional check to see if this migration is necessary for users who have downgraded and are upgrading again.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf/pull/3664 **Author:** [@advplyr](https://github.com/advplyr) **Created:** 11/29/2024 **Status:** ✅ Merged **Merged:** 11/30/2024 **Merged by:** [@advplyr](https://github.com/advplyr) **Base:** `master` ← **Head:** `v2.17.3-fk-constraints-migration` --- ### 📝 Commits (2) - [`70f466d`](https://github.com/advplyr/audiobookshelf/commit/70f466d03c4c27d99070d764a2eddac0bdccc9f8) Add migration for v2.17.3 to fix dropped fk constraints - [`4b52f31`](https://github.com/advplyr/audiobookshelf/commit/4b52f31d58216875f9429f1ace2314bb4061d19f) Update v2.17.3 migration file to first check if constraints need to be updated, add unit test ### 📊 Changes **3 files changed** (+496 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `server/migrations/changelog.md` (+7 -6) ➕ `server/migrations/v2.17.3-fk-constraints.js` (+259 -0) ➕ `test/server/migrations/v2.17.3-fk-constraints.test.js` (+230 -0) </details> ### 📄 Description ## Brief summary The migration in v2.17.0 caused the modified tables to lose their foreign key constraints. This is a [known bug](https://github.com/sequelize/sequelize/issues/12741) in sequelize. ## Which issue is fixed? This resolves server crashes when deleting records in the affected table that have an association. ## In-depth Description This migration does the following for each table affected (follows the outlined method in [sqlite docs](https://www.sqlite.org/lang_altertable.html#otheralter)): 1. Creates a new table with a temp name with the correct fk constraints 2. Populates the new table with the original tables records 3. Drops the old table 4. Renames the old table to the original ## How have you tested this? Testing in progress. Will most likely add an additional check to see if this migration is necessary for users who have downgraded and are upgrading again. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-25 00:18:06 +02:00
adam closed this issue 2026-04-25 00:18:06 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#4046