core: make item migration fall through all db versions

this was not exactly a bug but it can cause a lot of unintended
behaviour. Previously, you'd have to manually specify which version the
item migration should jump to. This was buggy and poorly designed.
This change makes the item iterate over all the db migrations one by one
automatically.

For example:

An item at version 5.2 will go through:
- 5.3
- 5.4
- and so on
This commit is contained in:
Abdullah Atta
2022-10-12 10:39:47 +05:00
committed by Abdullah Atta
parent 9701a3d660
commit c09715d053
3 changed files with 102 additions and 91 deletions

View File

@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { migrations } from "../migrations";
import { migrateItem } from "../migrations";
class Migrator {
async migrate(db, collections, get, version) {
@@ -40,8 +40,12 @@ class Migrator {
item.type = "tiptap";
}
const migrate = migrations[version][item.type || collection.type];
if (migrate) item = await migrate(item, db);
item = await migrateItem(
item,
version,
item.type || collection.type,
db
);
if (collection.dbCollection.merge) {
await collection.dbCollection.merge(item);