Skip to content

Commit cc70928

Browse files
sametbasbugclaude
andcommitted
Say out loud that the restore replays history
I read the restore as full of workarounds — rows inserted in a starting state, fields left null — and assumed they were dodging triggers, with some of them quietly losing data. Both readings were wrong. Announcements go in as drafts, media assets staged, transform claims reserved, MCP grants unrevoked. Then the transition rows follow, and the *_apply triggers rebuild the final state from them. The restore does not copy state; it replays the path production took to reach that state. Measured: a claim exported as succeeded comes back succeeded, and a revoked grant comes back revoked with its own reason rather than the bulk one. So there is nothing to simplify here. What was missing is that the code never said any of this, which is how I misread it and how the next reader would too. That explanation is now at the top of the restore. Two properties that held only by luck now hold by test. A backup taken from a restored database has to pass its own verification — otherwise surviving one disaster leaves you defenceless against the second. And the transform claims have to come back with the statuses they left with, since a claim stuck at reserved would contradict the monthly counts and invalidate the next backup. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 88ceffc commit cc70928

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎scripts/orbit-slice4-tests.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { canonicalJson } from '../src/server/publication/content';
1111
import {
1212
encryptDynamicBackup,
1313
RESTORE_GATE_CLASSIFICATION,
14+
verifyDynamicBackup,
1415
type DynamicBackup,
1516
} from '../src/server/backup/dynamic-backup';
1617

@@ -1151,6 +1152,11 @@ describe('Orbit V6 Slice 4 publication and backup core', { concurrency: false },
11511152
);
11521153
assert.ok(restoredExport.tables.records.some((row) => row.parent_id === removedPost.id));
11531154

1155+
// Geri yükleme bir kere olmaz. Geri yüklenmiş bir veritabanından alınan
1156+
// yedek de kendi doğrulamasından geçmek zorunda, yoksa ilk felaketten
1157+
// sonra ikincisine karşı savunmasız kalırız.
1158+
await verifyDynamicBackup(restoredExport);
1159+
11541160
// Askıya alınan kapılar aynı SQL ile geri kondu: geri yüklenmiş
11551161
// veritabanının tetikleyici kümesi taze şemadan ayırt edilemez.
11561162
const afterTriggers = await testPost('/__test/schema-triggers', {}, started.url)

‎scripts/orbit-slice5-tests.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
decryptChunkedBackup,
1414
encryptChunkedBackup,
1515
} from '../src/server/backup/chunked-backup';
16+
import { verifyDynamicBackup } from '../src/server/backup/dynamic-backup';
1617
import { ImageTransformError, inspectImage, transformImage } from '../src/server/media/image-processor';
1718
import sharp from 'sharp';
1819

@@ -1155,6 +1156,29 @@ describe('Orbit V6 Slice 5 dashboard and platform core', { concurrency: false },
11551156
assert.equal(proof.counts.closedAccounts, 1);
11561157
assert.equal(proof.counts.validations, 1);
11571158
assert.equal(proof.foreignKeyViolations, 0);
1159+
1160+
// Geri yükleme bir kere olmaz. Geri yüklenmiş veritabanından alınan
1161+
// yedek de kendi doğrulamasından geçmeli, yoksa ilk felaketten sonra
1162+
// ikincisine karşı savunmasız kalırız.
1163+
const restoredDynamic = await fetch(`${started.url}/__test/backup-export`, {
1164+
method: 'POST',
1165+
headers: { 'content-type': 'application/json', 'x-test-now': String(NOW) },
1166+
body: JSON.stringify({ includeSessions: true }),
1167+
}).then((response) => response.json()) as {
1168+
tables: Record<string, Array<Record<string, unknown>>>;
1169+
};
1170+
await verifyDynamicBackup(restoredDynamic);
1171+
1172+
// Dönüşüm talepleri sonuçlarıyla birlikte geri gelmeli: 'reserved' diye
1173+
// yazılan bir talep aylık sayımla çelişir ve o çelişki bir sonraki
1174+
// yedeği geçersiz kılar.
1175+
const sourceClaims = new Map(dynamicExport.tables.mediaTransformClaims.map(
1176+
(row) => [String(row.id), row.status],
1177+
));
1178+
assert.ok(sourceClaims.size > 0, 'yedekte dönüşüm talebi yok, denetim boşa çalışıyor');
1179+
for (const row of restoredDynamic.tables.mediaTransformClaims) {
1180+
assert.equal(row.status, sourceClaims.get(String(row.id)), `talep durumu kayıp: ${String(row.id)}`);
1181+
}
11581182
} finally {
11591183
if (restoreWorker) await stopWorker(restoreWorker);
11601184
await rm(restorePersist, { recursive: true, force: true });

‎src/server/backup/dynamic-backup.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ export async function restoreDynamicBackup(
329329
throw new Error('backup_restore_target_not_empty');
330330
}
331331

332+
/* Aşağıdaki satır satır okunduğunda kaçınılması güç bir yanlış anlama var,
333+
* bir kez ben de düştüm: bazı satırlar başlangıç durumuyla giriliyor ve
334+
* bazı alanlar boş bırakılıyor. Bu tetikleyici atlatmak için değil.
335+
*
336+
* Duyurular taslak giriyor, medya varlıkları staged, dönüşüm talepleri
337+
* reserved, MCP yetkileri iptalsiz. Sonra o tabloların geçiş kayıtları
338+
* (announcement_transitions, media_attachment_transitions,
339+
* media_transform_results, mcp_authorization_revocations) sırayla
340+
* yazılıyor ve *_apply tetikleyicileri son durumu yeniden kuruyor. Yani
341+
* geri yükleme durumu kopyalamıyor, üretim hangi yoldan o duruma geldiyse
342+
* aynı yoldan yeniden üretiyor. Doğruladım: kaynak yedekte 'succeeded'
343+
* olan bir talep geri yüklenmiş veritabanında da 'succeeded'.
344+
*
345+
* Bu yüzden burada sadeleştirilecek bir kıvrım yok. Boş bırakılan alanların
346+
* geri geldiğini orbit-slice5-tests bir tur dönerek kontrol ediyor. */
332347
const suspendedGates = await captureSuspendedGates(db);
333348

334349
const statements: D1PreparedStatementLike[] = [];

0 commit comments

Comments
 (0)