44from typing import Dict
55from typing import Optional
66
7+ from singlestoredb .management .workspace import StarterWorkspace
8+
79from .. import result
810from ..handler import SQLHandler
911from ..result import FusionSQLResult
10- from .utils import dt_isoformat
12+ from .utils import dt_isoformat , get_deployment
1113from .utils import get_workspace
1214from .utils import get_workspace_group
1315from .utils import get_workspace_manager
@@ -889,3 +891,90 @@ def run(self, params: Dict[str, Any]) -> Optional[FusionSQLResult]:
889891
890892
891893DropWorkspaceHandler .register (overwrite = True )
894+
895+ class UpgradeVirtualWorkspaceHandler (SQLHandler ):
896+ """
897+ UPGRADE SHAREDTIER { virtual_workspace_name | virtual_workspace_id }
898+ [ new_workspace_name ]
899+ [ size ]
900+ [ new_workspace_group_name ]
901+ [ region_id ]
902+
903+ # Name of the virtual workspace to upgrade
904+ virtual_workspace_name = '<virtual-workspace-name>'
905+
906+ # ID of the virtual workspace to upgrade
907+ virtual_workspace_id = ID '<virtual-workspace-id>'
908+
909+ # New name for the upgraded workspace
910+ new_workspace_name = 'AS <new-workspace-name>'
911+
912+ # Runtime size
913+ size = 'WITH SIZE <size>'
914+
915+ # New workspace group name
916+ new_workspace_group_name = 'TO <new-workspace-group-name>'
917+
918+ # Region to create the new workspace group in
919+ region_id = 'IN REGION <region-id>'
920+
921+ Description
922+ -----------
923+ Upgrade a SharedTier Workspace to a dedicated Cluster. Refer to
924+ `Upgrading from SharedTier <TODO: GET LINK/>`_
925+ for more information.
926+
927+ Arguments
928+ ---------
929+ * ``<virtual_workspace_name>``: The name of the virtual workspace to upgrade.
930+ * ``<virtual_workspace_id>``: The ID of the virtual workspace to upgrade.
931+ * ``<new_workspace_name>``: The name of the new workspace to create.
932+ * ``<size>``: The size of the new workspace in workspace size notation,
933+ for example "S-1".
934+ * ``<new_workspace_group_name>``: The name of the new workspace group to create.
935+ * ``<region_id>``: The ID of the region in which to create the new workspace group.
936+
937+ Remarks
938+ -------
939+ * By omition the new workspace will be created in the first region available.
940+
941+ Example
942+ -------
943+ The following command upgrades a virtual workspace named **strater-workspace** to a workspace
944+ named **workspace** with size **S-2** in a new workspace group named **wsgroup**::
945+
946+ UPGRADE SHAREDTIER "strater-workspace"
947+ AS "workspace"
948+ WITH SIZE "S-2"
949+ TO "wsgroup"
950+
951+ """
952+
953+ def run (self , params : Dict [str , Any ]) -> Optional [FusionSQLResult ]:
954+
955+ search_params = { }
956+ if params ['virtual_workspace_name' ]:
957+ search_params ['deployment_name' ] = params ['virtual_workspace_name' ]
958+ elif params ['virtual_workspace_id' ]:
959+ search_params ['deployment_id' ] = params ['virtual_workspace_id' ]
960+ else :
961+ raise ValueError ('either virtual_workspace_name or virtual_workspace_id must be specified' )
962+
963+ virtual_workspace = get_deployment (search_params )
964+
965+ if not isinstance (virtual_workspace , StarterWorkspace ):
966+ raise ValueError (
967+ 'Starter workspace not found' ,
968+ )
969+
970+ virtual_workspace .upgrade (
971+ new_workspace_name = params ['new_workspace_name' ],
972+ size = params ['size' ],
973+ new_workspace_group_name = params ['new_workspace_group_name' ],
974+ region_id = params ['region_id' ],
975+ )
976+
977+ return None
978+
979+
980+ UpgradeVirtualWorkspaceHandler .register (overwrite = True )
0 commit comments