From 3afe385b85dbb3e26d5b18df7146e8451a9342c5 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 20 Aug 2014 14:57:02 +0200 Subject: [PATCH] Add command to create missing tenant schemas refs #5106 --- .../management/commands/create_schema.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 entrouvert/djommon/multitenant/management/commands/create_schema.py diff --git a/entrouvert/djommon/multitenant/management/commands/create_schema.py b/entrouvert/djommon/multitenant/management/commands/create_schema.py new file mode 100644 index 0000000..46cba7f --- /dev/null +++ b/entrouvert/djommon/multitenant/management/commands/create_schema.py @@ -0,0 +1,20 @@ +from django.core.management.base import BaseCommand +from entrouvert.djommon.multitenant.middleware import TenantMiddleware +from django.db import connection + +class Command(BaseCommand): + help = "Create schemas" + + def handle(self, *args, **options): + verbosity = int(options.get('verbosity')) + + connection.set_schema_to_public() + all_tenants = TenantMiddleware.get_tenants() + for tenant in all_tenants: + if verbosity >= 1: + print + print self.style.NOTICE("=== Creating schema ") \ + + self.style.SQL_TABLE(tenant.schema_name) + + if not tenant.create_schema(check_if_exists=True): + print self.style.ERROR(' Nothing to do')