···385385 }
386386 }
387387388388- // Step 7: Delete old records from our database tables
389389- await step.run("delete-old-db-records", async () => {
390390- const oldPubUris = Object.keys(publicationUriMap).filter(uri =>
391391- new AtUri(uri).collection === "pub.leaflet.publication"
392392- );
393393- const oldDocUris = Object.keys(documentUriMap).filter(uri =>
394394- new AtUri(uri).collection === "pub.leaflet.document"
395395- );
396396-397397- // NOTE: We intentionally keep old documents_in_publications entries.
398398- // New entries are created in Step 4 with the new URIs, but the old entries
399399- // should remain so that notifications and other references that point to
400400- // old document/publication URIs can still look up the relationship.
401401-402402- // Delete from documents (old document URIs)
403403- if (oldDocUris.length > 0) {
404404- await supabaseServerClient
405405- .from("documents")
406406- .delete()
407407- .in("uri", oldDocUris);
408408- }
409409-410410- // Delete from publications (old publication URIs)
411411- if (oldPubUris.length > 0) {
412412- await supabaseServerClient
413413- .from("publications")
414414- .delete()
415415- .in("uri", oldPubUris);
416416- }
417417- });
388388+ // NOTE: We intentionally keep old documents, publications, and documents_in_publications entries.
389389+ // New entries are created with the new URIs, but the old entries remain so that:
390390+ // 1. Notifications referencing old document/publication URIs can still resolve
391391+ // 2. External references (e.g., from other AT Proto apps) to old URIs continue to work
392392+ // 3. The normalization layer handles both schemas transparently for reads
393393+ // Old records are also kept on the user's PDS so existing AT-URI references remain valid.
418394419395 return {
420396 success: stats.errors.length === 0,