From 5e168b0960bfc06e2c40a0d402c396cea7f2140a Mon Sep 17 00:00:00 2001 From: Kim Santiago <31145923+kisantia@users.noreply.github.com> Date: Thu, 11 Feb 2021 14:00:07 -0800 Subject: [PATCH] fix system db references going away when project target platform is changed (#14255) * fix system db references going away when target platform is changed * bump version --- extensions/sql-database-projects/package.json | 2 +- .../src/models/project.ts | 6 ++-- .../src/test/project.test.ts | 32 +++++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/extensions/sql-database-projects/package.json b/extensions/sql-database-projects/package.json index 0efb9d9975..63f660d557 100644 --- a/extensions/sql-database-projects/package.json +++ b/extensions/sql-database-projects/package.json @@ -2,7 +2,7 @@ "name": "sql-database-projects", "displayName": "SQL Database Projects", "description": "The SQL Database Projects extension for Azure Data Studio allows users to develop and publish database schemas.", - "version": "0.6.0", + "version": "0.6.1", "publisher": "Microsoft", "preview": true, "engines": { diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index 6898737536..de1d822ff7 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -376,7 +376,7 @@ export class Project { // update any system db references const systemDbReferences = this.databaseReferences.filter(r => r instanceof SystemDatabaseReferenceProjectEntry) as SystemDatabaseReferenceProjectEntry[]; if (systemDbReferences.length > 0) { - systemDbReferences.forEach((r) => { + for (let r of systemDbReferences) { // remove old entry in sqlproj this.removeDatabaseReferenceFromProjFile(r); @@ -385,8 +385,8 @@ export class Project { r.ssdtUri = this.getSystemDacpacSsdtUri(`${r.databaseName}.dacpac`); // add updated system db reference to sqlproj - this.addDatabaseReferenceToProjFile(r); - }); + await this.addDatabaseReferenceToProjFile(r); + } } await this.serializeToProjFile(this.projFileXmlDoc); diff --git a/extensions/sql-database-projects/src/test/project.test.ts b/extensions/sql-database-projects/src/test/project.test.ts index a6fea27fbb..d2f79222e3 100644 --- a/extensions/sql-database-projects/src/test/project.test.ts +++ b/extensions/sql-database-projects/src/test/project.test.ts @@ -168,6 +168,32 @@ describe('Project: sqlproj content operations', function (): void { should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.masterDacpac)).fsPath); }); + + it('Should update system dacpac paths in sqlproj when target platform is changed', async function (): Promise { + projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline); + const project = await Project.openProject(projFilePath); + await project.addSystemDatabaseReference({ + systemDb: SystemDatabase.master, + suppressMissingDependenciesErrors: false + }); + + let projFileText = await fs.readFile(projFilePath); + + should.equal(project.databaseReferences.length, 1, 'System db reference should have been added'); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '150', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should be 150'); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '150', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be 150'); + + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlServer2016)!); + projFileText = await fs.readFile(projFilePath); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db reference path should have been updated to 130'); + should(projFileText.includes(convertSlashesForSqlProj(Uri.file(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '130', 'SqlSchemas', constants.masterDacpac)).fsPath.substring(1)))).be.true('System db SSDT reference path should be 130'); + + await project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!); + 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'); + }); + it('Should choose correct msdb dacpac', async function (): Promise { projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline); const project = await Project.openProject(projFilePath); @@ -182,12 +208,6 @@ describe('Project: sqlproj content operations', function (): void { ssdtUri = project.getSystemDacpacSsdtUri(constants.msdbDacpac); should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', '130', constants.msdbDacpac)).fsPath); should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', '130', 'SqlSchemas', constants.msdbDacpac)).fsPath); - - project.changeTargetPlatform(constants.targetPlatformToVersion.get(constants.sqlAzure)!); - uri = project.getSystemDacpacUri(constants.msdbDacpac); - ssdtUri = project.getSystemDacpacSsdtUri(constants.msdbDacpac); - should.equal(uri.fsPath, Uri.parse(path.join('$(NETCoreTargetsPath)', 'SystemDacpacs', 'AzureV12', constants.msdbDacpac)).fsPath); - should.equal(ssdtUri.fsPath, Uri.parse(path.join('$(DacPacRootPath)', 'Extensions', 'Microsoft', 'SQLDB', 'Extensions', 'SqlServer', 'AzureV12', 'SqlSchemas', constants.msdbDacpac)).fsPath); }); it('Should throw error when choosing correct master dacpac if invalid DSP', async function (): Promise {