diff --git a/datajoint/schemas.py b/datajoint/schemas.py index a708db3ce..6dc3777ed 100644 --- a/datajoint/schemas.py +++ b/datajoint/schemas.py @@ -288,6 +288,17 @@ def repl(s): with open(python_filename, 'wt') as f: f.write(python_code) + def list_tables(self): + """ + Return a list of all tables in the schema except tables with ~ in first character such + as ~logs and ~job + :return: A list of table names in their raw datajoint naming convection form + """ + + return [table_name for (table_name,) in self.connection.query(""" + SELECT table_name FROM information_schema.tables + WHERE table_schema = %s and table_name NOT LIKE '~%%'""", args=(self.database))] + class VirtualModule(types.ModuleType): """ diff --git a/tests/test_schema.py b/tests/test_schema.py index 98ec3e7f5..2d868b60d 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -4,6 +4,7 @@ from . import schema from . import schema_empty from . import PREFIX, CONN_INFO +from .schema_simple import schema as schema_simple def relation_selector(attr): @@ -105,6 +106,11 @@ class Unit(dj.Part): test_schema.drop() +def test_list_tables(): + assert(['#a', '#argmax_test', '#data_a', '#data_b', '#i_j', '#j_i', '#l',\ + '#t_test_update', '__b', '__b__c', '__d', '__e', '__e__f', 'f',\ + 'reserved_word'] == schema_simple.list_tables()) + def test_schema_save(): assert_true("class Experiment(dj.Imported)" in schema.schema.code)