Project

General

Profile

0009-Add-command-to-create-missing-tenant-schemas.patch

Benjamin Dauvergne, 20 August 2014 03:23 PM

Download (1.47 KB)

View differences:

Subject: [PATCH 09/10] Add command to create missing tenant schemas

 .../management/commands/create_schema.py           |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 entrouvert/djommon/multitenant/management/commands/create_schema.py
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')
0
-