nextstrain / flora

DB management, APIs, web portals etc.
2 stars 3 forks source link

Flora requires databases and tables to exist #4

Open trvrb opened 6 years ago

trvrb commented 6 years ago

Currently, running python scripts/run.py --db lassa upload --filename ../sacra/output/lassa.json when there is no existing lassa database results in the following error:

Traceback (most recent call last):
  File "scripts/run.py", line 63, in <module>
    args.func(**vars(args))
  File "/Users/trvrb/Documents/src/flora/scripts/upload.py", line 31, in upload
    modify_db(rdb, table_name, rows, tables_primary_keys[table_name], preview, **kwargs)
  File "/Users/trvrb/Documents/src/flora/scripts/upload.py", line 43, in modify_db
    primary_keys_db = set(rdb.table(table_name).get_all(*primary_keys_sacra).get_field(pkey).run())
  File "/usr/local/lib/python2.7/site-packages/rethinkdb/ast.py", line 123, in run
    return c._start(self, **global_optargs)
  File "/usr/local/lib/python2.7/site-packages/rethinkdb/net.py", line 625, in _start
    return self._instance.run_query(q, global_optargs.get('noreply', False))
  File "/usr/local/lib/python2.7/site-packages/rethinkdb/net.py", line 471, in run_query
    raise res.make_error(query)
rethinkdb.errors.ReqlOpFailedError: Database `lassa` does not exist in:

Just like directories, if a Rethink database doesn't exist. Flora should create it.

Also, even if lassa database exists, flora crashes if the lassa database doesn't already have strains, samples, etc... tables.

jameshadfield commented 6 years ago

Hmm, I disagree. Flora has the commands to create tables, clear tables etc (python scripts/run.py -h). In my opinion, one should be appropriately warned if they're trying to push to a non-existent table, as it may be a typo or unintended. But I do agree the error should be caught and a nice message printed telling one how to create the appropriate tables.

trvrb commented 6 years ago

Okay. This makes sense to me. I didn't realize there was a command to create tables (I see it now in readme --- sorry). I would have this be a single command called something like initialize that creates the lassa db and its necessary strains, etc.. tables.