Skip to content

Commit

Permalink
Merge pull request #312 from fabalcu97/master
Browse files Browse the repository at this point in the history
Added database support to validate schemas
  • Loading branch information
tomturner committed Oct 27, 2019
2 parents 855453f + d02a4ee commit c442d67
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion django_tenants/management/commands/migrate_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def handle(self, *args, **options):
executor.run_migrations(tenants=[self.PUBLIC_SCHEMA_NAME])
if self.sync_tenant:
if self.schema_name and self.schema_name != self.PUBLIC_SCHEMA_NAME:
if not schema_exists(self.schema_name):
if not schema_exists(self.schema_name, self.options.get('database', None)):
raise RuntimeError('Schema "{}" does not exist'.format(
self.schema_name))
else:
Expand Down
2 changes: 1 addition & 1 deletion django_tenants/migration_executors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def style_func(msg):
msg
)

connection = connections[get_tenant_database_alias()]
connection = connections[options.get('database', get_tenant_database_alias())]
connection.set_schema(schema_name)

stdout = OutputWrapper(sys.stdout)
Expand Down
4 changes: 2 additions & 2 deletions django_tenants/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def django_is_in_test_mode():
return hasattr(mail, 'outbox')


def schema_exists(schema_name):
_connection = connections[get_tenant_database_alias()]
def schema_exists(schema_name, database=get_tenant_database_alias()):
_connection = connections[database]
cursor = _connection.cursor()

# check if this schema already exists in the db
Expand Down

0 comments on commit c442d67

Please sign in to comment.