Projet

Général

Profil

« Précédent | Suivant » 

Révision 3afe385b

Ajouté par Benjamin Dauvergne il y a plus de 9 ans

Add command to create missing tenant schemas

refs #5106

Voir les différences:

entrouvert/djommon/multitenant/management/commands/create_schema.py
1
from django.core.management.base import BaseCommand
2
from entrouvert.djommon.multitenant.middleware import TenantMiddleware
3
from django.db import connection
4

  
5
class Command(BaseCommand):
6
    help = "Create schemas"
7

  
8
    def handle(self, *args, **options):
9
        verbosity = int(options.get('verbosity'))
10

  
11
        connection.set_schema_to_public()
12
        all_tenants = TenantMiddleware.get_tenants()
13
        for tenant in all_tenants:
14
            if verbosity >= 1:
15
                print
16
                print self.style.NOTICE("=== Creating schema ") \
17
                    + self.style.SQL_TABLE(tenant.schema_name)
18

  
19
            if not tenant.create_schema(check_if_exists=True):
20
                print self.style.ERROR(' Nothing to do')

Formats disponibles : Unified diff