Priming a new db

Hi there.
In order to do this, I’d import the schema.
It is a simple monolithic file, easily put under svc.
But, what about UDFs?
How to store their defs somewhere?
How to put them under svc?
And how to batch load them?
Thanks for any reply.

This reminds me of my days when I wore a DBA hat. We used to require any and all schema changes, including additional triggers and functions, to be stored in a schema file that was checked into source control. Whenever a developer needed to spin up a new copy of the production database, they would first check out the latest version of the schema, run an import, then load their data.

I would use the same mechanism here. Make sure your GraphQL schema, including any and all mutations and queries, and the CreateFunction() statements for your UDFs, are all stored in your source control of choice. Then you’d use the fauna shell command with eval to load them. For instance:

$ fauna eval --file=./createFunctions.fql

See the documentation on fauna shell for more details.


Sounds cheap and easy!

Just a side note:
Is it the SHELL variant that I have to put within files with extension .fql?

And furthermore: how to concatenate several independent createFunction calls? Is there any termination punctuation or just new line…?


Glad to help!

You don’t have use to use the .fql file extension, I just used that for convention. You can use whatever you’d like. The eval --file= option will take any plaintext file it’s given, regardless of extension.

And yes, a newline suffices to keep the CreateFunction() calls distinct. The sample I threw together when making sure this would work was:

$ cat createFunctions.fql 
  name: 'double',
  body: Query(
    Lambda('x', Add(Var('x'), Var('x')))

  name: 'triple',
  body: Query(
    Lambda('x', Add(Var('x'),Var('x'), Var('x')))

And both functions loaded without any issue.


Really appreciated!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.