Skip to content

Commit

Permalink
Refactored migrate schemas.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardopires committed Jul 30, 2015
1 parent 52aa064 commit dee48dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
10 changes: 9 additions & 1 deletion tenant_schemas/management/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from django.core.management import call_command, get_commands, load_command_class
from django.core.management.base import BaseCommand, NoArgsCommand, CommandError
from django.db import connection
from django.db import connection, DEFAULT_DB_ALIAS

try:
from django.utils.six.moves import input
Expand Down Expand Up @@ -133,6 +133,14 @@ class SyncCommon(BaseCommand):
help='Tells Django to populate only tenant applications.'),
make_option('--shared', action='store_true', dest='shared', default=False,
help='Tells Django to populate only shared applications.'),
make_option('--app_label', action='store', dest='app_label', nargs='?',
help='App label of an application to synchronize the state.'),
make_option('--migration_name', action='store', dest='migration_name', nargs='?',
help=('Database state will be brought to the state after that '
'migration. Use the name "zero" to unapply all migrations.' ),
),
make_option('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,

This comment has been minimized.

Copy link
@goodtune

goodtune Aug 1, 2015

Collaborator

This refactoring has introduced and optparse conflict.

optparse.OptionConflictError: option --database: conflicting option string(s): --database

I've bisected from v1.5.2 to master (0b15c16) and this is the first occurrence.

help='Nominates a database to synchronize. Defaults to the "default" database.'),
make_option("-s", "--schema", dest="schema_name"),
)

Expand Down
17 changes: 2 additions & 15 deletions tenant_schemas/management/commands/migrate_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if django.VERSION >= (1, 7, 0):
from django.core.management.commands.migrate import Command as MigrateCommand
from django.db.migrations.recorder import MigrationRecorder
from django.db import connection, DEFAULT_DB_ALIAS
from django.db import connection
from django.conf import settings

from tenant_schemas.utils import get_tenant_model, get_public_schema_name, schema_exists
Expand Down Expand Up @@ -48,20 +48,7 @@ def run_migrations(self, schema_name, included_apps):
self._notice("=== Running migrate for schema %s" % schema_name)
connection.set_schema(schema_name)
command = MigrateCommand()

defaults = {}
for opt in MigrateCommand.option_list:
if opt.dest in self.options:
defaults[opt.dest] = self.options[opt.dest]
elif opt.default is NO_DEFAULT:
defaults[opt.dest] = None
else:
defaults[opt.dest] = opt.default

defaults['database'] = DEFAULT_DB_ALIAS
defaults['app_label'] = None
defaults['migration_name'] = None
command.execute(*self.args, **defaults)
command.execute(*self.args, **self.options)
connection.set_schema_to_public()

def _notice(self, output):
Expand Down

0 comments on commit dee48dc

Please sign in to comment.