# Path: django_sharding_library/exceptions.py
# class InvalidMigrationException(DjangoShardingException):
#     pass


from django.conf import settings
from django.core.management.commands.migrate import Command as MigrationCommand
from django_sharding_library.exceptions import InvalidMigrationException



class Command(MigrationCommand):
    def handle(self, *args, **options):
        if not options['database'] or options['database'] == 'all':
            databases = self.get_all_but_replica_dbs()
        elif options['database'] not in self.get_all_but_replica_dbs():

# Path: django_sharding_library/exceptions.py
# class InvalidMigrationException(DjangoShardingException):
#     pass


# Path: django_sharding_library/management/commands/migrate.py
from django.conf import settings
from django.core.management.commands.migrate import Command as MigrationCommand
from django_sharding_library.exceptions import InvalidMigrationException




class Command(MigrationCommand):
    def handle(self, *args, **options):
        if not options['database'] or options['database'] == 'all':
            databases = self.get_all_but_replica_dbs()
        elif options['database'] not in self.get_all_but_replica_dbs():

            raise InvalidMigrationException('You must migrate an existing non-primary DB.')