fix(onboarding): address final review findings — atomicity, scheduling guard, apply-all recovery, client validation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Théo LAGACHE
2026-06-19 15:49:46 +02:00
co-authored by Claude Sonnet 4.6
parent fc42afe89e
commit 68cd89fbe1
2 changed files with 65 additions and 44 deletions
@@ -93,6 +93,7 @@ export const applyOnboardingDbSettingsAction = userAction
}; };
const applyScheduling = async () => { const applyScheduling = async () => {
if (backupMethod === undefined) return;
// Direct DB update — intentionally skips the side effect in // Direct DB update — intentionally skips the side effect in
// updateDatabaseBackupPolicyAction that deletes retention policy on null. // updateDatabaseBackupPolicyAction that deletes retention policy on null.
const cronValue = const cronValue =
@@ -105,37 +106,41 @@ export const applyOnboardingDbSettingsAction = userAction
const applyNotifications = async () => { const applyNotifications = async () => {
if (!notificationPolicies) return; if (!notificationPolicies) return;
await db await db.transaction(async (tx) => {
.delete(drizzleDb.schemas.alertPolicy) await tx
.where(eq(drizzleDb.schemas.alertPolicy.databaseId, databaseId)); .delete(drizzleDb.schemas.alertPolicy)
.where(eq(drizzleDb.schemas.alertPolicy.databaseId, databaseId));
if (notificationPolicies.length > 0) { if (notificationPolicies.length > 0) {
await db.insert(drizzleDb.schemas.alertPolicy).values( await tx.insert(drizzleDb.schemas.alertPolicy).values(
notificationPolicies.map((p) => ({ notificationPolicies.map((p) => ({
databaseId, databaseId,
notificationChannelId: p.channelId, notificationChannelId: p.channelId,
eventKinds: p.eventKinds as any, eventKinds: p.eventKinds as any,
enabled: p.enabled, enabled: p.enabled,
})) }))
); );
} }
});
}; };
const applyStorage = async () => { const applyStorage = async () => {
if (!storagePolicies) return; if (!storagePolicies) return;
await db await db.transaction(async (tx) => {
.delete(drizzleDb.schemas.storagePolicy) await tx
.where(eq(drizzleDb.schemas.storagePolicy.databaseId, databaseId)); .delete(drizzleDb.schemas.storagePolicy)
.where(eq(drizzleDb.schemas.storagePolicy.databaseId, databaseId));
if (storagePolicies.length > 0) { if (storagePolicies.length > 0) {
await db.insert(drizzleDb.schemas.storagePolicy).values( await tx.insert(drizzleDb.schemas.storagePolicy).values(
storagePolicies.map((p) => ({ storagePolicies.map((p) => ({
databaseId, databaseId,
storageChannelId: p.channelId, storageChannelId: p.channelId,
enabled: p.enabled, enabled: p.enabled,
})) }))
); );
} }
});
}; };
if (section === "retention" || section === "all") await applyRetention(); if (section === "retention" || section === "all") await applyRetention();
@@ -497,7 +497,7 @@ const NotificationsSection = ({
</Button> </Button>
<Button <Button
type="button" type="button"
disabled={isPending} disabled={isPending || policies.some((p) => !p.channelId || p.eventKinds.length === 0)}
onClick={() => onSave(policies)} onClick={() => onSave(policies)}
className="ml-auto" className="ml-auto"
> >
@@ -666,7 +666,7 @@ const StorageSection = ({
</Button> </Button>
<Button <Button
type="button" type="button"
disabled={isPending} disabled={isPending || policies.some((p) => !p.channelId)}
onClick={() => onSave(policies)} onClick={() => onSave(policies)}
className="ml-auto" className="ml-auto"
> >
@@ -803,26 +803,42 @@ export const StepDbSettings = () => {
const handleApplyToAll = async () => { const handleApplyToAll = async () => {
const otherDbIds = databaseIds.filter((id) => id !== dbId); const otherDbIds = databaseIds.filter((id) => id !== dbId);
const succeededIds: string[] = [];
for (const targetId of otherDbIds) { for (const targetId of otherDbIds) {
await applyMutation.mutateAsync({ try {
databaseId: targetId, await applyMutation.mutateAsync({
section: "all", databaseId: targetId,
retention: settings.retention, section: "all",
backupMethod: settings.backupMethod, retention: settings.retention,
backupCron: settings.backupCron, backupMethod: settings.backupMethod,
notificationPolicies: settings.notificationPolicies as any, backupCron: settings.backupCron,
storagePolicies: settings.storagePolicies, notificationPolicies: settings.notificationPolicies,
storagePolicies: settings.storagePolicies,
});
succeededIds.push(targetId);
} catch {
// mutation onError already shows a toast
}
}
if (succeededIds.length > 0) {
const updatedSettings = { ...dbSettings };
succeededIds.forEach((id) => {
updatedSettings[id] = { ...(dbSettings[id] ?? {}), ...settings };
});
await updateContext({
flowData: { ...state?.context.flowData, dbSettings: updatedSettings },
}); });
} }
const updatedSettings = { ...dbSettings };
otherDbIds.forEach((id) => { if (succeededIds.length === otherDbIds.length) {
updatedSettings[id] = { ...(dbSettings[id] ?? {}), ...settings }; toast.success("Settings applied to all databases.");
}); setPhase({ kind: "grid" });
await updateContext({ } else if (succeededIds.length > 0) {
flowData: { ...state?.context.flowData, dbSettings: updatedSettings }, toast.warning(`Settings applied to ${succeededIds.length} of ${otherDbIds.length} databases.`);
}); setPhase({ kind: "grid" });
toast.success("Settings applied to all databases."); }
setPhase({ kind: "grid" });
}; };
const SECTIONS: { const SECTIONS: {