diff options
| author | historia <[not public]> | 2026-09-19 03:52:04 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-19 03:52:04 -0400 |
| commit | bab5dd653039d026eb3d4e46da7aafef7137fe7c (patch) | |
| tree | 9a1d8686dbcef8c145e3593511153768ae08962c /internal/admin/room_content_migrate.go | |
| parent | 0e60567a7a0addb9421769ee7be7853bfa8788cb (diff) | |
| download | thehouseoficarus-bab5dd653039d026eb3d4e46da7aafef7137fe7c.tar.gz | |
fix: journal in-game room insert/remove, rewrite non-room room refs on rename/swap, seed admin grid from edited room, type action switches
Diffstat (limited to 'internal/admin/room_content_migrate.go')
| -rw-r--r-- | internal/admin/room_content_migrate.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/internal/admin/room_content_migrate.go b/internal/admin/room_content_migrate.go new file mode 100644 index 0000000..47353fd --- /dev/null +++ b/internal/admin/room_content_migrate.go @@ -0,0 +1,38 @@ +package admin + +import ( + "fmt" + "path/filepath" + + "thehouseoficarus/internal/behavior" + "thehouseoficarus/internal/persistence" +) + +// rewriteContentRoomRefs rewrites structural room-ID references in every +// non-room content file under dataDir per idMap, stages the changed files into +// txn, and returns the before/after images so the caller can record them for +// undo. This keeps a room rename's content updates in the SAME journaled +// commit as the room files. +func rewriteContentRoomRefs(dataDir string, idMap map[int]int, txn *persistence.Transaction) ([]ExtraFile, error) { + if len(idMap) == 0 { + return nil, nil + } + var extras []ExtraFile + for _, sub := range behavior.RoomRefContentDirs { + changes, err := behavior.RewriteRoomRefsInDir(filepath.Join(dataDir, sub), idMap) + if err != nil { + return extras, fmt.Errorf("scan %s: %w", sub, err) + } + for _, ch := range changes { + if err := txn.Replace(ch.Path, ch.Content, 0644); err != nil { + return extras, fmt.Errorf("stage %s: %w", ch.Path, err) + } + extras = append(extras, ExtraFile{ + FilePath: ch.Path, + OldContent: ch.Old, + NewContent: ch.Content, + }) + } + } + return extras, nil +} |
