What is the preferred method of ensuring a schema exists in a keyspace?


Hi! I’m experimenting with incorporating Grakn into an application we’re building to provide a different way of visualising our data. For background, the application is running in Docker (using the official Grakn image) and I’d like to extend it so that whenever the container is brought up it ensures the correct schema is present in the keyspace.

I’ve made a .gql file containing the entire schema definition with the intention of running graql console -k mykeyspace -f schema.gql whenever the container is brought up. Is this the best way to go about it, or is there a way of checking which parts (if any) of the schema exist in the keyspace and applying changes selectively?


Hi @MorayM

Can you please clarify what you mean by whenever the container is brought up? What would be the state of the Grakn instance when the container is brought up?


Hi @soroush, bringing up the container starts the server and loads a shared volume into /grakn/db so that data is persisted whenever the container is brought down. Once grakn is running (i.e. the Storage, Queue and Grakn components), a script runs to ensure that the schema is in place so the graph is in a healthy state for the rest of the application services to work with.


Thanks for the clear explanation.

If you expect the schema to evolve at your application’s run-time (via the Grakn client), then you need to make sure that the schema you load into the keyspace, after every boot-up, also gets updated. Otherwise, if you don’t programatically manipulate the schema, then there is nothing to be concerned about as the data instances will always conform to the initial (or manually updated) schema.