I'm attempting to create a schema for my OrientDB and it's proving quite 
challenging to make the process repeatable. That is, I'm coming from a 
MySQL realm and my peers really want to see the schema in place, plus we're 
deploying the DB in many different instances and want to be able to 
recreate the DB in each instance when we set them up.

 I've resorted to using console.sh. Even that is cumbersome and doesn't 
work as documented. The doc here: 
http://orientdb.com/docs/last/Console-Commands.html says that you should be 
able do do something like 'console.<sh|bat> commands.txt'. That doesn't 
seem to work as console starts up and then  tries to run commands.txt as 
the command.

My solution so far has been to create a commands.txt file with contents 
like:

set ignoreErrors true;
DROP DATABASE remote:localhost/<DBNAME> admin admin;
set ignoreErrors false;

# Create the database as plocal for persistent storage;
CREATE DATABASE remote:localhost/<DBNAME> admin admin plocal graph;

CREATE CLASS <YourClass> extends V;

CREATE PROPERTY <YourClass>.<NAME> string;
ALTER PROPERTY <YourClass>.<NAME> MANDATORY=true;
ALTER PROPERTY <YourClass>.<NAME> NOTNULL=true;
--->8 snip 8<---

There are more things in it to create more classes which extend V and 
others that extend E.

Then, I execute the script as such:

$ /path/to/orientdb/bin/console.sh `cat /path/to/commands.txt`
NOTES:
- Those are back-ticks around the `cat /path/to/commands.txt` such that it 
ends up being the commands which will be run in console.
- Using this method is subject to command line length limits... Which means 
that I've broken some things up into multiple files to do this.

I'm attempting to do something with the REST API, but that's not as 
functional as I had hoped. I thought I could collapse the CREATE 
PROPERTY/ALTER PROPERTY commands into a single JSON post, but that doesn't 
seem to work either.

Once I've got the DB in place, I am attempting to do a POST operation as 
such (here's a snippet of python):

req_json = {
    'propFoo': {'propertyType': 'STRING', 'mandatory': 'true', 'notNull': 
'true'},
    'propBar': {'propertyType': 'STRING', 'mandatory': 'true', 'notNull': 
'true'},
    'propBaz': {'propertyType': 'STRING', 'mandatory': 'true', 'notNull': 
'true'},
}

# Create the MyFirstClass class properties
print "create enclosure class properties"
res = requests.post(
    'http://localhost:2480/property/DEMO/MyFirstClass',
    auth=HTTPBasicAuth('admin', 'admin'),
    json=req_json
)

Then, listing the class, I see the properties created, but mandatory and 
notNull are still false:
    "properties": [
        {
            "collate": "default",
            "mandatory": false,
            "max": null,
            "min": null,
            "name": "propFoo",
            "notNull": false,
            "readonly": false,
            "regexp": null,
            "type": "STRING"
        },
        {
            "collate": "default",
            "mandatory": false,
            "max": null,
            "min": null,
            "name": "propBar",
            "notNull": false,
            "readonly": false,
            "regexp": null,
            "type": "STRING"
        },
        {
            "collate": "default",
            "mandatory": false,
            "max": null,
            "min": null,
            "name": "propBaz",
            "notNull": false,
            "readonly": false,
            "regexp": null,
            "type": "STRING"
        }
    ],

What am I missing here? How can one easily define a schema in a file and 
load it into OrientDB? I'm really looking for the equivalent to something 
like "mysql -u username -p password database_name < filename.sql".

Thanks
-Tim

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to