Skip to content

Commit

Permalink
Merge pull request #2130 from Automattic/add/warning-for-mydumper
Browse files Browse the repository at this point in the history
Add a warning on `vip export` when exporting a MyDumper SQL dump
  • Loading branch information
robersongomes authored Nov 27, 2024
2 parents 19f0cfd + ccb5cef commit 90146fa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/commands/export-sql.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export type AppBackupAndJobStatusQuery = {
environments?: Array< {
__typename?: 'AppEnvironment';
id?: number | null;
backupsSqlDumpTool?: string | null;
latestBackup?: {
__typename?: 'Backup';
id?: number | null;
type?: string | null;
size?: number | null;
filename?: string | null;
sqlDumpTool?: string | null;
createdAt?: string | null;
} | null;
jobs?: Array<
Expand Down
23 changes: 21 additions & 2 deletions src/commands/export-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const BACKUP_AND_JOB_STATUS_QUERY = gql`
id
environments(id: $envId) {
id
backupsSqlDumpTool
latestBackup {
id
type
size
filename
sqlDumpTool
createdAt
}
jobs(jobTypes: [db_backup_copy]) {
Expand Down Expand Up @@ -98,6 +100,7 @@ async function fetchLatestBackupAndJobStatusBase(
): Promise< {
latestBackup: Backup | undefined;
jobs: Job[];
envSqlDumpTool: string | null | undefined;
} > {
const api = API();

Expand All @@ -108,11 +111,12 @@ async function fetchLatestBackupAndJobStatusBase(
} );

const environments = response.data.app?.environments;
const envSqlDumpTool = environments?.[ 0 ]?.backupsSqlDumpTool;

const latestBackup: Backup | undefined = environments?.[ 0 ]?.latestBackup as Backup;
const jobs: Job[] = ( environments?.[ 0 ]?.jobs || [] ) as Job[];

return { latestBackup, jobs };
return { latestBackup, jobs, envSqlDumpTool };
}

async function fetchLatestBackupAndJobStatus(
Expand Down Expand Up @@ -412,7 +416,10 @@ export class ExportSQLCommand {
await this.runBackupJob();
}

const { latestBackup } = await fetchLatestBackupAndJobStatus( this.app.id, this.env.id );
const { latestBackup, envSqlDumpTool } = await fetchLatestBackupAndJobStatus(
this.app.id,
this.env.id
);

if ( ! latestBackup ) {
await this.track( 'error', {
Expand All @@ -436,6 +443,18 @@ export class ExportSQLCommand {
);
}

const showMyDumperWarning = ( latestBackup.sqlDumpTool ?? envSqlDumpTool ) === 'mydumper';
if ( showMyDumperWarning ) {
console.warn(
chalk.yellow.bold( 'WARNING:' ),
chalk.yellow(
'This is a large or complex database. The backup file for this database is generated with MyDumper. ' +
'The file can only be loaded with MyLoader. ' +
'For more information: https://github.com/mydumper/mydumper'
)
);
}

if ( await this.getExportJob() ) {
console.log(
`Attaching to an existing export for the backup with timestamp ${ latestBackup.createdAt }`
Expand Down
1 change: 1 addition & 0 deletions src/graphqlTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ export type Backup = {
filename?: Maybe< Scalars[ 'String' ][ 'output' ] >;
id?: Maybe< Scalars[ 'Float' ][ 'output' ] >;
size?: Maybe< Scalars[ 'Float' ][ 'output' ] >;
sqlDumpTool?: Maybe< Scalars[ 'String' ][ 'output' ] >;
type?: Maybe< Scalars[ 'String' ][ 'output' ] >;
};

Expand Down

0 comments on commit 90146fa

Please sign in to comment.