Skip to content

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

@NobleDraconian

Description

@NobleDraconian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions