Tutorial
Config Inference
Now that you've set up Postgres and added the "db" system, you can use config inference.
Add a db/2-user-roles.sql
:
CREATE TYPE role AS ENUM ('editor', 'buyer', 'engineer', 'exec');
ALTER TABLE users ADD COLUMN roles role[];
And run docker compose down -v
and docker compose up -d
to pick up the new schema.
Now run rngo infer
. This will output the following:
Updating the config:
- adding property roles to stream users
and update .rngo/config
to look something like this:
streams:
users:
# ...
schema:
type: object
properties:
id:
type: integer
minimum: 1
rngo:
cursor: ascending
full_name:
type: string
rngo:
enum: enum.fullName
created_at:
type: string
format: date-time
rngo:
const: sim.now
roles:
type: array
items:
type: string
enum:
- editor
- buyer
- engineer
- exec
required:
- id
- full_name
- created_at
Notice that it has preserved the customizations we made. It is safe to run rngo infer
at any time - by default it is non-destructive and will only append to the schema. You should run in to bootstrap a new project and after subsequent schema updates.
Run rngo sim
again - this time, the new roles
column will have an array of the configured enum values, or null
since it is not required like the other properties.