-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from macbre/single_column
Report tables with just a single column
- Loading branch information
Showing
7 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
""" | ||
This linter reports tables with just a single column | ||
""" | ||
from indexdigest.utils import LinterEntry | ||
|
||
|
||
def check_single_column(database): | ||
""" | ||
:type database indexdigest.database.Database | ||
:rtype: list[LinterEntry] | ||
""" | ||
tables = [ | ||
table | ||
for table in database.get_tables() | ||
if len(database.get_table_columns(table)) == 1 | ||
] | ||
|
||
for table in tables: | ||
yield LinterEntry(linter_type='single_column', table_name=table, | ||
message='"{}" has just a single column'. | ||
format(table), | ||
context={'schema': database.get_table_schema(table)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from __future__ import print_function | ||
|
||
from unittest import TestCase | ||
|
||
from indexdigest.linters import check_single_column | ||
from indexdigest.test import DatabaseTestMixin | ||
|
||
|
||
class TestSingleColumn(TestCase, DatabaseTestMixin): | ||
|
||
def test_check_single_column(self): | ||
reports = list(check_single_column(self.connection)) | ||
|
||
print(list(map(str, reports))) | ||
|
||
self.assertEqual(len(reports), 1) | ||
|
||
self.assertEqual(str(reports[0]), | ||
'0074_bag_of_ints: "0074_bag_of_ints" has just a single column') | ||
self.assertTrue('CREATE TABLE `0074_bag_of_ints` (' in reports[0].context['schema']) | ||
|
||
# assert False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- Report tables with just a single column | ||
-- | ||
-- https://github.com/macbre/index-digest/issues/74 | ||
DROP TABLE IF EXISTS `0074_bag_of_ints`; | ||
CREATE TABLE `0074_bag_of_ints` ( | ||
`id` int(9) NOT NULL AUTO_INCREMENT, | ||
PRIMARY KEY (`id`) | ||
) CHARSET=utf8; |