diff --git a/README.md b/README.md index db7e8132..c1f001f2 100644 --- a/README.md +++ b/README.md @@ -520,6 +520,14 @@ But sometimes, you might want to have your own sensitive keywords, then above co SILKY_SENSITIVE_KEYS = {'custom-password'} ``` +### Custom Database Tables + +By default, Silk is using below-mentioned table name (they are case insensitive) + +```python +SILKY_DATABASE_TABLES = {'REQUEST': 'silk_request', 'RESPONSE': 'silk_response', + 'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'} +``` ### Clearing logged data diff --git a/project/project/settings.py b/project/project/settings.py index e3586db7..e017a0ac 100644 --- a/project/project/settings.py +++ b/project/project/settings.py @@ -126,3 +126,5 @@ SILKY_MAX_RECORDED_REQUESTS_CHECK_PERCENT = 0 # SILKY_AUTHENTICATION = True # SILKY_AUTHORISATION = True +# SILKY_DATABASE_TABLES = {'REQUEST': 'test_silk_request', 'RESPONSE': 'silk_response', +# 'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'} diff --git a/silk/config.py b/silk/config.py index 8b237340..c81a5d78 100644 --- a/silk/config.py +++ b/silk/config.py @@ -34,7 +34,9 @@ class SilkyConfig(metaclass=Singleton): 'SILKY_ANALYZE_QUERIES': False, 'SILKY_EXPLAIN_FLAGS': None, 'SILKY_SENSITIVE_KEYS': {'username', 'api', 'token', 'key', 'secret', 'password', 'signature'}, - 'SILKY_DELETE_PROFILES': False + 'SILKY_DELETE_PROFILES': False, + 'SILKY_DATABASE_TABLES': {'REQUEST': 'silk_request', 'RESPONSE': 'silk_response', + 'SQLQUERY': 'silk_sqlquery', 'PROFILE': 'silk_profile'} } def _setup(self): diff --git a/silk/models.py b/silk/models.py index b8d1ce17..464db41b 100644 --- a/silk/models.py +++ b/silk/models.py @@ -26,6 +26,7 @@ from silk.utils.profile_parser import parse_profile silk_storage = get_storage_class(SilkyConfig().SILKY_STORAGE_CLASS)() +silk_db_tables = SilkyConfig().SILKY_DATABASE_TABLES # Seperated out so can use in tests w/o models @@ -190,6 +191,9 @@ def save(self, *args, **kwargs): super().save(*args, **kwargs) Request.garbage_collect(force=False) + class Meta: + db_table = silk_db_tables['REQUEST'] + class Response(models.Model): id = CharField(max_length=36, default=uuid4, primary_key=True) @@ -218,6 +222,9 @@ def headers(self): def raw_body_decoded(self): return base64.b64decode(self.raw_body) + class Meta: + db_table = silk_db_tables['RESPONSE'] + # TODO rewrite docstring class SQLQueryManager(models.Manager): @@ -323,6 +330,9 @@ def delete(self, *args, **kwargs): self.request.save() super().delete(*args, **kwargs) + class Meta: + db_table = silk_db_tables['SQLQUERY'] + class BaseProfile(models.Model): name = CharField(max_length=300, blank=True, default='') @@ -364,3 +374,6 @@ def is_context_profile(self): @property def time_spent_on_sql_queries(self): return sum(x.time_taken for x in self.queries.all()) + + class Meta: + db_table = silk_db_tables['PROFILE']