Fauna schema updates + development

I am committing some .fsl files to a repo, and deploying them automatically via github actions CI on any push.

My question is about developing + schema files. If I make a change to the schema definition, the CI logs an error, as below. I don’t understand how to have a good development workflow. The schema should change as part of developing; I don’t really want an “add migration”, because it will be unnecessary in production; the schema is just changing for development purposes.

Is it possible to change a schema (add a field) without adding a migration field?

Run npx fauna schema push --dir=fauna --no-input --secret=***
 ›   Error: error: Field `.metadata` is not present in the live schema
 ›   at read-token.fsl:5:5
 ›     |
 ›   5 |     metadata: {
 ›     |     ^^^^^^^^
 ›     |
 ›   hint: Provide an `add` migration for this field
 ›     |
 ›   5 |       migrations {
 ›     |  _____+
 ›   6 | |     add .metadata
 ›   7 | |     backfill .metadata = <expr>
 ›   8 | |   }
 ›     | |____^
 ›     |
 ›   hint: Add a default value to this field
 ›   at read-token.fsl:9:6
 ›     |
 ›   9 |     } = <expr>
 ›     |      +++++++++
 ›     |
 ›   hint: Make the field nullable
 ›   at read-token.fsl:9:6
 ›     |
 ›   9 |     }?
 ›     |      +
 ›     |
Error: Process completed with exit code 1.

Fauna cares very deeply about your data being correct. When you update your database from one explicit schema to another, the only way to ensure the data remains correct is by articulating how to migrate from one schema to another. The migration block is how you can do that.

When you add a field definition with a type that is mandatory, you assert that “every document has this field”. Before, the schema did not include this field. Fauna assumes that some or all documents potentially do not include this field, OR perhaps if it does it may not have the correct type. So you include the instructions for how to handle that. Either by using a default, a backfill, or making the field nullable as the hints suggest.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.