Project

General

Profile

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

root / entrouvert / djommon / multitenant / management / commands / create_schemas.py @ 01a055c6

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 for all declared tenants"
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
            tenant.create_schema(check_if_exists=True)
(2-2/12)