mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
Changes to add pre/post deploy script to sqlproj (#11864)
* Initial changes for adding pre/post deploy script in project * Right click > Add pre/post deploy script * Print script files in tree * Add new pre-post deploy items with their own tags and additional ones with None * Add tests * Fix error due to merge conflicts * Addressed comments and fixed tests. * Fix code scan error * Addressed comments
This commit is contained in:
@@ -7,6 +7,7 @@ import * as should from 'should';
|
||||
import * as path from 'path';
|
||||
import * as sinon from 'sinon';
|
||||
import * as baselines from './baselines/baselines';
|
||||
import * as templates from '../templates/templates';
|
||||
import * as testUtils from './testUtils';
|
||||
import * as constants from '../common/constants';
|
||||
|
||||
@@ -152,7 +153,7 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
project.changeDSP(TargetPlatform.SqlAzureV12.toString());
|
||||
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(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);
|
||||
});
|
||||
|
||||
@@ -231,6 +232,58 @@ describe('Project: sqlproj content operations', function (): void {
|
||||
await testUtils.shouldThrowSpecificError(async () => await project.addDatabaseReference(Uri.parse('test.dacpac'), DatabaseReferenceLocation.sameDatabase), constants.databaseReferenceAlreadyExists);
|
||||
should(project.databaseReferences.length).equal(2, 'There should be two database references after trying to add a reference to test.dacpac again');
|
||||
});
|
||||
|
||||
it('Should add pre and post deployment scripts as entries to sqlproj', async function (): Promise<void> {
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
const folderPath = 'Pre-Post Deployment Scripts';
|
||||
const preDeploymentScriptFilePath = path.join(folderPath, 'Script.PreDeployment1.sql');
|
||||
const postDeploymentScriptFilePath = path.join(folderPath, 'Script.PostDeployment1.sql');
|
||||
const fileContents = ' ';
|
||||
|
||||
await project.addFolderItem(folderPath);
|
||||
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, templates.preDeployScript);
|
||||
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, templates.postDeployScript);
|
||||
|
||||
const newProject = await Project.openProject(projFilePath);
|
||||
|
||||
should(newProject.preDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(preDeploymentScriptFilePath))).not.equal(undefined, 'File Script.PreDeployment1.sql not read');
|
||||
should(newProject.postDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(postDeploymentScriptFilePath))).not.equal(undefined, 'File Script.PostDeployment1.sql not read');
|
||||
});
|
||||
|
||||
it('Should show information messages when adding more than one pre/post deployment scripts to sqlproj', async function (): Promise<void> {
|
||||
const stub = sinon.stub(window, 'showInformationMessage').returns(<any>Promise.resolve());
|
||||
|
||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.newProjectFileBaseline);
|
||||
const project: Project = await Project.openProject(projFilePath);
|
||||
|
||||
const folderPath = 'Pre-Post Deployment Scripts';
|
||||
const preDeploymentScriptFilePath = path.join(folderPath, 'Script.PreDeployment1.sql');
|
||||
const postDeploymentScriptFilePath = path.join(folderPath, 'Script.PostDeployment1.sql');
|
||||
const preDeploymentScriptFilePath2 = path.join(folderPath, 'Script.PreDeployment2.sql');
|
||||
const postDeploymentScriptFilePath2 = path.join(folderPath, 'Script.PostDeployment2.sql');
|
||||
const fileContents = ' ';
|
||||
|
||||
await project.addFolderItem(folderPath);
|
||||
await project.addScriptItem(preDeploymentScriptFilePath, fileContents, templates.preDeployScript);
|
||||
await project.addScriptItem(postDeploymentScriptFilePath, fileContents, templates.postDeployScript);
|
||||
|
||||
await project.addScriptItem(preDeploymentScriptFilePath2, fileContents, templates.preDeployScript);
|
||||
should(stub.calledWith(constants.deployScriptExists(constants.PreDeploy))).be.true(`showInformationMessage not called with expected message '${constants.deployScriptExists(constants.PreDeploy)}' Actual '${stub.getCall(0).args[0]}'`);
|
||||
|
||||
await project.addScriptItem(postDeploymentScriptFilePath2, fileContents, templates.postDeployScript);
|
||||
should(stub.calledWith(constants.deployScriptExists(constants.PostDeploy))).be.true(`showInformationMessage not called with expected message '${constants.deployScriptExists(constants.PostDeploy)}' Actual '${stub.getCall(0).args[0]}'`);
|
||||
|
||||
const newProject = await Project.openProject(projFilePath);
|
||||
|
||||
should(newProject.preDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(preDeploymentScriptFilePath))).not.equal(undefined, 'File Script.PreDeployment1.sql not read');
|
||||
should(newProject.postDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(postDeploymentScriptFilePath))).not.equal(undefined, 'File Script.PostDeployment1.sql not read');
|
||||
should(newProject.noneDeployScripts.length).equal(2);
|
||||
should(newProject.noneDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(preDeploymentScriptFilePath2))).not.equal(undefined, 'File Script.PreDeployment2.sql not read');
|
||||
should(newProject.noneDeployScripts.find(f => f.type === EntryType.File && f.relativePath === convertSlashesForSqlProj(postDeploymentScriptFilePath2))).not.equal(undefined, 'File Script.PostDeployment2.sql not read');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('Project: round trip updates', function (): void {
|
||||
@@ -239,7 +292,7 @@ describe('Project: round trip updates', function (): void {
|
||||
});
|
||||
|
||||
it('Should update SSDT project to work in ADS', async function (): Promise<void> {
|
||||
await testUpdateInRoundTrip( baselines.SSDTProjectFileBaseline, baselines.SSDTProjectAfterUpdateBaseline, true, true);
|
||||
await testUpdateInRoundTrip(baselines.SSDTProjectFileBaseline, baselines.SSDTProjectAfterUpdateBaseline, true, true);
|
||||
});
|
||||
|
||||
it('Should update SSDT project with new system database references', async function (): Promise<void> {
|
||||
|
||||
@@ -243,6 +243,25 @@ describe('ProjectsController', function (): void {
|
||||
|
||||
should(await exists(scriptEntry.fsUri.fsPath)).equal(true, 'script is supposed to still exist on disk');
|
||||
});
|
||||
|
||||
it('Should be able to add pre deploy and post deploy script', async function (): Promise<void> {
|
||||
const preDeployScriptName = 'PreDeployScript1.sql';
|
||||
const postDeployScriptName = 'PostDeployScript1.sql';
|
||||
|
||||
const projController = new ProjectsController(new SqlDatabaseProjectTreeViewProvider());
|
||||
const project = await testUtils.createTestProject(baselines.newProjectFileBaseline);
|
||||
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(preDeployScriptName);
|
||||
should(project.preDeployScripts.length).equal(0, 'There should be no pre deploy scripts');
|
||||
await projController.addItemPrompt(project, '', templates.preDeployScript);
|
||||
should(project.preDeployScripts.length).equal(1, `Pre deploy script should be successfully added. ${project.preDeployScripts.length}, ${project.files.length}`);
|
||||
|
||||
sinon.restore();
|
||||
sinon.stub(vscode.window, 'showInputBox').resolves(postDeployScriptName);
|
||||
should(project.postDeployScripts.length).equal(0, 'There should be no post deploy scripts');
|
||||
await projController.addItemPrompt(project, '', templates.postDeployScript);
|
||||
should(project.postDeployScripts.length).equal(1, 'Post deploy script should be successfully added');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Publishing and script generation', function (): void {
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('Templates: loading templates from disk', function (): void {
|
||||
|
||||
// check expected counts
|
||||
|
||||
const numScriptObjectTypes = 4;
|
||||
const numScriptObjectTypes = 6;
|
||||
|
||||
should(templates.projectScriptTypes().length).equal(numScriptObjectTypes);
|
||||
should(Object.keys(templates.projectScriptTypes()).length).equal(numScriptObjectTypes);
|
||||
|
||||
Reference in New Issue
Block a user