1+ --[[
2+ This script will:
3+ - Migrate the latest version of the DS2 data store to the migrated data store,
4+ - Delete the entire DS2 data store.
5+
6+ This script deletes the entire DS2 data store, so use with caution.
7+ ]]
8+ local DataStoreService = game :GetService ("DataStoreService" )
9+ local HttpService = game :GetService ("HttpService" )
10+ local MIGRATED_DS_SCOPE = "global" -- Change to a different scope as needed
11+ local UNIVERSE_ID = - 1 -- Change to the universe id
12+
13+ -- Wait for sufficient data store budget
14+ local function waitForBudgetAsync (requestType : Enum .DataStoreRequestType , minBudget : number ): ()
15+ while true do
16+ local budget = DataStoreService :GetRequestBudgetForRequestType (requestType )
17+ if budget >= minBudget then
18+ return
19+ end
20+ task.wait (0.5 ) -- Wait 0.5 second before checking again
21+ end
22+ end
23+
24+ return function (dataStoreName )
25+ -- Parse the datastore name
26+ local ds2Key , playerIdString = string.match (dataStoreName , "^(.*)/([^/]*)$" )
27+
28+ if not ds2Key or not playerIdString then
29+ error ("Invalid Data Store Name: " .. dataStoreName )
30+ end
31+
32+ local playerId = tonumber (playerIdString )
33+
34+ -- Initialize data stores
35+ local ds2SDS = DataStoreService :GetDataStore (dataStoreName )
36+ local ds2ODS = DataStoreService :GetOrderedDataStore (dataStoreName )
37+ local migratedDS = DataStoreService :GetDataStore (ds2Key , MIGRATED_DS_SCOPE )
38+
39+ -------------
40+ -- MIGRATE --
41+ -------------
42+
43+ -- Modified from BerezaaMethodDataMigrationTool
44+ -- See https://create.roblox.com/store/asset/100741523916104/BETA-Berezaa-Method-Data-Migration-Tool
45+ local migratedData = migratedDS :GetAsync (playerId )
46+ if migratedData == nil then
47+ waitForBudgetAsync (Enum.DataStoreRequestType.GetSortedAsync , 1 )
48+ local pages = ds2ODS :GetSortedAsync (false , 1 )
49+
50+ -- Get the latest version
51+ local latestVersion = pages :GetCurrentPage ()[1 ]
52+ if latestVersion then
53+ -- Get the data value from the SDS
54+ local version = latestVersion .value
55+ waitForBudgetAsync (Enum.DataStoreRequestType.GetAsync , 2 )
56+ local data = ds2SDS :GetAsync (version )
57+
58+ -- Move this data into the new SDS
59+ waitForBudgetAsync (Enum.DataStoreRequestType.SetIncrementAsync , 1 )
60+ migratedDS :UpdateAsync (playerId , function (oldData )
61+ if oldData then
62+ return oldData
63+ end
64+ return data
65+ end )
66+ end
67+ print ("Info: Migrated latest version from " .. dataStoreName .. " to " .. ds2Key .. "." )
68+ else
69+ print ("Info: Data already exists for player " .. playerId .. " in " .. ds2Key .. "." )
70+ end
71+
72+ ------------
73+ -- DELETE --
74+ ------------
75+
76+ -- Delete the data store
77+ local encodedDataStoreName = HttpService :UrlEncode (dataStoreName )
78+ local apiKey = HttpService :GetSecret ("DS_DELETION_API_KEY" )
79+ local response = HttpService :RequestAsync ({
80+ Url = "https://apis.roblox.com/cloud/v2/universes/" .. UNIVERSE_ID .. "/data-stores/" .. encodedDataStoreName ,
81+ Method = "DELETE" ,
82+ Headers = {
83+ ["x-api-key" ] = apiKey ,
84+ ["Content-Type" ] = "application/json" ,
85+ },
86+ })
87+
88+ if response .StatusCode ~= 200 then
89+ error ("Failed to delete data store. Status code: " .. response .StatusCode .. ", Status message: " .. response .StatusMessage .. ", Body: " .. response .Body )
90+ end
91+ print ("Info: Deleted data store: " .. dataStoreName )
92+ end
0 commit comments