question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for migrations

See original GitHub issue

Feature request

I’ve been thinking about how I could make the usage of slate in production easier for me (and possibly others). The thing is:

  • There are quite a few breaking changes.

In terms of code, I don’t mind it that much. Yeah, it’s a pain and it’s all for a good reason. I am fine with that.

  • These breaking changes often change the structure of the editor state.

Now, this, in my opinion, is a problem. The state is often persisted in various storage (server/client side) and as a result of these changes, companies, especially the ones that have a lot of data, can run into trouble. Also, it is not always clear how and when the state structure changed. Yes there is the changelog which is extremely useful, but it requires some serious time to investigate and act on these changes. I am suggesting a way to potentially mitigate this: Create slate-migrations package This package would simply contain a folder migrations, and for each braking change in the state, a new migration would be created and placed in this folder. The interface for a migration could look something like:

export interface Migration {
  // Semver range
  fromVersionRange: string;
  // Semver single version
  toVersion: string;
  migrate: (value: any) => any;
}

Notice the ‘any’ for value, we obviously can’t strongly type migrations as it would reference a code that could have changed in the meantime. Slate could then take an extra field ‘migrations’ which would be an array of migrations. The state of the editor would have to change from an array of nodes to an object in order to keep the version in it. So:

{
  version: '0.52.2', 
  children: Node[]
}

Would effectively become the value of the editor. The version could be picked up from the package version of slate. When first initialized, the Slate could look at the version and the migrations field, try to migrate and if it succeeds, it would then use the migration chain to migrate the value to the most recent state. It would be fully up to users to include as many migrations as they want (if any). I have previously successfully implemented something like this here:
https://github.com/react-page/react-page/pull/554#issuecomment-413847279 It also contains some pseudo-code on how the migrations would work.

I’d like to know what you all think about this. Please note that while this is an extra package, and some extra code, the maintenance would be minimal, as migrations are pretty much ‘create once and never touch again’ kind of thing. The added responsibility of creating migrations might suck a little bit, but it has great value for users. Also to create migrations is actually not too much work. Check for instance the migrations here: https://github.com/react-page/react-page/tree/master/packages/plugins/content/slate/src/migrations these actually handle the changed slate state for versions around 40 (I don’t remember which exactly). Also if we have the information of the version on the state, we can gracefully fail and provide information on the reason for the failure if it failed because the state is incompatible.

I am happy to implement this functionality but before I start the work, I want to make sure it’s ok with everybody here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PeterKottascommented, Feb 11, 2021

@oyeanuj Nothing freestanding that can be used solely by slate, but you can check https://github.com/react-page/react-page/tree/b6c83a8650cfe9089e0c3eaf471ab58a0f7db761/packages/plugins/content/slate/src/migrations for an example of migrations and https://github.com/react-page/react-page/blob/db777ca3df54b3547adf7f6b3b9988bc63f1b7da/packages/core/src/service/plugin/classes.ts searching for “migration” for implementation. Not sure if that helps but it’s the best I have 😃

1reaction
PeterKottascommented, Dec 9, 2019

Thanks Ian. I think I can figure out some sort of combination of both, but for the time being, I guess the shim will be enough.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get migration help and support | Atlassian
Understand the support options available to you during your migration – from Atlassian's migration specialists to our trusted network of Solution Partners.
Read more >
Support For Migrants | International Organization for Migration
Support For Migrants gives you the latest advice on government, UN and NGO services wherever you are in the Western Balkans. If you...
Read more >
Help Desk Migration Service - Automated Import and ...
Help Desk Migration service allows migrating data from one help desk system to another. Easily. Quickly. With Free Demo available. Starting at $1....
Read more >
International Organization for Migration | IOM, UN Migration
Official website of IOM, the leading organization within the United Nations system promoting humane and orderly migration for the benefit of all.
Read more >
Global compact for migration | Refugees and Migrants
The global compact comprises 23 objectives for better managing migration at local, national, regional and global levels. The compact: aims to mitigate the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found