-
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.
check_missing_primary_index: add test cases and tables for #34
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
indexdigest/test/linters/test_0034_missing_primary_index.py
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,33 @@ | ||
from __future__ import print_function | ||
|
||
from unittest import TestCase | ||
|
||
from indexdigest.linters import check_missing_primary_index | ||
from indexdigest.test import Database, DatabaseTestMixin | ||
|
||
|
||
class LimitedViewDatabase(Database, DatabaseTestMixin): | ||
""" | ||
Limit test to tables from sql/0034-missing-primary-index | ||
""" | ||
def get_tables(self): | ||
return ['0034_with_primary_key', '0034_with_unique_key', '0034_querycache'] | ||
|
||
|
||
class TestMissingPrimaryIndex(TestCase): | ||
@property | ||
def connection(self): | ||
return LimitedViewDatabase.connect_dsn(DatabaseTestMixin.DSN) | ||
|
||
def test_missing_primary_index(self): | ||
reports = list(check_missing_primary_index(self.connection)) | ||
|
||
print(list(map(str, reports))) | ||
|
||
self.assertEqual(len(reports), 1) | ||
|
||
self.assertEqual(str(reports[0]), | ||
'0034_querycache: "0034_querycache" table does not have any primary or unique index') | ||
self.assertTrue('CREATE TABLE `0034_querycache` (' 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Report missing primary or unique keys | ||
-- | ||
-- https://github.com/macbre/index-digest/issues/34 | ||
DROP TABLE IF EXISTS `0034_with_primary_key`; | ||
CREATE TABLE `0034_with_primary_key` ( | ||
`id` int(9) NOT NULL AUTO_INCREMENT, | ||
`name` varchar(255) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) CHARSET=utf8; | ||
|
||
DROP TABLE IF EXISTS `0034_with_unique_key`; | ||
CREATE TABLE `0034_with_unique_key` ( | ||
`id` int(9) NOT NULL AUTO_INCREMENT, | ||
`name` varchar(255) NOT NULL, | ||
UNIQUE KEY idx (`id`) | ||
) CHARSET=utf8; | ||
|
||
-- https://github.com/Wikia/app/pull/9863 | ||
DROP TABLE IF EXISTS `0034_querycache`; | ||
CREATE TABLE `0034_querycache` ( | ||
`qc_type` varbinary(32) NOT NULL, | ||
`qc_value` int(10) unsigned NOT NULL DEFAULT '0', | ||
`qc_namespace` int(11) NOT NULL DEFAULT '0', | ||
`qc_title` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT '', | ||
KEY `qc_type` (`qc_type`,`qc_value`) | ||
) CHARSET=utf8; |