Skip to content

Commit 7c4eac8

Browse files
author
Alexander Eyers-Taylor
authored
Avoid prompting for upgrades when they wouldn't be prompted. (#1500)
1 parent da90651 commit 7c4eac8

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

extensions/ql-vscode/src/cli.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,17 @@ export class CliVersionConstraint {
12611261

12621262
/**
12631263
* CLI version where database registration was introduced
1264-
*/
1264+
*/
12651265
public static CLI_VERSION_WITH_DB_REGISTRATION = new SemVer('2.4.1');
12661266

1267+
/**
1268+
* CLI version where non destructive upgrades were introduced.
1269+
*
1270+
* This was landed in multiple parts so this is the version where all necessary feature were supported.
1271+
*/
1272+
public static CLI_VERSION_WITH_NON_DESTRUCTIVE_UPGRADES = new SemVer('2.4.2');
1273+
1274+
12671275
/**
12681276
* CLI version where the `--allow-library-packs` option to `codeql resolve queries` was
12691277
* introduced.
@@ -1359,6 +1367,10 @@ export class CliVersionConstraint {
13591367
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DB_REGISTRATION);
13601368
}
13611369

1370+
async supportsNonDestructiveUpgrades(): Promise<boolean> {
1371+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NON_DESTRUCTIVE_UPGRADES);
1372+
}
1373+
13621374
async supportsDatabaseUnbundle() {
13631375
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
13641376
}

extensions/ql-vscode/src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ async function activateWithInstalledDistribution(
782782
});
783783
}
784784

785-
if (queryUris.length > 1) {
785+
if (queryUris.length > 1 && !await cliServer.cliConstraints.supportsNonDestructiveUpgrades()) {
786786
// Try to upgrade the current database before running any queries
787787
// so that the user isn't confronted with multiple upgrade
788788
// requests for each query to run.

extensions/ql-vscode/src/run-queries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import * as messages from './pure/messages';
3232
import { InitialQueryInfo, LocalQueryInfo } from './query-results';
3333
import * as qsClient from './queryserver-client';
3434
import { isQuickQueryPath } from './quick-query';
35-
import { compileDatabaseUpgradeSequence, hasNondestructiveUpgradeCapabilities, upgradeDatabaseExplicit } from './upgrades';
35+
import { compileDatabaseUpgradeSequence, upgradeDatabaseExplicit } from './upgrades';
3636
import { ensureMetadataIsComplete } from './query-results';
3737
import { SELECT_QUERY_NAME } from './contextual/locationFinder';
3838
import { DecodedBqrsChunk } from './pure/bqrs-cli-types';
@@ -862,7 +862,7 @@ export async function compileAndRunQueryAgainstDatabase(
862862
let upgradeDir: tmp.DirectoryResult | undefined;
863863
try {
864864
let upgradeQlo;
865-
if (await hasNondestructiveUpgradeCapabilities(qs)) {
865+
if (await qs.cliServer.cliConstraints.supportsNonDestructiveUpgrades()) {
866866
upgradeDir = await tmp.dir({ dir: upgradesTmpDir, unsafeCleanup: true });
867867
upgradeQlo = await compileNonDestructiveUpgrade(qs, upgradeDir, query, qlProgram, dbItem, progress, token);
868868
} else {

extensions/ql-vscode/src/upgrades.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as messages from './pure/messages';
66
import * as qsClient from './queryserver-client';
77
import * as tmp from 'tmp-promise';
88
import * as path from 'path';
9-
import * as semver from 'semver';
109
import { DatabaseItem } from './databases';
1110

1211
/**
@@ -16,16 +15,6 @@ import { DatabaseItem } from './databases';
1615
*/
1716
const MAX_UPGRADE_MESSAGE_LINES = 10;
1817

19-
/**
20-
* Check that we support non-destructive upgrades.
21-
*
22-
* This requires 3 features. The ability to compile an upgrade sequence; The ability to
23-
* run a non-destructive upgrades as a query; the ability to specify a target when
24-
* resolving upgrades. We check for a version of codeql that has all three features.
25-
*/
26-
export async function hasNondestructiveUpgradeCapabilities(qs: qsClient.QueryServerClient): Promise<boolean> {
27-
return semver.gte(await qs.cliServer.getVersion(), '2.4.2');
28-
}
2918

3019

3120
/**
@@ -43,7 +32,7 @@ export async function compileDatabaseUpgradeSequence(
4332
if (dbItem.contents === undefined || dbItem.contents.dbSchemeUri === undefined) {
4433
throw new Error('Database is invalid, and cannot be upgraded.');
4534
}
46-
if (!await hasNondestructiveUpgradeCapabilities(qs)) {
35+
if (!await qs.cliServer.cliConstraints.supportsNonDestructiveUpgrades()) {
4736
throw new Error('The version of codeql is too old to run non-destructive upgrades.');
4837
}
4938
// If possible just compile the upgrade sequence

0 commit comments

Comments
 (0)