Repository navigation
fix(import): replace import removes the previous site media - #637
Merged
Merged
Conversation
A replace import wiped rows, folders and redirects but kept the old media_assets rows, so a second site shipping a file at the same storage path (two sites that embed the same font file) failed on media_assets.public_path after the data had already committed. Replace now deletes the library inside the import transaction and removes the bytes after commit, before the bundle's media is written. It only does so when the import carries media and the shell on main with no other branch, and it spares avatars and plugin-managed media, since those survive a replace. The archive endpoint now shares the JSON endpoint's apply path instead of a synthetic request, and the custom-table delete binds its boolean so replace runs on Postgres.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
A
replaceimport wiped rows, folders and redirects but kept the previous site'smedia_assetsrows. Importing a second site that ships a file at the same storage path, such as two sites that embed the same font file, failed withUNIQUE constraint failed: media_assets.public_pathafter the data had committed, and the new bytes had already overwritten the old asset's file.The fix
replacenow deletes the media library inside the import transaction and removes the files after commit, before the bundle's media is written. It does this only when the import carries both media and the site shell, runs on main, and no other branch exists; user avatars and plugin-managed media are kept. The archive endpoint now calls the JSON endpoint's apply path directly, and the custom-table delete binds its boolean soreplaceruns on Postgres.Verification
src/__tests__/server/importReplaceMedia.test.tsfails on main (4 of 10) and passes here on SQLite and on a local Postgres 16.