Skip to content

Commit 8b5622e

Browse files
committed
Fix upgrades path
Ensure that upgrades can be resolved even when the upgrades pack is not in the workspace. This is the situation when the core libraries are resolved from the package cache. This change works because `qlProgram.libraryPath` is the resolved search path for compiling the query. We are guaranteed that the appropriate core libraries are included in this query. Note that this change avoids using extra source folders from the workspace. Previously without using packages, we assume that all relevant query paths are already inside the workspace. With packaging, this is no longer the case. It is theoretically possible that there will be extra upgrade scripts that are not on the resolved search path, but are included in the workspace. This situation would have worked in the past.This is not a situation that we expect to happen in practice. And if this does happen, I believe this is an error and all upgrades should be added explicitly to the search path. An open question is if this will work with downgrade scripts. If it does not, then I don't think this change makes things any worse than before.
1 parent cc9cbf7 commit 8b5622e

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,23 @@ async function compileNonDestructiveUpgrade(
437437
progress: ProgressCallback,
438438
token: CancellationToken,
439439
): Promise<string> {
440-
const searchPath = getOnDiskWorkspaceFolders();
441440

442441
if (!dbItem?.contents?.dbSchemeUri) {
443442
throw new Error('Database is invalid, and cannot be upgraded.');
444443
}
445-
const { scripts, matchesTarget } = await qs.cliServer.resolveUpgrades(dbItem.contents.dbSchemeUri.fsPath, searchPath, true, query.queryDbscheme);
444+
445+
// When packaging is used, dependencies may exist outside of the workspace and they are always on the resolved search path.
446+
// When packaging is not used, all dependencies are in the workspace.
447+
const upgradesPath = (await qs.cliServer.cliConstraints.supportsPackaging())
448+
? qlProgram.libraryPath
449+
: getOnDiskWorkspaceFolders();
450+
451+
const { scripts, matchesTarget } = await qs.cliServer.resolveUpgrades(
452+
dbItem.contents.dbSchemeUri.fsPath,
453+
upgradesPath,
454+
true,
455+
query.queryDbscheme
456+
);
446457

447458
if (!matchesTarget) {
448459
reportNoUpgradePath(qlProgram, query);

0 commit comments

Comments
 (0)