Project

General

Profile

Download (738 Bytes) Statistics
| Branch: | Tag: | Revision:

root / entrouvert / djommon / multitenant / management / commands / create_schema.py @ 7e82bd8e

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')
(2-2/11)