nezuo / lapis

A DataStore abstraction library for Roblox
https://nezuo.github.io/lapis/
MIT License
59 stars 10 forks source link

Backwards compatible migrations #54

Closed nezuo closed 4 months ago

nezuo commented 4 months ago

Migrations can now be marked as backwards compatible. Backwards compatibility is transitive, for example, if v2 is backwards compatible with v1 and v3 is backwards compatible with v2, v3 is also backwards compatible with v1.

When a document is loaded with a migrationVersion greater than the latest migration version the server has, the document will be loaded as long as it is backwards compatible with the server version.

A lastCompatibleVersion is saved to a document when it's created or when it's migrated to a new version. If lastCompatibleVersion is nil because the document existed before this feature was added and hasn't had a migration since, Lapis will assume that the document isn't backwards compatible with any version.

If a migration's backwardsCompatible value is changed after the fact, it won't affect documents until and unless the documents are created for the first time or they are migrated to a new version.

I chose this behavior because if you joined a server with the old backwardsCompatible value after joining a server with the new one, it would recalculate lastCompatibleVersion to be an incorrect version.

The alternative that was ruled out was recalculating lastCompatibleVersion every time a document was loaded.