Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
EVEREST-629 Allowed pitr restore to new db cluster (#266)
Browse files Browse the repository at this point in the history
* EVEREST-629 Allowed pitr restore to new db cluster

* EVEREST-629 Removed console.log

* EVEREST-629 refactor pointInTimeDate, pitrBackupName

* EVEREST-629 after review fix
  • Loading branch information
filipmikes1 authored Feb 29, 2024
1 parent e45bd31 commit 66ce532
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 17 deletions.
14 changes: 10 additions & 4 deletions apps/everest/src/hooks/api/db-cluster/useCreateDbCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
// limitations under the License.

import { dbTypeToDbEngine } from '@percona/utils';
import { createDbClusterFn, getDbClusterCredentialsFn } from 'api/dbClusterApi';
import { getCronExpressionFromFormValues } from 'components/time-selection/time-selection.utils.ts';
import { DbWizardType } from 'pages/database-form/database-form-schema.ts';
import { generateShortUID } from 'pages/database-form/steps/first/utils.ts';
import {
UseMutationOptions,
useMutation,
useQuery,
} from '@tanstack/react-query';
import { createDbClusterFn, getDbClusterCredentialsFn } from 'api/dbClusterApi';
import { getCronExpressionFromFormValues } from 'components/time-selection/time-selection.utils.ts';
import { DbWizardType } from 'pages/database-form/database-form-schema.ts';
import { generateShortUID } from 'pages/database-form/steps/first/utils.ts';
import {
ClusterCredentials,
DataSource,
Expand Down Expand Up @@ -123,6 +123,12 @@ const formValuesToPayloadMapping = (
...(backupDataSource?.dbClusterBackupName && {
dataSource: {
dbClusterBackupName: backupDataSource.dbClusterBackupName,
...(backupDataSource?.pitr && {
pitr: {
date: backupDataSource.pitr.date,
type: 'date',
},
}),
},
}),
},
Expand Down
44 changes: 33 additions & 11 deletions apps/everest/src/modals/restore-db-modal/restore-db-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,42 @@ const RestoreDbModal = <T extends FieldValues>({
defaultValues={defaultValues}
values={{ ...defaultValues, pitrBackup: pitrData?.latestDate }}
onSubmit={({ backupName, backupType, pitrBackup }) => {
let pointInTimeDate = '';
let pitrBackupName = '';

if (pitrData) {
pitrBackupName = pitrData.latestBackupName;
}

if (pitrBackup && pitrBackup instanceof Date) {
pointInTimeDate = pitrBackup.toISOString().split('.')[0] + 'Z';
}

if (isNewClusterMode) {
closeModal();
const selectedBackup = backups?.find(
(backup) => backup.name === backupName
);
navigate('/databases/new', {
state: {
selectedDbCluster: dbCluster.metadata.name,
backupName,
namespace,
backupStorageName: selectedBackup,
},
});
if (backupType === BackuptypeValues.fromBackup) {
navigate('/databases/new', {
state: {
selectedDbCluster: dbCluster.metadata.name,
backupName,
namespace,
backupStorageName: selectedBackup,
},
});
} else {
navigate('/databases/new', {
state: {
selectedDbCluster: dbCluster.metadata.name,
backupName: pitrBackupName,
namespace,
backupStorageName: selectedBackup,
pointInTimeDate: pointInTimeDate,
},
});
}
} else {
if (backupType === BackuptypeValues.fromBackup) {
restoreBackupFromBackup(
Expand All @@ -105,9 +128,9 @@ const RestoreDbModal = <T extends FieldValues>({
} else {
restoreBackupFromPointInTime(
{
backupName: pitrData!.latestBackupName,
backupName: pitrBackupName,
namespace,
pointInTimeDate: pitrBackup!.toISOString().split('.')[0] + 'Z',
pointInTimeDate: pointInTimeDate,
},
{
onSuccess() {
Expand Down Expand Up @@ -152,7 +175,6 @@ const RestoreDbModal = <T extends FieldValues>({
{
label: Messages.fromPitr,
value: BackuptypeValues.fromPitr,
disabled: isNewClusterMode,
},
]}
/>
Expand Down
4 changes: 4 additions & 0 deletions apps/everest/src/pages/database-form/database-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export const DatabasePage = () => {
...(mode === 'restoreFromBackup' && {
backupDataSource: {
dbClusterBackupName: state?.backupName,
pitr: {
date: state?.pointInTimeDate,
type: 'date',
},
},
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { useEffect } from 'react';
import { useFormContext } from 'react-hook-form';
import { DbWizardFormFields } from '../../database-form.types';
import { StepHeader } from '../step-header/step-header';
import { Messages } from './pitr.messages';
import PitrStorage from './pitr-storage';
import { Messages } from './pitr.messages';

const PITRStep = () => {
const { control, watch, setValue } = useFormContext();
Expand Down
2 changes: 1 addition & 1 deletion apps/everest/src/pages/databases/DbClusterView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useMemo, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { DbClusterStatus } from 'shared-types/dbCluster.types';
import { DbEngineType } from 'shared-types/dbEngines.types';
import { useDBClustersForNamespaces } from '../../hooks/api/db-clusters/useDbClusters';
import { DB_CLUSTER_STATUS_TO_BASE_STATUS } from './DbClusterView.constants';
import {
beautifyDbClusterStatus,
Expand All @@ -42,7 +43,6 @@ import { Messages } from './dbClusterView.messages';
import { DbClusterTableElement } from './dbClusterView.types';
import { DbTypeIconProvider } from './dbTypeIconProvider/DbTypeIconProvider';
import { ExpandedRow } from './expandedRow/ExpandedRow';
import { useDBClustersForNamespaces } from '../../hooks/api/db-clusters/useDbClusters';

export const DbClusterView = () => {
const [isNewClusterMode, setIsNewClusterMode] = useState(false);
Expand Down
6 changes: 6 additions & 0 deletions apps/everest/src/shared-types/dbCluster.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ interface Proxy {

export interface DataSource {
dbClusterBackupName: string;
pitr?: DataSourcePitr;
}

export interface DataSourcePitr {
date: string;
type: 'date';
}

export interface Monitoring {
Expand Down

0 comments on commit 66ce532

Please sign in to comment.