@@ -131,6 +131,12 @@ export class CodeQLCliServer implements Disposable {
131131 */
132132 private static CLI_VERSION_WITH_LANGUAGE = new SemVer ( '2.4.1' ) ;
133133
134+ /**
135+ * CLI version where `codeql resolve upgrades` supports
136+ * the `--allow-downgrades` flag
137+ */
138+ private static CLI_VERSION_WITH_DOWNGRADES = new SemVer ( '2.4.4' ) ;
139+
134140 /** The process for the cli server, or undefined if one doesn't exist yet */
135141 process ?: child_process . ChildProcessWithoutNullStreams ;
136142 /** Queue of future commands*/
@@ -662,15 +668,19 @@ export class CodeQLCliServer implements Disposable {
662668 * Gets information necessary for upgrading a database.
663669 * @param dbScheme the path to the dbscheme of the database to be upgraded.
664670 * @param searchPath A list of directories to search for upgrade scripts.
671+ * @param allowDowngradesIfPossible Whether we should try and include downgrades of we can.
665672 * @param targetDbScheme The dbscheme to try to upgrade to.
666673 * @returns A list of database upgrade script directories
667674 */
668- resolveUpgrades ( dbScheme : string , searchPath : string [ ] , targetDbScheme ?: string ) : Promise < UpgradesInfo > {
675+ async resolveUpgrades ( dbScheme : string , searchPath : string [ ] , allowDowngradesIfPossible : boolean , targetDbScheme ?: string ) : Promise < UpgradesInfo > {
669676 const args = [ '--additional-packs' , searchPath . join ( path . delimiter ) , '--dbscheme' , dbScheme ] ;
670677 if ( targetDbScheme ) {
671678 args . push ( '--target-dbscheme' , targetDbScheme ) ;
679+ if ( allowDowngradesIfPossible && await this . supportsDowngrades ( ) ) {
680+ args . push ( '--allow-downgrades' ) ;
681+ }
672682 }
673- return this . runJsonCodeQlCliCommand < UpgradesInfo > (
683+ return await this . runJsonCodeQlCliCommand < UpgradesInfo > (
674684 [ 'resolve' , 'upgrades' ] ,
675685 args ,
676686 'Resolving database upgrade scripts' ,
@@ -744,6 +754,10 @@ export class CodeQLCliServer implements Disposable {
744754 return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_LANGUAGE ) >= 0 ;
745755 }
746756
757+ public async supportsDowngrades ( ) {
758+ return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_DOWNGRADES ) >= 0 ;
759+ }
760+
747761 private async refreshVersion ( ) {
748762 const distribution = await this . distributionProvider . getDistribution ( ) ;
749763 switch ( distribution . kind ) {
0 commit comments