Project

General

Profile

« Previous | Next » 

Revision 3afe385b

Added by Benjamin Dauvergne over 10 years ago

Add command to create missing tenant schemas

refs #5106

View differences:

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')

Also available in: Unified diff