Skip to content

Commit

Permalink
Merge pull request #321 from mikicz/ignore-missing-schemas
Browse files Browse the repository at this point in the history
Raising an exception when a schema is missing, added an option to migrate_schemas to ignore this error
  • Loading branch information
bernardopires committed Sep 21, 2016
2 parents 65bf9da + c4129e5 commit 5d33237
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ The options given to ``migrate_schemas`` are also passed to every ``migrate``. H
./manage.py migrate_schemas --list
``migrate_schemas`` raises an exception when an tenant schema is missing.

tenant_command
~~~~~~~~~~~~~~

Expand Down
8 changes: 7 additions & 1 deletion tenant_schemas/management/commands/migrate_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.core.management.commands.migrate import Command as MigrateCommand
from django.db import connection
from django.db.migrations.exceptions import MigrationSchemaMissing


from tenant_schemas.management.commands import SyncCommon
Expand Down Expand Up @@ -37,7 +38,7 @@ def handle(self, *args, **options):
if self.sync_tenant:
if self.schema_name and self.schema_name != self.PUBLIC_SCHEMA_NAME:
if not schema_exists(self.schema_name):
raise RuntimeError('Schema "{}" does not exist'.format(
raise MigrationSchemaMissing('Schema "{}" does not exist'.format(
self.schema_name))
else:
self.run_migrations(self.schema_name, settings.TENANT_APPS)
Expand All @@ -49,6 +50,11 @@ def handle(self, *args, **options):
def run_migrations(self, schema_name, included_apps):
if int(self.options.get('verbosity', 1)) >= 1:
self._notice("=== Running migrate for schema %s" % schema_name)

if not schema_exists(schema_name):
raise MigrationSchemaMissing('Schema "{}" does not exist'.format(
schema_name))

connection.set_schema(schema_name)
command = MigrateCommand()
command.execute(*self.args, **self.options)
Expand Down

0 comments on commit 5d33237

Please sign in to comment.