mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
load publish profile sqlcmd "value" tag and throw error if not loaded correctly (#11615)
* load publish profile sqlcmd "value" tag and throw error if not loaded correctly * moved the read profile function to utils
This commit is contained in:
@@ -78,6 +78,7 @@ export const dataSourceDropdownTitle = localize('dataSourceDropdownTitle', "Data
|
|||||||
export const noDataSourcesText = localize('noDataSourcesText', "No data sources in this project");
|
export const noDataSourcesText = localize('noDataSourcesText', "No data sources in this project");
|
||||||
export const loadProfileButtonText = localize('loadProfileButtonText', "Load Profile...");
|
export const loadProfileButtonText = localize('loadProfileButtonText', "Load Profile...");
|
||||||
export const profileWarningText = localize('profileWarningText', "⚠ Warning: Connection strings using AAD Authentication are not supported at this time");
|
export const profileWarningText = localize('profileWarningText', "⚠ Warning: Connection strings using AAD Authentication are not supported at this time");
|
||||||
|
export const profileReadError = localize('profileReadError', "Could not load the profile file.");
|
||||||
export const sqlCmdTableLabel = localize('sqlCmdTableLabel', "SQLCMD Variables");
|
export const sqlCmdTableLabel = localize('sqlCmdTableLabel', "SQLCMD Variables");
|
||||||
export const sqlCmdVariableColumn = localize('sqlCmdVariableColumn', "Variable");
|
export const sqlCmdVariableColumn = localize('sqlCmdVariableColumn', "Variable");
|
||||||
export const sqlCmdValueColumn = localize('sqlCmdValueColumn', "Value");
|
export const sqlCmdValueColumn = localize('sqlCmdValueColumn', "Value");
|
||||||
@@ -158,6 +159,7 @@ export const Version = 'Version';
|
|||||||
export const PrivateAssets = 'PrivateAssets';
|
export const PrivateAssets = 'PrivateAssets';
|
||||||
export const SqlCmdVariable = 'SqlCmdVariable';
|
export const SqlCmdVariable = 'SqlCmdVariable';
|
||||||
export const DefaultValue = 'DefaultValue';
|
export const DefaultValue = 'DefaultValue';
|
||||||
|
export const Value = 'Value';
|
||||||
export const ArtifactReference = 'ArtifactReference';
|
export const ArtifactReference = 'ArtifactReference';
|
||||||
export const SuppressMissingDependenciesErrors = 'SuppressMissingDependenciesErrors';
|
export const SuppressMissingDependenciesErrors = 'SuppressMissingDependenciesErrors';
|
||||||
export const DatabaseVariableLiteralValue = 'DatabaseVariableLiteralValue';
|
export const DatabaseVariableLiteralValue = 'DatabaseVariableLiteralValue';
|
||||||
|
|||||||
@@ -127,12 +127,18 @@ export function convertSlashesForSqlProj(filePath: string): string {
|
|||||||
*/
|
*/
|
||||||
export function readSqlCmdVariables(xmlDoc: any): Record<string, string> {
|
export function readSqlCmdVariables(xmlDoc: any): Record<string, string> {
|
||||||
let sqlCmdVariables: Record<string, string> = {};
|
let sqlCmdVariables: Record<string, string> = {};
|
||||||
for (let i = 0; i < xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable).length; i++) {
|
for (let i = 0; i < xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)?.length; i++) {
|
||||||
const sqlCmdVar = xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)[i];
|
const sqlCmdVar = xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)[i];
|
||||||
const varName = sqlCmdVar.getAttribute(constants.Include);
|
const varName = sqlCmdVar.getAttribute(constants.Include);
|
||||||
|
|
||||||
const varValue = sqlCmdVar.getElementsByTagName(constants.DefaultValue)[0].childNodes[0].nodeValue;
|
if (sqlCmdVar.getElementsByTagName(constants.DefaultValue)[0] !== undefined) {
|
||||||
sqlCmdVariables[varName] = varValue;
|
// project file path
|
||||||
|
sqlCmdVariables[varName] = sqlCmdVar.getElementsByTagName(constants.DefaultValue)[0].childNodes[0].nodeValue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// profile path
|
||||||
|
sqlCmdVariables[varName] = sqlCmdVar.getElementsByTagName(constants.Value)[0].childNodes[0].nodeValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sqlCmdVariables;
|
return sqlCmdVariables;
|
||||||
|
|||||||
@@ -231,10 +231,16 @@ export class ProjectsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async readPublishProfileCallback(profileUri: vscode.Uri): Promise<PublishProfile> {
|
public async readPublishProfileCallback(profileUri: vscode.Uri): Promise<PublishProfile> {
|
||||||
|
try {
|
||||||
const dacFxService = await this.getDaxFxService();
|
const dacFxService = await this.getDaxFxService();
|
||||||
const profile = await load(profileUri, dacFxService);
|
const profile = await load(profileUri, dacFxService);
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
|
catch (e) {
|
||||||
|
vscode.window.showErrorMessage(constants.profileReadError);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async schemaCompare(treeNode: BaseProjectTreeItem): Promise<void> {
|
public async schemaCompare(treeNode: BaseProjectTreeItem): Promise<void> {
|
||||||
// check if schema compare extension is installed
|
// check if schema compare extension is installed
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import * as os from 'os';
|
|||||||
import { Uri } from 'vscode';
|
import { Uri } from 'vscode';
|
||||||
import { promises as fs } from 'fs';
|
import { promises as fs } from 'fs';
|
||||||
import { DataSource } from './dataSources/dataSources';
|
import { DataSource } from './dataSources/dataSources';
|
||||||
import { readSqlCmdVariables } from './publishProfile/publishProfile';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class representing a Project, and providing functions for operating on it
|
* Class representing a Project, and providing functions for operating on it
|
||||||
@@ -81,7 +80,7 @@ export class Project {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// find all SQLCMD variables to include
|
// find all SQLCMD variables to include
|
||||||
this.sqlCmdVariables = readSqlCmdVariables(this.projFileXmlDoc);
|
this.sqlCmdVariables = utils.readSqlCmdVariables(this.projFileXmlDoc);
|
||||||
|
|
||||||
// find all database references to include
|
// find all database references to include
|
||||||
const references = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference);
|
const references = this.projFileXmlDoc.documentElement.getElementsByTagName(constants.ArtifactReference);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export async function load(profileUri: Uri, dacfxService: mssql.IDacFxService):
|
|||||||
const optionsResult = await dacfxService.getOptionsFromProfile(profileUri.fsPath);
|
const optionsResult = await dacfxService.getOptionsFromProfile(profileUri.fsPath);
|
||||||
|
|
||||||
// get all SQLCMD variables to include from the profile
|
// get all SQLCMD variables to include from the profile
|
||||||
const sqlCmdVariables = readSqlCmdVariables(profileXmlDoc);
|
const sqlCmdVariables = utils.readSqlCmdVariables(profileXmlDoc);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
databaseName: targetDbName,
|
databaseName: targetDbName,
|
||||||
@@ -52,22 +52,6 @@ export async function load(profileUri: Uri, dacfxService: mssql.IDacFxService):
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Read SQLCMD variables from xmlDoc and return them
|
|
||||||
* @param xmlDoc xml doc to read SQLCMD variables from. Format must be the same that sqlproj and publish profiles use
|
|
||||||
*/
|
|
||||||
export function readSqlCmdVariables(xmlDoc: any): Record<string, string> {
|
|
||||||
let sqlCmdVariables: Record<string, string> = {};
|
|
||||||
for (let i = 0; i < xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)?.length; i++) {
|
|
||||||
const sqlCmdVar = xmlDoc.documentElement.getElementsByTagName(constants.SqlCmdVariable)[i];
|
|
||||||
const varName = sqlCmdVar.getAttribute(constants.Include);
|
|
||||||
|
|
||||||
const varValue = sqlCmdVar.getElementsByTagName(constants.DefaultValue)[0].childNodes[0].nodeValue;
|
|
||||||
sqlCmdVariables[varName] = varValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sqlCmdVariables;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function readConnectionString(xmlDoc: any): Promise<{ connectionId: string, connectionString: string }> {
|
async function readConnectionString(xmlDoc: any): Promise<{ connectionId: string, connectionString: string }> {
|
||||||
let targetConnectionString: string = '';
|
let targetConnectionString: string = '';
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SqlCmdVariable Include="ProdDatabaseName">
|
<SqlCmdVariable Include="ProdDatabaseName">
|
||||||
<DefaultValue>MyProdDatabase</DefaultValue>
|
<Value>MyProdDatabase</Value>
|
||||||
<Value>$(SqlCmdVar__1)</Value>
|
|
||||||
</SqlCmdVariable>
|
</SqlCmdVariable>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<SqlCmdVariable Include="ProdDatabaseName">
|
<SqlCmdVariable Include="ProdDatabaseName">
|
||||||
<DefaultValue>MyProdDatabase</DefaultValue>
|
<Value>MyProdDatabase</Value>
|
||||||
<Value>$(SqlCmdVar__1)</Value>
|
|
||||||
</SqlCmdVariable>
|
</SqlCmdVariable>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user