Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Document migrations #54

Open
timoconnellaus opened this issue May 26, 2024 · 1 comment
Open

Feature: Document migrations #54

timoconnellaus opened this issue May 26, 2024 · 1 comment

Comments

@timoconnellaus
Copy link

The issue: The schema in the definitions might change but there isn't a standard way to deal with keeping the document in line with updates to the schema.

The idea is to add a migrate function and version field to the NoCodeComponentDefinition object. The migrate function would be called (probably when reading a document from the backend) and would run migrations in order based on the current version of the definition and the version of the data that is stored in the document to bring the document up to the latest version.

This would allow for document schemas to change over time with the developer able to implement migration steps that automatically deal with the documents as they are read instead of having to build a bulk migration process that is run on deployment.

Some examples of when this would be utilised:

  • renaming a field
  • moving a few fields (e.g. select fields) into a widget that has them all combined into one object
  • changing the type of the field e.g. number to select
@r00dY
Copy link
Contributor

r00dY commented May 27, 2024

That would be great. The simplest way I see it is like this:

export const linkDefinition: NoCodeComponentDefinition = {
  // ...
  version: 2,
  migrations: [
    // index 0 is migration from 0 -> 1
    (entry0: NoCodeComponentEntry) => {
      const entry1 : NoCodeComponentEntry = migrateEntryFrom0To1(entry0);
      return entry1
    },
    // index 1 is migration from 1 -> 2
    (entry1: NoCodeComponentEntry) => {
      const entry2 : NoCodeComponentEntry = migrateEntryFrom1To2(entry1);
      return entry2
    }
  ]
};

Do you think sth like this would work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants