Développement #102916
disposer d'un outil pour voir si une table SQL est bien celle prévue par le modèle
0%
Description
Quelque chose sur le principe de sqldiff proposé par django_extension : https://github.com/django-extensions/django-extensions/blob/main/django_extensions/management/commands/sqldiff.py
Ca fonctionne à base de connection.introspection, comme combo-manage tenant_command inspectdb
Related issues
History
Updated by Thomas Noël about 2 months ago
Cependant connection.introspection ça n'a pas l'air de fonctionner avec notre système multitenant / tenant_command :
$ combo-manage tenant_command inspectdb # Unable to inspect table 'assets_asset' # The error was: FieldInfo.__new__() missing 1 required positional argument: 'collation' # Unable to inspect table 'auth_group' # The error was: FieldInfo.__new__() missing 1 required positional argument: 'collation' # Unable to inspect table 'auth_group_permissions' # The error was: FieldInfo.__new__() missing 1 required positional argument: 'collation' # Unable to inspect table 'auth_permission' # The error was: FieldInfo.__new__() missing 1 required positional argument: 'collation' # Unable to inspect table 'auth_user' # The error was: FieldInfo.__new__() missing 1 required positional argument: 'collation' ... (même chose sur toute les tables)
J'ai les mêmes erreurs en cherchant à utiliser sqldiff de django_extensions.
(J'arrête ici mes investigations, je n'ai rien trouvé d'évident)
Updated by Thomas Noël about 2 months ago
https://github.com/django-tenants/django-tenants/pull/693 ... comme quoi la migration vers django-tenants nous ferait sans doute du bien.
Updated by Thomas Noël about 2 months ago
- Related to Développement #102921: django-tenant-schemas: prendre le introspection.py de django-tenants added
Updated by Thomas Noël about 2 months ago
Avec #102921 dans django-tenant-schemas j'ai un sqldiff qui fonctionne avec un minimum d'adaptations, qu'on pourrait poser dans hobo/multitenant/management. Mais ça indique un peu trop de fausses différences (soi-disant qu'il manque des "NOT NULL" un peu partout, ou qu'il faut remplacer un type "smallint" par un type "smallint" heu oui bon). Je vais voir si je peux corriger ça. Bonne piste, en tout cas.
Updated by Robot Gitea about 2 months ago
- Status changed from Nouveau to En cours
- Assignee set to Thomas Noël
Thomas NOËL (tnoel) a ouvert une pull request sur Gitea concernant cette demande :
- URL : https://git.entrouvert.org/entrouvert/hobo/pulls/214
- Titre : WIP: multitenant: add sqldiff command (#102916)
- Modifications : https://git.entrouvert.org/entrouvert/hobo/pulls/214/files
Updated by Thomas Noël about 2 months ago
Avec le patch proposé, j'obtiens un sqldiff pas trop verbeux mais qui semble encore afficher des choses "peut-être pas problématiques".
Sur mes instances combo locales, en affichage "SQL" :
(publik-env-py3) thomas@zepo:~/src/hobo [wip/102916-add-sqldiff-command|…1]$ combo-manage tenant_command sqldiff -a -e --all-tenants -v3 * Running command sqldiff on tenant agent-combo.dev.publik.love BEGIN; -- Application: maps -- Model: MapLayerOptions ALTER TABLE "maps_map_layers" DROP CONSTRAINT "maps_map_layers_map_id_maplayer_id_c274da74_uniq"; ALTER TABLE "maps_map_layers" ADD CONSTRAINT "maps_map_layers_map_cell_id_map_layer_id_7e3d4c3f_uniq" UNIQUE ("map_cell_id", "map_layer_id"); COMMIT; * Running command sqldiff on tenant combo.dev.publik.love BEGIN; -- Application: maps -- Model: MapLayerOptions ALTER TABLE "maps_map_layers" DROP CONSTRAINT "maps_map_layers_map_id_maplayer_id_c274da74_uniq"; ALTER TABLE "maps_map_layers" ADD CONSTRAINT "maps_map_layers_map_cell_id_map_layer_id_7e3d4c3f_uniq" UNIQUE ("map_cell_id", "map_layer_id"); COMMIT;
Et en affichage "texte" (option -t) :
(publik-env-py3) thomas@zepo:~/src/hobo [wip/102916-add-sqldiff-command|…1]$ combo-manage tenant_command sqldiff -a -e -t --all-tenants -v3 * Running command sqldiff on tenant agent-combo.dev.publik.love + Application: maps |-+ Differences for model: MapLayerOptions |--+ field 'maps_map_layers_map_id_maplayer_id_c274da74_uniq' UNIQUE defined in database schema but missing in model |--+ field 'map_cell_id, map_layer_id' UNIQUE named 'maps_map_layers_map_cell_id_map_layer_id_7e3d4c3f_uniq' defined in model but missing in database * Running command sqldiff on tenant combo.dev.publik.love + Application: maps |-+ Differences for model: MapLayerOptions |--+ field 'maps_map_layers_map_id_maplayer_id_c274da74_uniq' UNIQUE defined in database schema but missing in model |--+ field 'map_cell_id, map_layer_id' UNIQUE named 'maps_map_layers_map_cell_id_map_layer_id_7e3d4c3f_uniq' defined in model but missing in database
Sur chrono l'intérêt est un peu plus parlant :
$ chrono-manage tenant_command sqldiff -a -e -t --all-tenants -v3 * Running command sqldiff on tenant chrono.dev.publik.love + Application: agendas |-+ Differences for model: TimePeriod |--+ field 'date_xor_weekday' INDEX defined in database schema but missing in model |-+ Differences for model: Event |--+ field 'tstzrange_constraint' INDEX defined in database schema but missing in model |--+ field '_ignore_reason' defined in database but missing in model |--+ field '' INDEX named 'agendas_event__11d3b318_idx' defined in model but missing in database |--+ field '' INDEX named 'agendas_event__11d3b318_idx' defined in model but missing in database |--+ field '' INDEX named 'agendas_event__11d3b318_idx' defined in model but missing in database |-+ Differences for model: BookingColor |--+ field 'agendas_bookingcolor_label_e4264816_uniq' UNIQUE defined in database schema but missing in model |-+ Differences for model: SharedCustodyAgenda |--+ field 'unique_child_no_date_end' INDEX defined in database schema but missing in model |--+ field 'child_id' UNIQUE named 'agendas_sharedcustodyagenda_child_id_52978d84_uniq' defined in model but missing in database
On voit surtout :
|--+ field 'tstzrange_constraint' INDEX defined in database schema but missing in model |--+ field '_ignore_reason' defined in database but missing in model
qui sont deux champs effectivement ajoutés juste dans le SQL lors d'une migration "sauvage" (en SQL pur, qu'on devrait éviter à l'avenir). C'est ce genre d'alerte qu'on veut.
Voilà où j'en suis, je me pose maintenant ces questions :- ai-je été trop brutal sur les moments commentés "EO patch" qui annulent certaines différences que j'ai jugées être de fausses alertes
- il faut comprendre d'où viennent les messages ci-dessus parlant de « agendas_event__11d3b318_idx » ou « maps_map_layers_map_id_maplayer_id_c274da74_uniq » ... on dirait des fausses alertes
- finalement, est-ce que je reprends tout, parce que c'est un peu fatras (mais ça me semble pas mal de boulot)
- déjà peut-être nettoyer encore sqldiff.py pour focaliser sur nos usages (uniquement postgresql) au risque de diverger encore plus du sqldiff de django-extensions
Je m'arrête un peu ici pour l'instant, y'a d'autres choses à faire :/ Peut-être chercher ailleurs si d'autres personnes ont travaillé sur ce sujet (j'ai sauté rapidement sur sqldiff).