简体   繁体   中英

How to programmatically create an OrientDB database of a given (json) schema?

For my dev workflow purposes, I'd like to create a new orientdb database given a JSON schema, on the fly. I dont believe this is natively supported in orientdb, are there any existing solutions that do this - provide a JSON schema and point to a orientdb instance, and it auto-creates the database (edges, vertices, indexes and perhaps some sample data).

I ended up creating a .sh script to create the DB on the fly. The .sh files looks something like:

# (file: createmydb.sh)

# script to create my database declaratively

set echo true

# use this to ignore errors and continue, if needed
# set ignoreErrors true

# create database
create database plocal:../databases/MyDB root root plocal graph

# create User vertex
create class User extends      V

create property User.Email                  STRING
create property User.Firstname              STRING
...

And then call it like:

/usr/local/src/orientdb/bin/console.sh createmydb.sh

This works well for my purposes. The DB creation script is very easy to read, can be modified easily. And I am sure very backwards compatible (which may not have been the case with importing an exported JSON version of the db schema).

So far I've found that pre-loading the schema using an external definition stored in either JSON or OSQL has been most successful for me. Currently I am using an OSQL script that contains a whole bunch of CREATE CLASS ... and CREATE PROPERTY ... commands. It works well enough.

Pretty soon I'll have to start supporting dynamic changes to the data model, at which point I will have to write code to read a JSON schema definition and convert that to appropriate calls into OrientDB, either through the Blueprints API or through SQL batches.

I've not found a tool that does what you need "automatically." If you find one, please let me (and everyone else here) know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM