mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Sqlproj - Saving the connection after db is deployed to docker container (#17294)
This commit is contained in:
@@ -27,5 +27,6 @@ export interface ILocalDbSetting {
|
|||||||
password: string,
|
password: string,
|
||||||
dbName: string,
|
dbName: string,
|
||||||
dockerBaseImage: string,
|
dockerBaseImage: string,
|
||||||
connectionRetryTimeout?: number
|
connectionRetryTimeout?: number,
|
||||||
|
profileName?: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class DeployService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DefaultSqlRetryTimeoutInSec: number = 10;
|
private DefaultSqlRetryTimeoutInSec: number = 10;
|
||||||
private DefaultSqlNumberOfRetries: number = 10;
|
private DefaultSqlNumberOfRetries: number = 3;
|
||||||
|
|
||||||
private createConnectionStringTemplate(runtime: string | undefined): string {
|
private createConnectionStringTemplate(runtime: string | undefined): string {
|
||||||
switch (runtime?.toLocaleLowerCase()) {
|
switch (runtime?.toLocaleLowerCase()) {
|
||||||
@@ -137,6 +137,13 @@ export class DeployService {
|
|||||||
const dockerFilePath = path.join(mssqlFolderPath, constants.dockerFileName);
|
const dockerFilePath = path.join(mssqlFolderPath, constants.dockerFileName);
|
||||||
const startFilePath = path.join(commandsFolderPath, constants.startCommandName);
|
const startFilePath = path.join(commandsFolderPath, constants.startCommandName);
|
||||||
|
|
||||||
|
|
||||||
|
// If profile name is not set use the docker name to have a unique name
|
||||||
|
if (!profile.localDbSetting.profileName) {
|
||||||
|
profile.localDbSetting.profileName = imageSpec.containerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logToOutput(constants.cleaningDockerImagesMessage);
|
||||||
// Clean up existing docker image
|
// Clean up existing docker image
|
||||||
const containerIds = await this.getCurrentDockerContainer(imageSpec.label);
|
const containerIds = await this.getCurrentDockerContainer(imageSpec.label);
|
||||||
if (containerIds.length > 0) {
|
if (containerIds.length > 0) {
|
||||||
@@ -218,7 +225,7 @@ export class DeployService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connects to a database
|
// Connects to a database
|
||||||
private async connectToDatabase(profile: ILocalDbSetting, savePassword: boolean, database: string): Promise<ConnectionResult | string | undefined> {
|
private async connectToDatabase(profile: ILocalDbSetting, saveConnectionAndPassword: boolean, database: string): Promise<ConnectionResult | string | undefined> {
|
||||||
const getAzdataApi = await utils.getAzdataApi();
|
const getAzdataApi = await utils.getAzdataApi();
|
||||||
const vscodeMssqlApi = getAzdataApi ? undefined : await utils.getVscodeMssqlApi();
|
const vscodeMssqlApi = getAzdataApi ? undefined : await utils.getVscodeMssqlApi();
|
||||||
if (getAzdataApi) {
|
if (getAzdataApi) {
|
||||||
@@ -226,12 +233,12 @@ export class DeployService {
|
|||||||
password: profile.password,
|
password: profile.password,
|
||||||
serverName: `${profile.serverName},${profile.port}`,
|
serverName: `${profile.serverName},${profile.port}`,
|
||||||
database: database,
|
database: database,
|
||||||
savePassword: savePassword,
|
savePassword: saveConnectionAndPassword,
|
||||||
userName: profile.userName,
|
userName: profile.userName,
|
||||||
providerName: 'MSSQL',
|
providerName: 'MSSQL',
|
||||||
saveProfile: false,
|
saveProfile: false,
|
||||||
id: '',
|
id: '',
|
||||||
connectionName: `${constants.connectionNamePrefix} ${database}`,
|
connectionName: `${profile.profileName}`,
|
||||||
options: [],
|
options: [],
|
||||||
authenticationType: 'SqlLogin'
|
authenticationType: 'SqlLogin'
|
||||||
};
|
};
|
||||||
@@ -242,7 +249,7 @@ export class DeployService {
|
|||||||
server: `${profile.serverName}`,
|
server: `${profile.serverName}`,
|
||||||
port: profile.port,
|
port: profile.port,
|
||||||
database: database,
|
database: database,
|
||||||
savePassword: savePassword,
|
savePassword: saveConnectionAndPassword,
|
||||||
user: profile.userName,
|
user: profile.userName,
|
||||||
authenticationType: 'SqlLogin',
|
authenticationType: 'SqlLogin',
|
||||||
encrypt: false,
|
encrypt: false,
|
||||||
@@ -269,9 +276,10 @@ export class DeployService {
|
|||||||
replication: undefined,
|
replication: undefined,
|
||||||
trustServerCertificate: undefined,
|
trustServerCertificate: undefined,
|
||||||
typeSystemVersion: undefined,
|
typeSystemVersion: undefined,
|
||||||
workstationId: undefined
|
workstationId: undefined,
|
||||||
|
profileName: profile.profileName
|
||||||
};
|
};
|
||||||
let connectionUrl = await vscodeMssqlApi.connect(connectionProfile);
|
let connectionUrl = await vscodeMssqlApi.connect(connectionProfile, saveConnectionAndPassword);
|
||||||
return connectionUrl;
|
return connectionUrl;
|
||||||
} else {
|
} else {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -304,12 +312,12 @@ export class DeployService {
|
|||||||
return connectionResult ? connectionResult.connectionId : <string>connection;
|
return connectionResult ? connectionResult.connectionId : <string>connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getConnection(profile: ILocalDbSetting, savePassword: boolean, database: string): Promise<string | undefined> {
|
public async getConnection(profile: ILocalDbSetting, saveConnectionAndPassword: boolean, database: string): Promise<string | undefined> {
|
||||||
const getAzdataApi = await utils.getAzdataApi();
|
const getAzdataApi = await utils.getAzdataApi();
|
||||||
let connection = await utils.retry(
|
let connection = await utils.retry(
|
||||||
constants.connectingToSqlServerOnDockerMessage,
|
constants.connectingToSqlServerOnDockerMessage,
|
||||||
async () => {
|
async () => {
|
||||||
return await this.connectToDatabase(profile, savePassword, database);
|
return await this.connectToDatabase(profile, saveConnectionAndPassword, database);
|
||||||
},
|
},
|
||||||
this.validateConnection,
|
this.validateConnection,
|
||||||
this.formatConnectionResult,
|
this.formatConnectionResult,
|
||||||
|
|||||||
@@ -54,9 +54,10 @@ declare module 'vscode-mssql' {
|
|||||||
* Attempts to create a new connection for the given connection info. An error is thrown and displayed
|
* Attempts to create a new connection for the given connection info. An error is thrown and displayed
|
||||||
* to the user if an error occurs while connecting.
|
* to the user if an error occurs while connecting.
|
||||||
* @param connectionInfo The connection info
|
* @param connectionInfo The connection info
|
||||||
|
* @param saveConnection Save the connection profile if sets to true
|
||||||
* @returns The URI associated with this connection
|
* @returns The URI associated with this connection
|
||||||
*/
|
*/
|
||||||
connect(connectionInfo: IConnectionInfo): Promise<string>;
|
connect(connectionInfo: IConnectionInfo, saveConnection?: boolean): Promise<string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists the databases for a given connection. Must be given an already-opened connection to succeed.
|
* Lists the databases for a given connection. Must be given an already-opened connection to succeed.
|
||||||
|
|||||||
Reference in New Issue
Block a user