def create_tables(): from .registry import model_registry created_tables = r.table_list().run() for model_cls in model_registry.all().values(): if model_cls.table_name not in created_tables: result = r.table_create(model_cls.table_name).run() if result['tables_created'] != 1: raise RuntimeError('Could not create table %s for model %s' % (model_cls.table_name, model_cls.__name__))
def create_table(self, table=None, remove_existing=False): """ Creating a table if not exists, taking for Granted the DB already exists """ if table in r.table_list().run(): logger.debug("Table '" + table + "' already exists.") if remove_existing: r.table_drop(table).run() logger.info("Removed") else: r.table_create(table).run() logger.info("Table '" + table + "' created")
def assert_table_created(self, table): assert table in r.table_list().run()
def assert_table_dropped(self, table): assert table not in r.table_list().run()
def table_exists(self): return self._state.name in r.table_list().run(self._state.conn)