mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
Add new wizard for login migrations experience (#21317)
This commit is contained in:
@@ -58,6 +58,22 @@ const query_databases_with_size = `
|
||||
WHERE sys.databases.state = 0
|
||||
`;
|
||||
|
||||
const query_login_tables_sql = `
|
||||
SELECT
|
||||
sp.name as login,
|
||||
sp.type_desc as login_type,
|
||||
sp.default_database_name,
|
||||
case when sp.is_disabled = 1 then 'Disabled' else 'Enabled' end as status
|
||||
FROM sys.server_principals sp
|
||||
LEFT JOIN sys.sql_logins sl ON sp.principal_id = sl.principal_id
|
||||
WHERE sp.type NOT IN ('G', 'R') AND sp.type_desc IN (
|
||||
'SQL_LOGIN'
|
||||
--, 'WINDOWS_LOGIN'
|
||||
) AND sp.name NOT LIKE '##%##'
|
||||
ORDER BY sp.name;`;
|
||||
|
||||
const query_is_sys_admin_sql = `SELECT IS_SRVROLEMEMBER('sysadmin');`;
|
||||
|
||||
export const excludeDatabases: string[] = [
|
||||
'master',
|
||||
'tempdb',
|
||||
@@ -85,6 +101,13 @@ export interface TargetDatabaseInfo {
|
||||
targetTables: Map<string, TableInfo>;
|
||||
}
|
||||
|
||||
export interface LoginTableInfo {
|
||||
loginName: string;
|
||||
loginType: string;
|
||||
defaultDatabaseName: string;
|
||||
status: string;
|
||||
}
|
||||
|
||||
function getSqlDbConnectionProfile(
|
||||
serverName: string,
|
||||
tenantId: string,
|
||||
@@ -123,7 +146,7 @@ function getSqlDbConnectionProfile(
|
||||
};
|
||||
}
|
||||
|
||||
function getConnectionProfile(
|
||||
export function getConnectionProfile(
|
||||
serverName: string,
|
||||
azureResourceId: string,
|
||||
userName: string,
|
||||
@@ -319,3 +342,64 @@ export async function getDatabasesList(connectionProfile: azdata.connection.Conn
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export async function collectSourceLogins(sourceConnectionId: string): Promise<LoginTableInfo[]> {
|
||||
const ownerUri = await azdata.connection.getUriForConnection(sourceConnectionId);
|
||||
const queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(
|
||||
'MSSQL',
|
||||
azdata.DataProviderType.QueryProvider);
|
||||
|
||||
const results = await queryProvider.runQueryAndReturn(
|
||||
ownerUri,
|
||||
query_login_tables_sql);
|
||||
|
||||
return results.rows.map(row => {
|
||||
return {
|
||||
loginName: getSqlString(row[0]),
|
||||
loginType: getSqlString(row[1]),
|
||||
defaultDatabaseName: getSqlString(row[2]),
|
||||
status: getSqlString(row[3]),
|
||||
};
|
||||
}) ?? [];
|
||||
}
|
||||
|
||||
export async function collectTargetLogins(
|
||||
targetServer: AzureSqlDatabaseServer,
|
||||
userName: string,
|
||||
password: string): Promise<string[]> {
|
||||
|
||||
const connectionProfile = getConnectionProfile(
|
||||
targetServer.properties.fullyQualifiedDomainName,
|
||||
targetServer.id,
|
||||
userName,
|
||||
password);
|
||||
|
||||
const result = await azdata.connection.connect(connectionProfile, false, false);
|
||||
if (result.connected && result.connectionId) {
|
||||
const queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(
|
||||
'MSSQL',
|
||||
azdata.DataProviderType.QueryProvider);
|
||||
|
||||
const ownerUri = await azdata.connection.getUriForConnection(result.connectionId);
|
||||
const results = await queryProvider.runQueryAndReturn(
|
||||
ownerUri,
|
||||
query_login_tables_sql);
|
||||
|
||||
return results.rows.map(row => getSqlString(row[0])) ?? [];
|
||||
}
|
||||
|
||||
throw new Error(result.errorMessage);
|
||||
}
|
||||
|
||||
export async function isSysAdmin(sourceConnectionId: string): Promise<boolean> {
|
||||
const ownerUri = await azdata.connection.getUriForConnection(sourceConnectionId);
|
||||
const queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(
|
||||
'MSSQL',
|
||||
azdata.DataProviderType.QueryProvider);
|
||||
|
||||
const results = await queryProvider.runQueryAndReturn(
|
||||
ownerUri,
|
||||
query_is_sys_admin_sql);
|
||||
|
||||
return getSqlBoolean(results.rows[0][0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user