Skip to content

[SavedObjects] Allow migrations to be a function#88594

Merged
Bamieh merged 10 commits intoelastic:masterfrom
Bamieh:migrations/support_embeddables
Jan 19, 2021
Merged

[SavedObjects] Allow migrations to be a function#88594
Bamieh merged 10 commits intoelastic:masterfrom
Bamieh:migrations/support_embeddables

Conversation

@Bamieh
Copy link
Copy Markdown
Contributor

@Bamieh Bamieh commented Jan 18, 2021

Closes #84907

Allows Savedobject migrations property to be a function.

const savedObjectType = {
  migrations: () => ({
    '2.0.0': migrations.migrateToV2,
    '2.1.0': migrations.migrateToV2_1
  },
}

Key changes:

  • savedObjectType.migrations property can now be a function or an object.
  • The migrations Map validation is now run separately at the very beginning of the SO start lifecycle.
  • This allows delayed evaluation of the SO migrations Map until all plugins have executed their setup lifecycle function.

This will help support 'augmenting' the migration objects by other external plugins without requiring to manually add each version to the migration to check if those external plugins (like embeddables) need to migrate any sub-documents.

Code Example
// viz plugin
// registers embeddable type

setup() {
  embeddablesRegistry.registerEmbeddable({
    id: 'visualize_embeddable',
    migrations: {
      '7.11': (state) => ({...state, new: 'thing' }),
    },
  });
}

// dashboard plugin
// uses embeddables so it needs to make sure
// all embeddables are migrated as well

// when calling migrations we need setup to be completely ran first
// to give a chance to all plugins to add their embeddable migration plans (like how viz did above)
// gets all migrations needed from embeddables

// embeddable will inject their own migration plan to each do
{
  setup({ savedObjects, embeddable }) {
    savedObjects.register({
      type: 'dashboard',
      migrations: () => {
        const dashboardMigrations = {
          '7.11': (state) => {
            return {
      
            }
          },
        }

        return embeddable.injectEmbeddableMigrations(dashboardMigrations);
      }
    })
  }
}

@Bamieh Bamieh requested a review from rudolf January 18, 2021 13:00
@Bamieh Bamieh added 8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.12.0 labels Jan 18, 2021
Copy link
Copy Markdown
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some small nits, but overall looks good

@Bamieh Bamieh marked this pull request as ready for review January 19, 2021 08:39
@Bamieh Bamieh requested a review from a team as a code owner January 19, 2021 08:39
@Bamieh Bamieh requested a review from rudolf January 19, 2021 09:15
Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looking good.

Just got a question regarding the KibanaMigrator. migrateDocument call to documentMigrator.prepareMigrations

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@Bamieh Bamieh merged commit f5c73a9 into elastic:master Jan 19, 2021
@Bamieh Bamieh deleted the migrations/support_embeddables branch January 19, 2021 16:37
jportner added a commit to jportner/kibana that referenced this pull request Jan 19, 2021
Bamieh added a commit that referenced this pull request Jan 19, 2021
Co-authored-by: Rudolf Meijering <skaapgif@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.12.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

saved object migrations should support embeddable migrations

4 participants