Files
azuredatastudio/extensions/sql-database-projects/src/sqldbproj.d.ts
Alexander Ivanov c6fec97819 Expose default database collation through 'sql-database-projects' extension API (#15538)
* Expose default database collation through 'sql-database-projects' extension API.

For the purpose of schema conversion we would need to know whether target database is configured as CI or CS. This will be used to produce a warning, if we detect a case-sensitive identifier, but database is configured as CI. In order to support this scenario we need to access `<DefaultCollation/>` property of the project.

This change adds new method to the `ISqlProject` interface that allows to read the value of the project property. There already was similar method for the SQL version/platform (`<DSP/>` property) and while working on the change, I took an opportunity to refactor the way project properties are extracted from the XML. Original code was hardcoded in the `getProjectTargetVersion` and I extracted it into separate `evaluateProjectPropertyValue` helper, that can be used in the future by any getter or access method that is supposed to return a value of the single property. This also allows us to improve the way properties are retrieved from the XML. Today the logic is very rudimentary - we read the first matching XML element with the required name. This is not correct as it does not verify the parent to be `<PropertyGroup/>`, neither it evaluates the `Condition` attributes nor property value itself. I did not invest in this, but added a TODO there explaining that the method may not perform as expected.

After the helper method was added, I updated the existing `getProjectTargetVersion` method to leverage it. The only complication here was the error throwing logic, as it was using custom error message. I preserved that, as there were tests verifying it already. For the new accessor method I did not introduce a special error message and rely on generic one I defined for use within the helper method. Additionally, for the collation we return default value of `SQL_Latin1_General_CP1_CI_AS`, if project does not have the property defined. This is what SSDT for Visual Studio shows in the UI when property is missing and I decided to align with that.

Finally, I added tests for both - original `getProjectTargetVersion` and new collation extraction method to make sure they work as expected. While working on the tests, I've noticed complaints that some rejected promises were not awaited. I added missing `await`s.
2021-05-28 12:42:21 -07:00

134 lines
4.2 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'sqldbproj' {
import * as vscode from 'vscode';
export const enum extension {
name = 'Microsoft.sql-database-projects'
}
/**
* sql database projects extension
*/
export interface IExtension {
/**
* Create a project
* @param name name of the project
* @param location the parent directory
* @param projectTypeId the ID of the project/template
* @returns Uri of the newly created project file
*/
createProject(name: string, location: vscode.Uri, projectTypeId: string): Promise<vscode.Uri>;
/**
* Opens and loads a .sqlproj file
*/
openProject(projectFilePath: string): Promise<ISqlProject>;
}
export interface ISqlProject {
/**
* Reads the project setting and contents from the file
*/
readProjFile(): Promise<void>;
/**
* Adds the list of sql files and directories to the project, and saves the project file
* @param list list of files and folder Uris. Files and folders must already exist. No files or folders will be added if any do not exist.
* @param doNotThrowOnDuplicate Flag that indicates whether duplicate entries should be ignored or throw an error.
*/
addToProject(list: vscode.Uri[], doNotThrowOnDuplicate?: boolean): Promise<void>;
/**
* Adds a folder to the project, and saves the project file
* @param relativeFolderPath Relative path of the folder
* @param doNotThrowOnDuplicate
* Flag that indicates whether duplicate entries should be ignored or throw an error. If flag is set to `true` and
* item already exists in the project file, then existing entry will be returned.
*/
addFolderItem(relativeFolderPath: string, doNotThrowOnDuplicate?: boolean): Promise<IFileProjectEntry>;
/**
* Writes a file to disk if contents are provided, adds that file to the project, and writes it to disk
* @param relativeFilePath Relative path of the file
* @param contents Contents to be written to the new file
* @param itemType Type of the project entry to add. This maps to the build action for the item.
* @param doNotThrowOnDuplicate
* Flag that indicates whether duplicate entries should be ignored or throw an error. If flag is set to `true` and
* item already exists in the project file, then existing entry will be returned.
*/
addScriptItem(relativeFilePath: string, contents?: string, itemType?: string, doNotThrowOnDuplicate?: boolean): Promise<IFileProjectEntry>;
/**
* Adds a SQLCMD variable to the project
* @param name name of the variable
* @param defaultValue
*/
addSqlCmdVariable(name: string, defaultValue: string): Promise<void>;
/**
* Excludes entry from project by removing it from the project file
* @param entry
*/
exclude(entry: IFileProjectEntry): Promise<void>;
/**
* Deletes file or folder and removes it from the project file
* @param entry
*/
deleteFileFolder(entry: IFileProjectEntry): Promise<void>;
/**
* returns the sql version the project is targeting
*/
getProjectTargetVersion(): string;
/**
* Gets the default database collation set in the project.
*
* @returns Default collation for the database set in the project.
*/
getDatabaseDefaultCollation(): string;
/**
* Path where dacpac is output to after a successful build
*/
readonly dacpacOutputPath: string;
/**
* Path to folder containing the project file
*/
readonly projectFolderPath: string;
/**
* Project file path
*/
readonly projectFilePath: string;
/**
* Project file name
*/
readonly projectFileName: string;
/**
* Files and folders that are included in the project
*/
readonly files: IFileProjectEntry[];
/**
* SqlCmd variables and their values
*/
readonly sqlCmdVariables: Record<string, string>;
}
/**
* Represents an entry in a project file
*/
export interface IFileProjectEntry {
fsUri: vscode.Uri;
relativePath: string;
}
}