refactor(trash): import skip-merge reuses trash() for pending_jobs invariant (review T10 minor #1)
This commit is contained in:
@@ -288,6 +288,10 @@ export class NoteRepository {
|
||||
* - id present + raw_text identical → no-op (status: 'skipped')
|
||||
* - id present + raw_text differs → INSERT under fresh uuidv7
|
||||
* to preserve the raw_text-immutable invariant (status: 'forked')
|
||||
*
|
||||
* deletedAt merge (v0.2.3 #4, spec §8.2): source/dest 중 IS NOT NULL 우선
|
||||
* (삭제 보존). skip 케이스에서 source NN + dest NULL 일 때만 dest 갱신.
|
||||
* insert/fork 는 source 의 deletedAt 그대로 보존.
|
||||
*/
|
||||
importNote(input: ImportNoteInput): ImportNoteResult {
|
||||
const existing = this.findRawTextById(input.id);
|
||||
@@ -295,15 +299,14 @@ export class NoteRepository {
|
||||
let status: ImportNoteStatus = 'inserted';
|
||||
if (existing !== null) {
|
||||
if (existing === input.rawText) {
|
||||
// skip — 단, source 가 deletedAt IS NOT NULL 이고 dest 가 NULL 이면 dest 갱신 (삭제 보존)
|
||||
if (input.deletedAt) {
|
||||
// skip — source 가 deletedAt IS NOT NULL 이고 dest 가 NULL 이면 dest 갱신 (삭제 보존).
|
||||
// trash() 를 재사용해 pending_jobs cleanup invariant (§9.2) 도 동시에 만족.
|
||||
if (input.deletedAt != null) {
|
||||
const destRow = this.db
|
||||
.prepare('SELECT deleted_at FROM notes WHERE id=?')
|
||||
.get(input.id) as { deleted_at: string | null } | undefined;
|
||||
if (destRow && destRow.deleted_at === null) {
|
||||
this.db
|
||||
.prepare('UPDATE notes SET deleted_at = ?, updated_at = ? WHERE id = ?')
|
||||
.run(input.deletedAt, input.deletedAt, input.id);
|
||||
this.trash(input.id, input.deletedAt);
|
||||
}
|
||||
}
|
||||
return { id: input.id, status: 'skipped' };
|
||||
|
||||
Reference in New Issue
Block a user