From 892944927aaa1e823bf64246ce2bd5ff40fe6bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Poulain?= Date: Mon, 3 Aug 2020 16:57:09 +0200 Subject: [PATCH] fix(inspectdb): va au bout de la logique des pefixes de table --- .../base/management/commands/inspectdb.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drupal2spip_lal/base/management/commands/inspectdb.py b/drupal2spip_lal/base/management/commands/inspectdb.py index 67b9927..d3d2898 100644 --- a/drupal2spip_lal/base/management/commands/inspectdb.py +++ b/drupal2spip_lal/base/management/commands/inspectdb.py @@ -4,7 +4,7 @@ import re from django.core.management.base import BaseCommand, CommandError from django.db import DEFAULT_DB_ALIAS, connections from django.db.models.constants import LOOKUP_SEP - +from django.utils.text import camel_case_to_spaces # On reconstruit ici la hiérarchie de la DB que les dev php n'ont pas été # capables de spécifier en sql. On en profite pour donner des noms explicites. @@ -160,13 +160,14 @@ class Command(BaseCommand): types.add('v') for table_name in (options['table'] or sorted(info.name for info in table_info if info.type in types)): + unprefixed_table_name = camel_case_to_snake(table2model(table_name)) if table_name_filter is not None and callable(table_name_filter): if not table_name_filter(table_name): continue try: try: relations = connection.introspection.get_relations(cursor, table_name) - relations.update(DB_RELATIONS[options['database']].get(table_name, {})) + relations.update(DB_RELATIONS[options['database']].get(unprefixed_table_name, {})) except NotImplementedError: relations = {} try: @@ -404,3 +405,10 @@ class Command(BaseCommand): tup = '(' + ', '.join(unique_together) + ',)' meta += [" unique_together = %s" % tup] return meta + + +def camel_case_to_snake(value): + """ + Split CamelCase and convert to snakecase. + """ + return camel_case_to_spaces(value).replace(' ', '_')