Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema migration should support data that existed prior to the schema existing #2

Open
NobleDraconian opened this issue May 29, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@NobleDraconian
Copy link
Member

NobleDraconian commented May 29, 2023

Currently as of v1.0.0, the schema migration feature of this data system does not support migrating data that has existed before the schema was active. This makes it difficult to migrate older data to work with this system.

This can be supported by adding a function to the schema migration module with a keyname of ? -> 1. This function would take any data that is missing the schema version metadata and update it to conform to the 1st schema version. Here's an example of a game migrating its existing data to utilize this system's schema features:

Old data (prior to using schemas):

{
	Coins = 120,
	XP = 3600,
	Inventory = {"Axe","Sword"}
}

Data schema version 2:

{
	Currency = {
		GoldCoins = 0,
		Gems = 0
	},
	Progress = {
		UnlockedWaystones = {},
		XP = 0,
	},
	OwnedItems = {
		Weapons = {},
		Armor = {},
		Consumables = {}
	}
}

Schema migrations:

local SchemaMigrations = {}

SchemaMigrations["? -> 1"] = function(OldData)
	local NewData = {
		Currency = {
			GoldCoins = OldData.Coins,
			Gems = 0
		},
		OwnedItems = {
			Weapons = {},
			Armor = {},
			Consumables = {}
		},
		XP = OldData.XP
	}
	
	for _,WeaponName in pairs(OldData.Inventory) do
		table.insert(NewData.OwnedItems.Weapons,LegacyNameToItemID(WeaponName))
	end
	
	return NewData
end

SchemaMigrations["1 -> 2"] = function(Data)
	Data.Progress = {
		UnlockedWaystones = {},
		XP = Data.XP
	}
	Data.XP = nil
	
	return Data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Status: To Do
Development

No branches or pull requests

1 participant