Best Practices for Maintaining Save Compatibility Through Updates

As the title says, I am wondering what some of the known tricks are for maintaining save compatibility when updating RPG Maker MZ games.

I know removing plugins can break old saves, but I have had experiences where adding a plugin breaks a save, changing events and variables around breaks the save, changing plugin parameters breaks a save, etc.

As someone who is planning to release a game and then continue to add significant content updates, how should I go about this?

Has anyone else had experience with updating their RPG Maker game after release (via Steam etc.)?

I figure if Fear and Hunger can publish frequent updates to fix bugs and add content, it must be possible in some reliable way.
The way to do it is this:

Set ALL your plugins before starting. Do not change a single one if you want to update. You run the risk of breaking saves due to new plugins looking for variables not in the save files.

For the database do not move anything around. You can add new items to unused slots, but moving anything in the databse (items, skills, weapons, armor, variables, switches, etc) will cause issues as the save will load it by ID in the database. So if previously weapon #5 was Copper sword with ATK 5 and you change it to Excalibur with ATK 500, all old saves where they got a copper sword will now be Excalibur as it is seeing they have weapon #5, and uses all stats from that.
The way I do it is to have a plugin that manages save file migration. Tag each save with a save version and then execute migration rules when loading a save with a lower save number than the current version and execute each migration rule on it.

So, for example. one migration rule might be to move the value of a variable into a different slot. Or maybe initialize a variable, or execute the initialization code for another plugin, etc. Or to take the above example, remove an outdated item and insert a replacement.

The following is an excerpt from my migration plugin.

Spoiler: migrator.js
Rich (BB code):
class Migrator0To1 {
    migrate() {
        // Set the newly introduced corruption limit https://gitgud.io/aura-dev/star_knightess_aura/-/issues/237
        $gameVariables.setValue(14, 25);
}

// More migrators...

class Migrator40To41 {
    migrate() {
        // Add current items/skills to recording arrays
        $gameParty._recordedItems = Object.keys($gameParty._items).map(itemId => parseInt(itemId));
        for (const actor of $gameActors._data) {
            if (actor) {
                actor._recordedSkills = actor.skills().map(skill => skill.id);
            }
        }
    }
}

// Migration service that executes all migrators starting from a specified version
class MigrationService {
    migrate(migrators, fromVersion) {
        // Undefined = version 0
        if (fromVersion == undefined) {
            fromVersion = 0;
        }

        // Execute the migrators
        for (let i = fromVersion; i < migrators.length; ++i) {
            migrators.migrate();
        }
    }
}

(() => {
    const VERSION = 41;
    const MIGRATORS = [
        new Migrator0To1(),
        // More migrators...
        new Migrator40To41()
    ];

    // Ensure that the save is marked with the correct version
    const _DataManager_makeSaveContents = DataManager.makeSaveContents;
    DataManager.makeSaveContents = () => {
        const contents = _DataManager_makeSaveContents();
        contents.version = VERSION;
        return contents;
    };

    // Check for migration and perform it if necessary
    const _DataManager_extractSaveContents = DataManager.extractSaveContents;
    DataManager.extractSaveContents = (contents) => {
        _DataManager_extractSaveContents(contents);
        const currentVersion = contents.version;

        // Check if migration is necessary
        // If no current version is defined or if the current version is older
        // then we need to execute the migrators
        if (currentVersion == undefined || currentVersion < VERSION) {
            const migrationService = new MigrationService();
            migrationService.migrate(MIGRATORS, currentVersion)
        }
    };
})();

EDIT: Just for reference, I have maintained save compatibility for nearly all of my players for now 3 years with the first version being a pure prototype with only the absolutely necessary plugins.
The way to do it is this:

Set ALL your plugins before starting. Do not change a single one if you want to update. You run the risk of breaking saves due to new plugins looking for variables not in the save files.

For the database do not move anything around. You can add new items to unused slots, but moving anything in the databse (items, skills, weapons, armor, variables, switches, etc) will cause issues as the save will load it by ID in the database. So if previously weapon #5 was Copper sword with ATK 5 and you change it to Excalibur with ATK 500, all old saves where they got a copper sword will now be Excalibur as it is seeing they have weapon #5, and uses all stats from that.
Keeping variables etc. where they are should be easy enough, though events are a bit trickier. If I have to remove an event, I guess I would be best-off making it do nothing instead, so that its ID wont be used if I create a new event on that same page. Or would that matter at all? I figure it would keep any self switches etc. that the old one had saved, but I guess the rest is reset on map load.

Plugins are the boogeyman of development I suppose. I've found odd issues here and there in some as I develop, but hopefully that stops happening by release. I would have to have to cut a problematic one and break saves.

The way I do it is to have a plugin that manages save file migration. Tag each save with a save version and then execute migration rules when loading a save with a lower save number than the current version and execute each migration rule on it.

So, for example. one migration rule might be to move the value of a variable into a different slot. Or maybe initialize a variable, or execute the initialization code for another plugin, etc. Or to take the above example, remove an outdated item and insert a replacement.

The following is an excerpt from my migration plugin.

Spoiler: migrator.js
Rich (BB code):
class Migrator0To1 {
    migrate() {
        // Set the newly introduced corruption limit https://gitgud.io/aura-dev/star_knightess_aura/-/issues/237
        $gameVariables.setValue(14, 25);
}

// More migrators...

class Migrator40To41 {
    migrate() {
        // Add current items/skills to recording arrays
        $gameParty._recordedItems = Object.keys($gameParty._items).map(itemId => parseInt(itemId));
        for (const actor of $gameActors._data) {
            if (actor) {
                actor._recordedSkills = actor.skills().map(skill => skill.id);
            }
        }
    }
}

// Migration service that executes all migrators starting from a specified version
class MigrationService {
    migrate(migrators, fromVersion) {
        // Undefined = version 0
        if (fromVersion == undefined) {
            fromVersion = 0;
        }

        // Execute the migrators
        for (let i = fromVersion; i < migrators.length; ++i) {
            migrators.migrate();
        }
    }
}

(() => {
    const VERSION = 41;
    const MIGRATORS = [
        new Migrator0To1(),
        // More migrators...
        new Migrator40To41()
    ];

    // Ensure that the save is marked with the correct version
    const _DataManager_makeSaveContents = DataManager.makeSaveContents;
    DataManager.makeSaveContents = () => {
        const contents = _DataManager_makeSaveContents();
        contents.version = VERSION;
        return contents;
    };

    // Check for migration and perform it if necessary
    const _DataManager_extractSaveContents = DataManager.extractSaveContents;
    DataManager.extractSaveContents = (contents) => {
        _DataManager_extractSaveContents(contents);
        const currentVersion = contents.version;

        // Check if migration is necessary
        // If no current version is defined or if the current version is older
        // then we need to execute the migrators
        if (currentVersion == undefined || currentVersion < VERSION) {
            const migrationService = new MigrationService();
            migrationService.migrate(MIGRATORS, currentVersion)
        }
    };
})();

EDIT: Just for reference, I have maintained save compatibility for nearly all of my players for now 3 years with the first version being a pure prototype with only the absolutely necessary plugins.

This is very interesting! I will definitely try using this if I have to move anything around. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/best-practices-for-maintaining-save-compatibility-through-updates.164582/