Tenant — Schema Manager¶
Le Schema Manager orchestre le cycle de vie complet des schémas PostgreSQL pour les tenants (création, migration, clonage, backup, restauration).
Module : src.module.tenant.infrastructure.schema_manager
Fonctions principales¶
- src.module.tenant.infrastructure.schema_manager.create_schema(tenant) None¶
Crée le schéma PostgreSQL pour un tenant et exécute les migrations initiales.
Délègue au backend d’isolation configuré.
- src.module.tenant.infrastructure.schema_manager.clone_schema(source_tenant, target_slug: str) None¶
Clone le schéma d’un tenant source vers un nouveau tenant. Copie les tables et les données.
Utile pour créer des environnements de test ou des sandbox.
from src.module.tenant.infrastructure.schema_manager import clone_schema clone_schema(production_tenant, "staging-acme")
- src.module.tenant.infrastructure.schema_manager.drop_schema(tenant, *, backup: bool = False) None¶
Supprime le schéma d’un tenant.
- Parameters:
tenant – Tenant à supprimer
backup – Si
True, effectue un backup avant la suppression
Warning
DESTRUCTIF. Toutes les données du tenant sont perdues.
- src.module.tenant.infrastructure.schema_manager.migrate_schema(tenant) None¶
Applique les migrations Django au schéma d’un tenant spécifique.
- src.module.tenant.infrastructure.schema_manager.migrate_all_schemas() dict[str, bool]¶
Migre tous les schémas tenant en batch.
- Returns:
Dictionnaire
{schema_name: success}pour chaque tenant.
from src.module.tenant.infrastructure.schema_manager import migrate_all_schemas results = migrate_all_schemas() failed = {k: v for k, v in results.items() if not v} if failed: print(f"Échec de migration pour : {list(failed.keys())}")
Introspection¶
- src.module.tenant.infrastructure.schema_manager.schema_exists(schema_name: str) bool¶
Vérifie si un schéma PostgreSQL existe.
Backup et Restauration¶
Database Router¶
Module : src.module.tenant.infrastructure.db_router