Skip to content

Commit bbf806d

Browse files
authored
R2NP: add 403 permissions or physical backups disabled handler (supabase#31197)
* add 403 err handler * validate error * rm retry logic in fvor of enabling the query only if pitr or pb are enabled * disable queries instead of checking error code
1 parent 02ad266 commit bbf806d

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

apps/studio/pages/project/[ref]/database/backups/restore-to-new-project.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const RestoreToNewProject = () => {
8282
PermissionAction.INFRA_EXECUTE,
8383
'queue_job.restore.prepare'
8484
)
85-
const hasPITREnabled = cloneBackups?.pitr_enabled
85+
const PITR_ENABLED = cloneBackups?.pitr_enabled
8686

8787
const dbVersion = getDatabaseMajorVersion(project?.dbVersion ?? '')
8888
const IS_PG15_OR_ABOVE = dbVersion >= 15
@@ -100,9 +100,10 @@ const RestoreToNewProject = () => {
100100
refetchInterval,
101101
refetchOnWindowFocus: false,
102102
onSuccess: (data) => {
103-
const hasTransientState = data.clones.some((c) => c.status === 'IN_PROGRESS')
103+
const hasTransientState = data?.clones.some((c) => c.status === 'IN_PROGRESS')
104104
if (!hasTransientState) setRefetchInterval(false)
105105
},
106+
enabled: PHYSICAL_BACKUPS_ENABLED || PITR_ENABLED,
106107
}
107108
)
108109
const IS_CLONED_PROJECT = (cloneStatus?.cloned_from?.source_project as any)?.ref ? true : false
@@ -179,6 +180,16 @@ const RestoreToNewProject = () => {
179180
}
180181
}
181182

183+
if (isFreePlan) {
184+
return (
185+
<UpgradeToPro
186+
buttonText="Upgrade"
187+
primaryText="Restore to a new project requires a pro plan or above."
188+
secondaryText="To restore to a new project, you need to upgrade to a Pro plan and have physical backups enabled."
189+
/>
190+
)
191+
}
192+
182193
if (isOrioleDb) {
183194
return (
184195
<Admonition
@@ -191,10 +202,6 @@ const RestoreToNewProject = () => {
191202
)
192203
}
193204

194-
if (isLoading) {
195-
return <GenericSkeletonLoader />
196-
}
197-
198205
if (!canReadPhysicalBackups) {
199206
return <NoPermission resourceText="view backups" />
200207
}
@@ -243,14 +250,8 @@ const RestoreToNewProject = () => {
243250
)
244251
}
245252

246-
if (plan === 'free') {
247-
return (
248-
<UpgradeToPro
249-
buttonText="Upgrade"
250-
primaryText="Restore to a new project requires a pro plan or above."
251-
secondaryText="To restore to a new project, you need to upgrade to a Pro plan and have physical backups enabled."
252-
/>
253-
)
253+
if (isLoading) {
254+
return <GenericSkeletonLoader />
254255
}
255256

256257
if (IS_CLONED_PROJECT) {
@@ -286,7 +287,7 @@ const RestoreToNewProject = () => {
286287

287288
if (
288289
!isLoading &&
289-
hasPITREnabled &&
290+
PITR_ENABLED &&
290291
!cloneBackups?.physicalBackupData.earliestPhysicalBackupDateUnix
291292
) {
292293
return (
@@ -298,7 +299,7 @@ const RestoreToNewProject = () => {
298299
)
299300
}
300301

301-
if (!isLoading && !hasPITREnabled && cloneBackups?.backups.length === 0) {
302+
if (!isLoading && !PITR_ENABLED && cloneBackups?.backups.length === 0) {
302303
return (
303304
<>
304305
<Admonition
@@ -354,7 +355,7 @@ const RestoreToNewProject = () => {
354355
</Panel>
355356
</div>
356357
) : null}
357-
{hasPITREnabled ? (
358+
{PITR_ENABLED ? (
358359
<>
359360
<PITRForm
360361
disabled={isRestoring}

0 commit comments

Comments
 (0)