diff --git a/extensions/sql-database-projects/BuildDirectory/SystemDacpacs/AzureDw/master.dacpac b/extensions/sql-database-projects/BuildDirectory/SystemDacpacs/AzureDw/master.dacpac new file mode 100644 index 0000000000..689f2c5044 Binary files /dev/null and b/extensions/sql-database-projects/BuildDirectory/SystemDacpacs/AzureDw/master.dacpac differ diff --git a/extensions/sql-database-projects/src/common/constants.ts b/extensions/sql-database-projects/src/common/constants.ts index c116e7e85b..773d85eacc 100644 --- a/extensions/sql-database-projects/src/common/constants.ts +++ b/extensions/sql-database-projects/src/common/constants.ts @@ -354,6 +354,9 @@ export const targetPlatformToVersion: Map = new Map targetPlatformToVersion.get(k) === version)[0]; } diff --git a/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts b/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts index d6f7a8ec2f..3af7905ed1 100644 --- a/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts +++ b/extensions/sql-database-projects/src/dialogs/addDatabaseReferenceDialog.ts @@ -315,8 +315,8 @@ export class AddDatabaseReferenceDialog { this.setDefaultDatabaseValues(); }); - // only master is a valid system db reference for projects targetting Azure - if (this.project.getProjectTargetVersion().toLowerCase().includes('azure')) { + // only master is a valid system db reference for projects targetting Azure and DW + if (this.project.getProjectTargetVersion().toLowerCase().includes('azure') || this.project.getProjectTargetVersion().toLowerCase().includes('dw')) { this.systemDatabaseDropdown.values?.splice(1); } diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index 2a0a36a67a..9d920c2ff0 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -441,6 +441,13 @@ export class Project implements ISqlProject { */ public async changeTargetPlatform(compatLevel: string): Promise { if (this.getProjectTargetVersion() !== compatLevel) { + TelemetryReporter.createActionEvent(TelemetryViews.ProjectTree, TelemetryActions.changePlatformType) + .withAdditionalProperties({ + from: this.getProjectTargetVersion(), + to: compatLevel + }) + .send(); + const newDSP = `${constants.MicrosoftDatatoolsSchemaSqlSql}${compatLevel}${constants.databaseSchemaProvider}`; this.projFileXmlDoc.getElementsByTagName(constants.DSP)[0].childNodes[0].data = newDSP; this.projFileXmlDoc.getElementsByTagName(constants.DSP)[0].childNodes[0].nodeValue = newDSP; @@ -462,13 +469,6 @@ export class Project implements ISqlProject { } await this.serializeToProjFile(this.projFileXmlDoc); - - TelemetryReporter.createActionEvent(TelemetryViews.ProjectTree, TelemetryActions.changePlatformType) - .withAdditionalProperties({ - from: this.getProjectTargetVersion(), - to: compatLevel - }) - .send(); } } @@ -498,13 +498,21 @@ export class Project implements ISqlProject { } public getSystemDacpacUri(dacpac: string): Uri { - let version = this.getProjectTargetVersion(); - return Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', version, dacpac)); + const versionFolder = this.getSystemDacpacFolderName(); + return Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', versionFolder, dacpac)); } public getSystemDacpacSsdtUri(dacpac: string): Uri { - let version = this.getProjectTargetVersion(); - return Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', version, 'SqlSchemas', dacpac)); + const versionFolder = this.getSystemDacpacFolderName(); + return Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', versionFolder, 'SqlSchemas', dacpac)); + } + + public getSystemDacpacFolderName(): string { + const version = this.getProjectTargetVersion(); + + // DW is special because the target version is DW, but the folder name for system dacpacs is AzureDW in SSDT + // the other target versions have the same version name and folder name + return version === constants.targetPlatformToVersion.get(constants.sqlDW) ? constants.AzureDwFolder : version; } public getProjectTargetVersion(): string { diff --git a/extensions/sql-database-projects/src/test/project.test.ts b/extensions/sql-database-projects/src/test/project.test.ts index ec346c7fc0..de83aa1304 100644 --- a/extensions/sql-database-projects/src/test/project.test.ts +++ b/extensions/sql-database-projects/src/test/project.test.ts @@ -155,17 +155,23 @@ describe('Project: sqlproj content operations', function (): void { should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.masterDacpac)).fsPath); should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.masterDacpac)).fsPath); - project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!); + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!); uri = project.getSystemDacpacUri(constants.masterDacpac); ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac); should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.masterDacpac)).fsPath); should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '130', 'SqlSchemas', constants.masterDacpac)).fsPath); - project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!); + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!); uri = project.getSystemDacpacUri(constants.masterDacpac); ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac); should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureV12', constants.masterDacpac)).fsPath); should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.masterDacpac)).fsPath); + + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlDW)!); + uri = project.getSystemDacpacUri(constants.masterDacpac); + ssdtUri = project.getSystemDacpacSsdtUri(constants.masterDacpac); + should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureDw', constants.masterDacpac)).fsPath); + should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureDw', 'SqlSchemas', constants.masterDacpac)).fsPath); }); @@ -192,6 +198,11 @@ describe('Project: sqlproj content operations', function (): void { projFileText = await fs.readFile(projFilePath); should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureV12', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to AzureV12'); should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be AzureV12'); + + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlDW)!); + projFileText = await fs.readFile(projFilePath); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureDw', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to AzureDw'); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureDw', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be AzureDw'); }); it('Should choose correct msdb dacpac', async function (): Promise { @@ -203,7 +214,7 @@ describe('Project: sqlproj content operations', function (): void { should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.msdbDacpac)).fsPath); should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.msdbDacpac)).fsPath); - project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!); + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!); uri = project.getSystemDacpacUri(constants.msdbDacpac); ssdtUri = project.getSystemDacpacSsdtUri(constants.msdbDacpac); should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.msdbDacpac)).fsPath); @@ -214,7 +225,7 @@ describe('Project: sqlproj content operations', function (): void { projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline); const project = await Project.openProject(projFilePath); - project.changeTargetPlatform('invalidPlatform'); + await project.changeTargetPlatform('invalidPlatform'); await testUtils.shouldThrowSpecificError(async () => await project.getSystemDacpacUri(constants.masterDacpac), constants.invalidDataSchemaProvider); });