How do you manage your databases?

I am struggling with finding a solution for managing my databases. One of the problems I am having is that I have to dive into the dashboard everytime I change my graphql schema. Working with mutliple databases exacerbates this problem. If I change 1 field in a mutation the dev process goes something like:

  1. Update test database graphql schema
  2. Update test database mutation resolver
  3. Deploy app to test environment
  4. Propagate updates to acceptance database
  5. Deploy app to acc environment
  6. Propagate updates to prod database
  7. Deploy app to prd environment

Ideally I would like to manage all these things automatically, so in this case:

  1. I would like my database to mirror the schema I have in a git repository based on the branch that it resides in.
  2. I would like to define my resolvers as code and store them in my git repository.

Is there some best-practice method for realizing this?


I don’t have a ready response for this and would love to write out an example but that’ll be the cause that other things don’t get done :).

I wonder, can’t you use a continuous deployment framework such as CircleCI (I’m pretty sure Zeit/Netlify also have the possibility to have custom logic like that) in combination with the update graphql endpoint? (maybe you are not aware that there is such an endpoint:

That should imo make it possible to:

  • push code
  • CI picks ups changes, updated database
  • etc etc.

Hey, thanks! I was definitely not aware of this endpoint and it does solve 1 part of the problem, specifically schema management. I don’t think something similar exists for FQL resolvers though? It creates functions for the defined resolvers, but it doesn’t seem like the resolvers can be managed through an API endpoint as well. Am I maybe overlooking this?

Look at the Fwitter code, resolvers are just User Defines Functions (UDFs) which can be managed via the Fauna Query Language.

In that file you see how to create these.

By default we have a CreateFunction and generic Update function (with generic I mean, for other things as well then functions). You can easily use JavaScript to compose a few FQL statements into one function that forms a convenient create or update.

function CreateOrUpdateFunction(obj) {
  return If(
    Update(q.Function(, { body: obj.body, role: obj.role }),
    CreateFunction({ name:, body: obj.body, role: obj.role })

You call that as you would normally call FQL, by creating a client with the javascript driver and calling client.query as explained here:

You can imagine that you could have a folder named: “UDFs” in your project which contains
JavaScript files that export one thing, the body of a UDF function. (You could if you want even write a small index.js to get all function definitions in that UDFs folder in a convenient array).

All that is left to do is import this index in your continuous deployment script and create or update each function. This is also on my I-would-really-like-to-write-an-example-of-this list. At this point Fwitter just runs a Setup script which calls all these function updates manually.
Just make sure thatthe javascript driver that you run in your continuous deployment script has access to do what it needs to do (you probably want to give it a Server key via an environment var if you consider that safe in your continuous deployment script)

For example, this is the main function that sets up my database:

1 Like

Aha, that actually solves the rest :slight_smile:

I’ll experiment and see how well I can get this to work! Thanks! :tada:

1 Like