Advanced

Schemas

Persisted relvars in the same folder are known as a schema. They can be queried together and any modifications are first checked against constraints in the schema's Constraint relvar.

When Ra is started the current folder becomes the current schema. No other process should access the folder while Ra is running.

Each schema folder can have an optional init.ra file which is executed when Ra first loads a schema. It is executed after any persisted relvars have been loaded from the folder into memory. It can be used to initialise relvars if they don't exist yet, or modify the structure or contents of ones that do exist, according to some logic. For example, a common pattern is to declare the schema's initial relvars if they don't already exist, and otherwise leave them with any subsequent modifications intact. e.g.

if not given(S) then begin
    S := {SNO:str, SNAME:str, STATUS:int, CITY:str}{
         ["S1",    "Smith",   20,         "London"],
         ["S2",    "Jones",   10,         "Paris"],
         ["S3",    "Blake",   30,         "Paris"],
         ["S4",    "Clark",   20,         "London"],
         ["S5",    "Adams",   30,         "Athens"],
    }
end

Here, the given function returns true if the relvar exists, i.e. was loaded from the schema folder.