mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
fix pre/post deploy scripts getting double counted in the files for sdk style projects (#17954)
* fix pre/post deploy scripts getting double counted in the files for sdk style projects * add test * update comment
This commit is contained in:
@@ -122,13 +122,15 @@ export class Project implements ISqlProject {
|
|||||||
// check if this is an sdk style project https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview
|
// check if this is an sdk style project https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview
|
||||||
this._isSdkStyleProject = this.CheckForSdkStyleProject();
|
this._isSdkStyleProject = this.CheckForSdkStyleProject();
|
||||||
|
|
||||||
|
// get pre and post deploy scripts specified in the sqlproj
|
||||||
|
this._preDeployScripts = this.readPreDeployScripts();
|
||||||
|
this._postDeployScripts = this.readPostDeployScripts();
|
||||||
|
this._noneDeployScripts = this.readNoneDeployScripts();
|
||||||
|
|
||||||
// get files and folders
|
// get files and folders
|
||||||
this._files = await this.readFilesInProject();
|
this._files = await this.readFilesInProject();
|
||||||
this.files.push(...await this.readFolders());
|
this.files.push(...await this.readFolders());
|
||||||
|
|
||||||
this._preDeployScripts = this.readPreDeployScripts();
|
|
||||||
this._postDeployScripts = this.readPostDeployScripts();
|
|
||||||
this._noneDeployScripts = this.readNoneDeployScripts();
|
|
||||||
this._databaseReferences = this.readDatabaseReferences();
|
this._databaseReferences = this.readDatabaseReferences();
|
||||||
this._importedTargets = this.readImportedTargets();
|
this._importedTargets = this.readImportedTargets();
|
||||||
|
|
||||||
@@ -225,6 +227,13 @@ export class Project implements ISqlProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.isSdkStyleProject) {
|
||||||
|
// remove any pre/post/none deploy scripts that were specified in the sqlproj so they aren't counted twice
|
||||||
|
this.preDeployScripts.forEach(f => filesSet.delete(f.relativePath));
|
||||||
|
this.postDeployScripts.forEach(f => filesSet.delete(f.relativePath));
|
||||||
|
this.noneDeployScripts.forEach(f => filesSet.delete(f.relativePath));
|
||||||
|
}
|
||||||
|
|
||||||
// create a FileProjectEntry for each file
|
// create a FileProjectEntry for each file
|
||||||
const fileEntries: FileProjectEntry[] = [];
|
const fileEntries: FileProjectEntry[] = [];
|
||||||
filesSet.forEach(f => {
|
filesSet.forEach(f => {
|
||||||
|
|||||||
@@ -20,6 +20,13 @@
|
|||||||
<Build Include="..\other\file1.sql" />
|
<Build Include="..\other\file1.sql" />
|
||||||
<Build Include="folder1\*.sql" />
|
<Build Include="folder1\*.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PreDeploy Include="..\other\folder2\Script.PreDeployment1.sql" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PostDeploy Include="..\other\folder2\Script.PostDeployment1.sql" />
|
||||||
|
<None Include="..\other\folder2\Script.PostDeployment2.sql" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\150\master.dacpac">
|
<ArtifactReference Condition="'$(NetCoreBuild)' == 'true'" Include="$(NETCoreTargetsPath)\SystemDacpacs\150\master.dacpac">
|
||||||
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
<SuppressMissingDependenciesErrors>False</SuppressMissingDependenciesErrors>
|
||||||
|
|||||||
@@ -844,7 +844,7 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
|
|
||||||
// Files and folders
|
// Files and folders
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
|
||||||
|
|
||||||
// SqlCmdVariables
|
// SqlCmdVariables
|
||||||
should(Object.keys(project.sqlCmdVariables).length).equal(2);
|
should(Object.keys(project.sqlCmdVariables).length).equal(2);
|
||||||
@@ -883,6 +883,27 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
should(project.files.filter(f => f.relativePath === 'folder1\\').length).equal(1);
|
should(project.files.filter(f => f.relativePath === 'folder1\\').length).equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should handle pre/post/none deploy scripts outside of project folder', async function (): Promise<void> {
|
||||||
|
const testFolderPath = await testUtils.generateTestFolderPath();
|
||||||
|
const mainProjectPath = path.join(testFolderPath, 'project');
|
||||||
|
const otherFolderPath = path.join(testFolderPath, 'other');
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectWithGlobsSpecifiedBaseline, mainProjectPath);
|
||||||
|
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
|
||||||
|
|
||||||
|
// create files outside of project folder that are included in the project file
|
||||||
|
await fs.mkdir(otherFolderPath);
|
||||||
|
await testUtils.createOtherDummyFiles(otherFolderPath);
|
||||||
|
|
||||||
|
const project: Project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
|
// verify files, folders, pre/post/none deploy scripts were loaded correctly
|
||||||
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
|
||||||
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(18);
|
||||||
|
should(project.preDeployScripts.length).equal(1);
|
||||||
|
should(project.postDeployScripts.length).equal(1);
|
||||||
|
should(project.noneDeployScripts.length).equal(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('Should handle globbing patterns listed in sqlproj', async function (): Promise<void> {
|
it('Should handle globbing patterns listed in sqlproj', async function (): Promise<void> {
|
||||||
const testFolderPath = await testUtils.generateTestFolderPath();
|
const testFolderPath = await testUtils.generateTestFolderPath();
|
||||||
const mainProjectPath = path.join(testFolderPath, 'project');
|
const mainProjectPath = path.join(testFolderPath, 'project');
|
||||||
@@ -1056,15 +1077,17 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
|
|
||||||
const project: Project = await Project.openProject(projFilePath);
|
const project: Project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
||||||
|
should(project.noneDeployScripts.length).equal(2);
|
||||||
|
|
||||||
// try to exclude a glob included folder
|
// try to exclude a glob included folder
|
||||||
await project.exclude(project.files.find(f => f.relativePath === 'folder1\\')!);
|
await project.exclude(project.files.find(f => f.relativePath === 'folder1\\')!);
|
||||||
|
|
||||||
// verify folder and contents are excluded
|
// verify folder and contents are excluded
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(1);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(1);
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(9);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(6);
|
||||||
|
should(project.noneDeployScripts.length).equal(1, 'Script.PostDeployment2.sql should have been excluded');
|
||||||
should(project.files.find(f => f.relativePath === 'folder1\\')).equal(undefined);
|
should(project.files.find(f => f.relativePath === 'folder1\\')).equal(undefined);
|
||||||
|
|
||||||
// verify sqlproj has glob exclude for folder, but not for files and inner folder
|
// verify sqlproj has glob exclude for folder, but not for files and inner folder
|
||||||
@@ -1082,7 +1105,7 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
|
|
||||||
const project: Project = await Project.openProject(projFilePath);
|
const project: Project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(17);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(13);
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(3);
|
||||||
|
|
||||||
// try to exclude a glob included folder
|
// try to exclude a glob included folder
|
||||||
@@ -1090,7 +1113,7 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
|
|
||||||
// verify folder and contents are excluded
|
// verify folder and contents are excluded
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(2);
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(15);
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(11);
|
||||||
should(project.files.find(f => f.relativePath === 'folder1\\nestedFolder\\')).equal(undefined);
|
should(project.files.find(f => f.relativePath === 'folder1\\nestedFolder\\')).equal(undefined);
|
||||||
|
|
||||||
// verify sqlproj has glob exclude for folder, but not for files
|
// verify sqlproj has glob exclude for folder, but not for files
|
||||||
|
|||||||
@@ -198,6 +198,9 @@ export async function createListOfFiles(filePath?: string): Promise<Uri[]> {
|
|||||||
* - folder2
|
* - folder2
|
||||||
* -file1.sql
|
* -file1.sql
|
||||||
* -file2.sql
|
* -file2.sql
|
||||||
|
* - Script.PreDeployment1.sql
|
||||||
|
* - Script.PostDeployment1.sql
|
||||||
|
* - Script.PostDeployment2.sql
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export async function createOtherDummyFiles(testFolderPath: string): Promise<string> {
|
export async function createOtherDummyFiles(testFolderPath: string): Promise<string> {
|
||||||
@@ -221,5 +224,13 @@ export async function createOtherDummyFiles(testFolderPath: string): Promise<str
|
|||||||
const testLongerName = path.join(testFolderPath, 'folder1', 'testLongerName.sql');
|
const testLongerName = path.join(testFolderPath, 'folder1', 'testLongerName.sql');
|
||||||
await fs.writeFile(testLongerName, '');
|
await fs.writeFile(testLongerName, '');
|
||||||
|
|
||||||
|
const preDeploymentScript = path.join(testFolderPath, 'folder2', 'Script.PreDeployment1.sql');
|
||||||
|
await fs.writeFile(preDeploymentScript, '');
|
||||||
|
|
||||||
|
const postDeploymentScript1 = path.join(testFolderPath, 'folder2', 'Script.PostDeployment1.sql');
|
||||||
|
await fs.writeFile(postDeploymentScript1, '');
|
||||||
|
|
||||||
|
const postDeploymentScript2 = path.join(testFolderPath, 'folder2', 'Script.PostDeployment2.sql');
|
||||||
|
await fs.writeFile(postDeploymentScript2, '');
|
||||||
return testFolderPath;
|
return testFolderPath;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user