mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
Update system database references from SSDT (#10891)
* convert system database references from SSDT * remove empty ItemGroup if no other database references * fix baseline files * also update sqlproj if system database references were added in SSDT since the sqlproj got updated with ADS imports * undo change * move updating system db references out of updateProjectForRoundTrip() * update test to have an already updated system db ref * add clean target after merge from master * add await * addressing comments
This commit is contained in:
@@ -329,6 +329,39 @@ export class Project {
|
||||
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||
}
|
||||
|
||||
public containsSSDTOnlySystemDatabaseReferences(): boolean {
|
||||
for (let r = 0; r < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length; r++) {
|
||||
const currentNode = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference)[r];
|
||||
if (!currentNode.getAttribute(constants.NetCoreCondition) && currentNode.getAttribute(constants.Include).includes(constants.DacpacRootPath)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public async updateSystemDatabaseReferencesInProjFile(): Promise<void> {
|
||||
// find all system database references
|
||||
for (let r = 0; r < this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length; r++) {
|
||||
const currentNode = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference)[r];
|
||||
if (!currentNode.getAttribute(constants.Condition) && currentNode.getAttribute(constants.Include).includes(constants.DacpacRootPath)) {
|
||||
// get name of system database
|
||||
const name = currentNode.getAttribute(constants.Include).includes(constants.master) ? SystemDatabase.master : SystemDatabase.msdb;
|
||||
this.projFileXmlDoc.documentElement.removeChild(currentNode);
|
||||
|
||||
// delete ItemGroup if there aren't any other children
|
||||
if (this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference).length === 0) {
|
||||
this.projFileXmlDoc.documentElement.removeChild(currentNode.parentNode);
|
||||
}
|
||||
|
||||
// remove from database references because it'll get added again later
|
||||
this.databaseReferences.splice(this.databaseReferences.findIndex(n => n === (name ? constants.master : constants.msdb)), 1);
|
||||
|
||||
await this.addSystemDatabaseReference(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async addToProjFile(entry: ProjectEntry) {
|
||||
switch (entry.type) {
|
||||
case EntryType.File:
|
||||
|
||||
Reference in New Issue
Block a user