Browse Source

feat(spip): ajoute la prise en compte d un préfixe de tables

wip_revisions
François Poulain 1 year ago
parent
commit
db85024859
  1. 4
      Makefile
  2. 10
      drupal2spip_lal/base/checks.py
  3. 8
      drupal2spip_lal/base/management/commands/inspectdb.py
  4. 2
      drupal2spip_lal/settings/base.py

4
Makefile

@ -1,5 +1,6 @@
# -*- mode: makefile-gmake -*-
## Définition des variables
SHELL := /bin/bash
# Le nom de l'exécutable Python à utiliser ou son chemin absolu
# (ex. : python ou python3).
PYTHON_EXE := python3
@ -120,8 +121,9 @@ ifeq ($(ENV), production)
endif
inspectdb: ### introspecte le schéma de base de donnée
$(PYTHON) manage.py inspectdb --database=drupal > drupal2spip_lal/drupal/models.py
$(PYTHON) manage.py inspectdb --database=spip > drupal2spip_lal/spip/models.py
source config.env && $(PYTHON) manage.py inspectdb --database=spip --tables-prefix=$$SPIP_TABLES_PREFIX > drupal2spip_lal/spip/models.py
## Cibles liées à l'environnement virtuel

10
drupal2spip_lal/base/checks.py

@ -1,18 +1,22 @@
import io
from difflib import unified_diff
from django.conf import settings
from django.core.checks import Error, Warning, register
from django.core.management import call_command
@register()
def check_inspected_databases(app_configs, **kwargs):
return check_inspected_db('drupal') + check_inspected_db('spip')
r = []
r += check_inspected_db('drupal')
r += check_inspected_db('spip', tables_prefix=settings.SPIP_TABLES_PREFIX)
return r
def check_inspected_db(dbname):
def check_inspected_db(dbname, **kwargs):
buf = io.StringIO()
rc = call_command('inspectdb', '--database', dbname, stdout=buf)
rc = call_command('inspectdb', '--database', dbname, stdout=buf, **kwargs)
if rc is not None:
return [
Error(

8
drupal2spip_lal/base/management/commands/inspectdb.py

@ -24,6 +24,10 @@ class Command(BaseCommand):
parser.add_argument(
'--include-partitions', action='store_true', help='Also output models for partition tables.',
)
parser.add_argument(
'--tables-prefix', nargs='?', type=str, default='',
help='Tables prefix to be stripped from model names.',
)
parser.add_argument(
'--include-views', action='store_true', help='Also output models for database views.',
)
@ -40,7 +44,11 @@ class Command(BaseCommand):
# 'table_name_filter' is a stealth option
table_name_filter = options.get('table_name_filter')
tables_prefix = options['tables_prefix']
def table2model(table_name):
if tables_prefix and table_name.startswith(tables_prefix):
table_name = table_name[len(tables_prefix):]
return re.sub(r'[^a-zA-Z0-9]', '', table_name.title())
with connection.cursor() as cursor:

2
drupal2spip_lal/settings/base.py

@ -66,6 +66,8 @@ DATABASES = {
),
}
SPIP_TABLES_PREFIX = env('SPIP_TABLES_PREFIX', default='spip')
DATABASE_ROUTERS = ['drupal2spip_lal.base.routers.Drupal2SPIPRouter']
# URLS

Loading…
Cancel
Save