backend/migrations: check all workspaces
This commit fixes a bug that (in the case of the `local` backend) would only check if the selected workspace had a state when deciding to preform a migration. When the selected workspace didn’t have a state (but other existing workspace(s) did), the migration would not be preformed and the other workspaces would be ignored.
This commit is contained in:
parent
cf8516287e
commit
1696ade924
|
@ -907,9 +907,14 @@ func (m *Meta) backend_C_r_s(
|
|||
return nil, fmt.Errorf(errBackendLocalRead, err)
|
||||
}
|
||||
|
||||
env := m.Workspace()
|
||||
workspaces, err := localB.States()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(errBackendLocalRead, err)
|
||||
}
|
||||
|
||||
localState, err := localB.State(env)
|
||||
var localStates []state.State
|
||||
for _, workspace := range workspaces {
|
||||
localState, err := localB.State(workspace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(errBackendLocalRead, err)
|
||||
}
|
||||
|
@ -917,10 +922,13 @@ func (m *Meta) backend_C_r_s(
|
|||
return nil, fmt.Errorf(errBackendLocalRead, err)
|
||||
}
|
||||
|
||||
// If the local state is not empty, we need to potentially do a
|
||||
// state migration to the new backend (with user permission), unless the
|
||||
// destination is also "local"
|
||||
// We only care about non-empty states.
|
||||
if localS := localState.State(); !localS.Empty() {
|
||||
localStates = append(localStates, localState)
|
||||
}
|
||||
}
|
||||
|
||||
if len(localStates) > 0 {
|
||||
// Perform the migration
|
||||
err = m.backendMigrateState(&backendMigrateOpts{
|
||||
OneType: "local",
|
||||
|
@ -946,6 +954,7 @@ func (m *Meta) backend_C_r_s(
|
|||
}
|
||||
|
||||
if erase {
|
||||
for _, localState := range localStates {
|
||||
// We always delete the local state, unless that was our new state too.
|
||||
if err := localState.WriteState(nil); err != nil {
|
||||
return nil, fmt.Errorf(errBackendMigrateLocalDelete, err)
|
||||
|
@ -955,6 +964,7 @@ func (m *Meta) backend_C_r_s(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if m.stateLock {
|
||||
stateLocker := clistate.NewLocker(context.Background(), m.stateLockTimeout, m.Ui, m.Colorize())
|
||||
|
|
Loading…
Reference in New Issue