Skip to content

Commit

Permalink
Merge 8135aff into c24f449
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudum committed Mar 27, 2018
2 parents c24f449 + 8135aff commit 888e3aa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -12,6 +12,8 @@ Changes
If you are using crash with Python 2.7 or 3.3 already, you will not be able
to install newer versions of this package.

- Updated the ``\dt`` command to show only tables, but not views. This is to
be forward compatible with CrateDB 3.0 and greater.

2017/12/15 0.23.0
=================
Expand Down
18 changes: 11 additions & 7 deletions src/crate/crash/command.py
Expand Up @@ -76,6 +76,7 @@ def emit(self, record):
'output_width'])

TABLE_SCHEMA_MIN_VERSION = StrictVersion("0.57.0")
TABLE_TYPE_MIN_VERSION = StrictVersion("2.0.0")


def parse_config_path(args=sys.argv):
Expand Down Expand Up @@ -288,14 +289,17 @@ def exit(self):
@noargs_command
def _show_tables(self, *args):
""" print the existing tables within the 'doc' schema """
v = self.connection.lowest_server_version
schema_name = \
"table_schema" if self.connection.lowest_server_version \
>= TABLE_SCHEMA_MIN_VERSION else "schema_name"

self._exec("select format('%s.%s', {schema}, table_name) as name "
"from information_schema.tables "
"where {schema} not in ('sys','information_schema', 'pg_catalog')"
.format(schema=schema_name))
"table_schema" if v >= TABLE_SCHEMA_MIN_VERSION else "schema_name"
table_filter = \
" AND table_type = 'BASE TABLE'" if v >= TABLE_TYPE_MIN_VERSION else ""

self._exec("SELECT format('%s.%s', {schema}, table_name) AS name "
"FROM information_schema.tables "
"WHERE {schema} NOT IN ('sys','information_schema', 'pg_catalog')"
"{table_filter}"
.format(schema=schema_name, table_filter=table_filter))

@noargs_command
def _quit(self, *args):
Expand Down
11 changes: 9 additions & 2 deletions src/crate/crash/test_commands.py
Expand Up @@ -124,19 +124,26 @@ def test_toggle_output(self, fake_cmd):

class ShowTablesCommandTest(TestCase):

def test_post_2_0(self):
cmd = CrateCmd()
cmd._exec = MagicMock()
cmd.connection.lowest_server_version = StrictVersion("2.0.0")
cmd._show_tables()
cmd._exec.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog') AND table_type = 'BASE TABLE'")

def test_post_0_57(self):
cmd = CrateCmd()
cmd._exec = MagicMock()
cmd.connection.lowest_server_version = StrictVersion("0.57.0")
cmd._show_tables()
cmd._exec.assert_called_with("select format('%s.%s', table_schema, table_name) as name from information_schema.tables where table_schema not in ('sys','information_schema', 'pg_catalog')")
cmd._exec.assert_called_with("SELECT format('%s.%s', table_schema, table_name) AS name FROM information_schema.tables WHERE table_schema NOT IN ('sys','information_schema', 'pg_catalog')")

def test_pre_0_57(self):
cmd = CrateCmd()
cmd._exec = MagicMock()
cmd.connection.lowest_server_version = StrictVersion("0.56.4")
cmd._show_tables()
cmd._exec.assert_called_with("select format('%s.%s', schema_name, table_name) as name from information_schema.tables where schema_name not in ('sys','information_schema', 'pg_catalog')")
cmd._exec.assert_called_with("SELECT format('%s.%s', schema_name, table_name) AS name FROM information_schema.tables WHERE schema_name NOT IN ('sys','information_schema', 'pg_catalog')")

class ChecksCommandTest(TestCase):

Expand Down
2 changes: 1 addition & 1 deletion versions.cfg
Expand Up @@ -31,7 +31,7 @@ tqdm = 4.14.0
twine = 1.9.1
urllib3 = 1.21.1
wheel = 0.29.0
zc.buildout = 2.10.0
zc.buildout = 2.11.2
zc.customdoctests = 1.0.1
zc.recipe.egg = 2.0.3
zc.recipe.testrunner = 2.0.0
Expand Down

0 comments on commit 888e3aa

Please sign in to comment.