Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

orientdb

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).

like image 870
Sat Thiru Avatar asked Sep 29 '22 13:09

Sat Thiru


1 Answers

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).

like image 196
Sat Thiru Avatar answered Oct 06 '22 20:10

Sat Thiru