data_migration/services/graph.py
def prepare_migration_state(self):
        """Migrates the django migration graph until dependencies are applied"""
        # Get the database we're operating from
        connection = connections['default']

        # Work out which apps have migrations and which do not
        executor = MigrationExecutor(connection)
        pre_migrate_state = executor._create_project_state(
            with_applied_migrations=True)
        migration_graph_in_place = True

        if self.migration_dependencies:
            recorder = MigrationRecorder(connections['default'])
            applied_migrations = recorder.applied_migrations()
            unapplied_dependencies = list()
            for dependency in self.migration_dependencies:
                plan = dependency.split('.')
                plan = tuple([plan[-2], plan[-1]])
                if plan not in applied_migrations:
                    unapplied_dependencies.append(plan)

            if unapplied_dependencies:
                try:
                    plan = executor.migration_plan(unapplied_dependencies)
                    executor.migrate(
                        unapplied_dependencies,
                        plan=plan,
                        state=pre_migrate_state.clone()
                    )
                    migration_graph_in_place = True
                except NodeNotFoundError as ex:
                    for dep in unapplied_dependencies:
                        if not recorder.migration_qs.filter(
                                app=dep[0],
                                name__icontains=dep[1]
                        ).exists():
                            raise ex

            if not migration_graph_in_place:
                migration_graph_in_place = (
                    recorder
                    .migration_qs
                    .filter(app=self.node.app_name)
                    .order_by('-pk').first() in self.migration_dependencies
                )

        return migration_graph_in_place
Migrates the django migration graph until dependencies are applied
Migrates the django migration graph until dependencies are applied
Migrates the django migration graph until dependencies are applied
def prepare_migration_state(self):
        connection = connections['default']
        executor = MigrationExecutor(connection)
        pre_migrate_state = executor._create_project_state(
            with_applied_migrations=True)
        migration_graph_in_place = True
        if self.migration_dependencies:
            recorder = MigrationRecorder(connections['default'])
            applied_migrations = recorder.applied_migrations()
            unapplied_dependencies = list()
            for dependency in self.migration_dependencies:
                plan = dependency.split('.')
                plan = tuple([plan[-2], plan[-1]])
                if plan not in applied_migrations:
                    unapplied_dependencies.append(plan)
            if unapplied_dependencies:
                try:
                    plan = executor.migration_plan(unapplied_dependencies)
                    executor.migrate(
                        unapplied_dependencies,
                        plan=plan,
                        state=pre_migrate_state.clone()
                    )
                    migration_graph_in_place = True
                except NodeNotFoundError as ex:
                    for dep in unapplied_dependencies:
                        if not recorder.migration_qs.filter(
                                app=dep[0],
                                name__icontains=dep[1]
                        ).exists():
                            raise ex
            if not migration_graph_in_place:
                migration_graph_in_place = (
                    recorder
                    .migration_qs
                    .filter(app=self.node.app_name)
                    .order_by('-pk').first() in self.migration_dependencies
                )
        return migration_graph_in_place
def prepare_migration_state ( self ) : connection = connections [ 'default' ] executor = MigrationExecutor ( connection ) pre_migrate_state = executor . _create_project_state ( with_applied_migrations = True ) migration_graph_in_place = True if self . migration_dependencies : recorder = MigrationRecorder ( connections [ 'default' ] ) applied_migrations = recorder . applied_migrations ( ) unapplied_dependencies = list ( ) for dependency in self . migration_dependencies : plan = dependency . split ( '.' ) plan = tuple ( [ plan [ - 2 ] , plan [ - 1 ] ] ) if plan not in applied_migrations : unapplied_dependencies . append ( plan ) if unapplied_dependencies : try : plan = executor . migration_plan ( unapplied_dependencies ) executor . migrate ( unapplied_dependencies , plan = plan , state = pre_migrate_state . clone ( ) ) migration_graph_in_place = True except NodeNotFoundError as ex : for dep in unapplied_dependencies : if not recorder . migration_qs . filter ( app = dep [ 0 ] , name__icontains = dep [ 1 ] ) . exists ( ) : raise ex if not migration_graph_in_place : migration_graph_in_place = ( recorder . migration_qs . filter ( app = self . node . app_name ) . order_by ( '-pk' ) . first ( ) in self . migration_dependencies ) return migration_graph_in_place
Migrates the django migration graph until dependencies are applied
Migrates the django migration graph until dependencies are applied
"""Migrates the django migration graph until dependencies are applied""" # Get the database we're operating from # Work out which apps have migrations and which do not
self