mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 09:35:37 -05:00
Fix bugbash SQL-Migration extension migration load issues (#16575)
* fix migration refresh issues * merge latest
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as vscode from 'vscode';
|
||||
import { azureResource } from 'azureResource';
|
||||
import { DatabaseMigration, SqlMigrationService, SqlManagedInstance, getMigrationStatus, AzureAsyncOperationResource, getMigrationAsyncOperationDetails, SqlVMServer } from '../api/azure';
|
||||
import { DatabaseMigration, SqlMigrationService, SqlManagedInstance, getMigrationStatus, AzureAsyncOperationResource, getMigrationAsyncOperationDetails, SqlVMServer, getSubscriptions } from '../api/azure';
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
export class MigrationLocalStorage {
|
||||
@@ -23,16 +23,20 @@ export class MigrationLocalStorage {
|
||||
const migrationMementos: MigrationContext[] = this.context.globalState.get(this.mementoToken) || [];
|
||||
for (let i = 0; i < migrationMementos.length; i++) {
|
||||
const migration = migrationMementos[i];
|
||||
migration.sessionId = migration.sessionId ?? undefinedSessionId;
|
||||
if (migration.sourceConnectionProfile.serverName === connectionProfile.serverName) {
|
||||
if (refreshStatus) {
|
||||
try {
|
||||
const backupConfiguration = migration.migrationContext.properties.backupConfiguration;
|
||||
const sourceDatabase = migration.migrationContext.properties.sourceDatabaseName;
|
||||
|
||||
await this.refreshMigrationAzureAccount(migration);
|
||||
|
||||
migration.migrationContext = await getMigrationStatus(
|
||||
migration.azureAccount,
|
||||
migration.subscription,
|
||||
migration.migrationContext,
|
||||
migration.sessionId ?? undefinedSessionId
|
||||
migration.sessionId!
|
||||
);
|
||||
migration.migrationContext.properties.sourceDatabaseName = sourceDatabase;
|
||||
migration.migrationContext.properties.backupConfiguration = backupConfiguration;
|
||||
@@ -41,7 +45,7 @@ export class MigrationLocalStorage {
|
||||
migration.azureAccount,
|
||||
migration.subscription,
|
||||
migration.asyncUrl,
|
||||
migration.sessionId ?? undefinedSessionId
|
||||
migration.sessionId!
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -62,6 +66,20 @@ export class MigrationLocalStorage {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async refreshMigrationAzureAccount(migration: MigrationContext): Promise<void> {
|
||||
if (migration.azureAccount.isStale) {
|
||||
const accounts = await azdata.accounts.getAllAccounts();
|
||||
const account = accounts.find(a => !a.isStale && a.key.accountId === migration.azureAccount.key.accountId);
|
||||
if (account) {
|
||||
const subscriptions = await getSubscriptions(account);
|
||||
const subscription = subscriptions.find(s => s.id === migration.subscription.id);
|
||||
if (subscription) {
|
||||
migration.azureAccount = account;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static saveMigration(
|
||||
connectionProfile: azdata.connection.ConnectionProfile,
|
||||
migrationContext: DatabaseMigration,
|
||||
@@ -106,3 +124,19 @@ export interface MigrationContext {
|
||||
asyncOperationResult?: AzureAsyncOperationResource,
|
||||
sessionId?: string
|
||||
}
|
||||
|
||||
export enum MigrationStatus {
|
||||
Failed = 'Failed',
|
||||
Succeeded = 'Succeeded',
|
||||
InProgress = 'InProgress',
|
||||
Canceled = 'Canceled',
|
||||
Completing = 'Completing',
|
||||
Creating = 'Creating',
|
||||
Canceling = 'Canceling'
|
||||
}
|
||||
|
||||
export enum ProvisioningState {
|
||||
Failed = 'Failed',
|
||||
Succeeded = 'Succeeded',
|
||||
Creating = 'Creating'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user