We decided to write the same schema in 2 format, one in Elasticsearch mappings, another in zod. We want type safety and correct indexing settings in the same time, however:
We can't describe complex rules in Elasticsearch index mappings.
We can't specify Elasticsearch indexing settings (such has using keywords or text, and the use of analyzers) in zod schema.
This is why we write the schema in two different formats, and use examples to ensure that the two schemas are in sync by type checking and try inserting them in DB during CI.
Changes
Adds new script, scan that scans through the entire index for docs that does not match the zod schema.
Convert all schemas into the new format with Typescript.
The examples are selected from real documents in index. Also, all schemas are ran against the production DB snapshot to ensure that the schema reflects the possibilities in real DB.
This helps with the type safety of rumors-api.
Schema in 2 formats
We decided to write the same schema in 2 format, one in Elasticsearch mappings, another in
zod
. We want type safety and correct indexing settings in the same time, however:zod
schema.This is why we write the schema in two different formats, and use
examples
to ensure that the two schemas are in sync by type checking and try inserting them in DB during CI.Changes
scan
that scans through the entire index for docs that does not match the zod schema.examples
are selected from real documents in index. Also, all schemas are ran against the production DB snapshot to ensure that the schema reflects the possibilities in real DB.