Skip to content

fix(import): replace import removes the previous site media - #637

Merged
DavidBabinec merged 1 commit into
mainfrom
fix/replace-import-media
Oct 13, 2026
Merged

DavidBabinec merged 1 commit into
mainfrom
fix/replace-import-media

Conversation

@DavidBabinec

Copy link
Copy Markdown
Contributor

The bug

A replace import wiped rows, folders and redirects but kept the previous site's media_assets rows. Importing a second site that ships a file at the same storage path, such as two sites that embed the same font file, failed with UNIQUE constraint failed: media_assets.public_path after the data had committed, and the new bytes had already overwritten the old asset's file.

The fix

replace now 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 so replace runs on Postgres.

Verification

src/__tests__/server/importReplaceMedia.test.ts fails on main (4 of 10) and passes here on SQLite and on a local Postgres 16.

before: {"error":"UNIQUE constraint failed: media_assets.public_path"}
after:  10 pass, 0 fail
BUILD_EXIT=0 LINT_EXIT=0 TEST_EXIT=0 (7132 pass, 0 fail)

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.
@DavidBabinec
DavidBabinec merged commit 87a4c7f into main Oct 13, 2026
11 checks passed
@DavidBabinec
DavidBabinec deleted the fix/replace-import-media branch October 13, 2026 15:02
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.

1 participant