Strata · Migrations

Document migrations

A document migration is a migration in a grammar sequence: the sequence owns document kinds where other sequences own tables, and its steps are transforms. Each step names the kind it applies to in at; its transform is passed { document, path } and returns the rewritten document. With Prism as the evaluator a rename is one $renameKeys expression, here label to text.

Grammar
{
  id: 'theatre.buttons',
  documents: { button: {} },
  migrations: [
    {
      description: 'label is now text',
      steps: [
        {
          kind: 'document',
          at: 'theatre.buttons/button',
          transform: {
            $renameKeys: { from: { $ref: '$.document' }, map: { label: 'text' } },
          },
        },
      ],
    },
  ],
}
Stored document
{ label: 'Book seats', tone: 'primary' }
Upgraded document
{ text: 'Book seats', tone: 'primary' }
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.