コード例 #1
0
    def check_migrations(self):
        try:
            migration_plan = septentrion.build_migration_plan(
                **septentrion_settings(connection)
            )
        except migrations.DBException as e:
            self.stdout.write(self.style.NOTICE("\n{}\n".format(e)))
            return

        if not septentrion.is_schema_initialized(
            **septentrion_settings(connection)
        ):
            self.stdout.write(self.style.NOTICE("\nSchema not inited.\n"))
            return

        has_migrations = migration_plan is not None and any(
            [
                any([not applied
                     for mig, applied, path, is_manual
                     in plan['plan']])
                for plan in migration_plan
            ]
        )
        if has_migrations:
            self.stdout.write(self.style.NOTICE(
                "\nYou have unapplied migrations; your app may not work "
                "properly until they are applied."
            ))
            self.stdout.write(self.style.NOTICE(
                "Run 'python manage.py migrate' to apply them.\n"
            ))
コード例 #2
0
def test_migrate_command_with_django_table(django_db_setup_no_init, settings):
    """
    This test simulate the case when a project
    was created to be used with django migrations table
    Either because it didn't use septentrion-based django-north,
    or a pre septentrion-base django-north version.
    """
    connection = connections['no_init']

    # We begin with an empty database
    assert migrations.get_current_version(connection) is None

    # We simulate the setup of the database in the past,
    # with a django_migrations table.
    updated_settings = septentrion_settings(connection)
    updated_settings.update({
        "target_version": "1.0",
        "table": "django_migrations",
    })
    septentrion.migrate(**updated_settings)

    # DB is initialized, this doesn't return None
    assert migrations.get_current_version(connections['no_init']) is not None

    # and migrate to newer version
    call_command('migrate', '--database', 'no_init')

    # check if max applied version is target version
    assert settings.NORTH_TARGET_VERSION != "1.0"
    assert (migrations.get_applied_versions(
        connections['no_init'])[-1] == settings.NORTH_TARGET_VERSION)
コード例 #3
0
    def handle(self, *args, **options):
        if getattr(settings, 'NORTH_MANAGE_DB', False) is not True:
            logger.info('showmigrations command disabled')
            return

        connection = connections[options['database']]

        septentrion.show_migrations(**septentrion_settings(connection),)
コード例 #4
0
ファイル: migrate.py プロジェクト: peopledoc/django-north
    def handle(self, *args, **options):
        if getattr(settings, 'NORTH_MANAGE_DB', False) is not True:
            logger.info('migrate command disabled')
            return

        self.verbosity = options.get('verbosity')

        connection = connections[options['database']]
        septentrion.migrate(**septentrion_settings(connection))
コード例 #5
0
    def emit_post_migrate(verbosity, interactive, database, current_version):
        # custom: do what was done on post_migrate
        # clear contenttype cache
        ContentType.objects.clear_cache()

        # reload fixtures
        connection = connections[database]
        septentrion.load_fixtures(
            current_version,
            **septentrion_settings(connection),
        )
コード例 #6
0
def get_applied_versions(connection):
    """
    Return the list of applied versions.
    Reuse django migration table.
    """
    recorder = MigrationRecorder(connection)

    applied_versions = list(recorder.migration_qs.filter(
        app__in=septentrion.get_known_versions(
            MIGRATIONS_ROOT=settings.NORTH_MIGRATIONS_ROOT,
            **septentrion_settings(connection)
        )
    ).values_list(
        'app', flat=True).order_by('app').distinct())

    # sort versions
    applied_versions.sort(key=StrictVersion)
    return applied_versions
コード例 #7
0
def test_septentrion_settings(db):
    settings = commands.septentrion_settings(connection)

    minimal_keys = {
        "migrations_root",
        "target_version",
        "table",
        "name_column",
        "version_column",
        "applied_at_column",
        "create_table",
    }
    assert minimal_keys <= set(settings)
    assert settings["migrations_root"].endswith("tests/north_project/sql")
    assert settings["target_version"] == "1.3"
    assert settings["table"] == 'django_migrations'
    assert settings["name_column"] == 'name'
    assert settings["version_column"] == 'app'
    assert settings["applied_at_column"] == 'applied'
    assert settings["create_table"] is False