Esempio n. 1
0
    def migrate_tenant_apps(self, schema_name=None):
        self._save_south_settings()

        apps = self.tenant_apps or self.installed_apps
        self._set_managed_apps(included_apps=apps,
                               excluded_apps=self.shared_apps)

        migrate_command = MigrateCommand()
        if schema_name:
            print self.style.NOTICE("=== Running migrate for schema: %s" %
                                    schema_name)
            connection.set_schema_to_public()
            sync_tenant = get_tenant_model().objects.filter(
                schema_name=schema_name).get()
            connection.set_tenant(sync_tenant, include_public=False)
            migrate_command.execute(**self.options)
        else:
            public_schema_name = get_public_schema_name()
            tenant_schemas_count = get_tenant_model().objects.exclude(
                schema_name=public_schema_name).count()
            if not tenant_schemas_count:
                print self.style.NOTICE("No tenants found")

            for tenant_schema in get_tenant_model().objects.exclude(
                    schema_name=public_schema_name).all():
                Migrations._dependencies_done = False  # very important, the dependencies need to be purged from cache
                print self.style.NOTICE("=== Running migrate for schema %s" %
                                        tenant_schema.schema_name)
                connection.set_tenant(tenant_schema, include_public=False)
                migrate_command.execute(**self.options)

        self._restore_south_settings()
Esempio n. 2
0
    def migrate_public_apps(self):
        self._save_south_settings()

        apps = self.shared_apps or self.installed_apps
        self._set_managed_apps(included_apps=apps,
                               excluded_apps=self.tenant_apps)

        self._notice("=== Running migrate for schema public")
        MigrateCommand().execute(*self.args, **self.options)

        self._clear_south_cache()
        self._restore_south_settings()
Esempio n. 3
0
 def _migrate_schema(self, tenant):
     connection.set_tenant(tenant, include_public=False)
     MigrateCommand().execute(*self.args, **self.options)