def _check_character_set(self):
        errors = []

        conn = None
        for _alias, check_conn in mysql_connections():
            if (hasattr(check_conn, "mysql_version")
                    and connection_is_mariadb(check_conn)
                    and check_conn.mysql_version >= (10, 0, 1)):
                conn = check_conn
                break

        if conn is not None:
            with conn.cursor() as cursor:
                cursor.execute("SELECT @@character_set_client")
                charset = cursor.fetchone()[0]

            if charset not in ("utf8", "utf8mb4"):
                errors.append(
                    checks.Error(
                        "The MySQL charset must be 'utf8' or 'utf8mb4' to "
                        "use DynamicField",
                        hint="You are currently connecting with the '{}' "
                        "character set. Add "
                        "'OPTIONS': {{'charset': 'utf8mb4'}}, to your "
                        "DATABASES setting to fix this".format(charset),
                        obj=self,
                        id="django_mysql.E014",
                    ))

        return errors
Example #2
0
    def _check_mysql_version(self):
        errors = []
        any_conn_works = False
        conns = list(mysql_connections())
        for alias, conn in conns:
            if ((hasattr(conn, 'mysql_version') and conn.mysql_version >=
                 (5, 7)) or
                (connection_is_mariadb(conn)
                 and hasattr(conn, 'mysql_version') and conn.mysql_version >=
                 (10, 2, 7))):
                any_conn_works = True

        if conns and self.null:
            errors.append(
                checks.Error(
                    'You should not use nullable JSONFields if you have MySQL connections.',
                    obj=self,
                    id='jsonfallback.E001',
                ), )

        if conns and not any_conn_works:
            errors.append(
                checks.Error(
                    'MySQL 5.7+ is required to use JSONField',
                    hint='At least one of your DB connections should be to '
                    'MySQL 5.7+ or MariaDB 10.2.7+',
                    obj=self,
                    id='django_mysql.E016',
                ), )
        return errors
Example #3
0
def check_mysql_version():
    """
    Return True if the mysql version exists and it is mayor to 5.7.
    """
    valid_version = False
    connections = list(mysql_connections())

    if connections:
        for alias, conn in connections:  # pylint: disable=unused-variable
            if hasattr(conn, "mysql_version") and conn.mysql_version >= (5, 7):
                valid_version = True

    return valid_version
Example #4
0
    def _check_mariadb_version(self) -> list[checks.CheckMessage]:
        errors = []

        any_conn_works = any((conn.vendor == "mysql" and conn.mysql_is_mariadb)
                             for _alias, conn in mysql_connections())

        if not any_conn_works:
            errors.append(
                checks.Error(
                    "MariaDB is required to use DynamicField",
                    hint=
                    "At least one of your DB connections should be MariaDB.",
                    obj=self,
                    id="django_mysql.E013",
                ))
        return errors
    def _check_mariadb_version(self):
        errors = []

        any_conn_works = any(
            (hasattr(conn, "mysql_version") and connection_is_mariadb(conn)
             and conn.mysql_version >= (10, 0, 1))
            for _alias, conn in mysql_connections())

        if not any_conn_works:
            errors.append(
                checks.Error(
                    "MariaDB 10.0.1+ is required to use DynamicField",
                    hint="At least one of your DB connections should be to "
                    "MariaDB 10.0.1+",
                    obj=self,
                    id="django_mysql.E013",
                ))
        return errors
Example #6
0
    def _check_mysql_version(self):
        errors = []

        any_conn_works = any(
            (hasattr(conn, "mysql_version") and not connection_is_mariadb(conn)
             and conn.mysql_version >= (5, 7))
            for _alias, conn in mysql_connections())

        if not any_conn_works:
            errors.append(
                checks.Error(
                    "MySQL 5.7+ is required to use JSONField",
                    hint="At least one of your DB connections should be to "
                    "MySQL 5.7+",
                    obj=self,
                    id="django_mysql.E016",
                ))
        return errors
Example #7
0
    def _check_mariadb_version(self):
        errors = []

        any_conn_works = False
        for alias, conn in mysql_connections():
            if (hasattr(conn, 'mysql_version') and connection_is_mariadb(conn)
                    and conn.mysql_version >= (10, 0, 1)):
                any_conn_works = True

        if not any_conn_works:
            errors.append(
                checks.Error(
                    'MariaDB 10.0.1+ is required to use DynamicField',
                    hint='At least one of your DB connections should be to '
                    'MariaDB 10.0.1+',
                    obj=self,
                    id='django_mysql.E013'))
        return errors
Example #8
0
    def _check_mysql_version(self):
        errors = []

        any_conn_works = False
        for _alias, conn in mysql_connections():
            if (hasattr(conn, "mysql_version") and connection_is_mariadb(conn)
                    and conn.mysql_version >= (10, 2, 7)):
                any_conn_works = True

        if not any_conn_works:
            errors.append(
                checks.Error(
                    "MariaDB 10.2.7+ is required to use JSONField",
                    hint="At least one of your DB connections should be to "
                    "MariaDB 10.2.7+. For MySQL 5.7+, install django-mysql "
                    "from pip.",
                    obj=self,
                    id="django_mysql.E016",
                ))
        return errors
Example #9
0
    def _check_mysql_version(self):
        errors = []

        any_conn_works = False
        for alias, conn in mysql_connections():
            if (hasattr(conn, 'mysql_version')
                    and not connection_is_mariadb(conn)
                    and conn.mysql_version >= (5, 7)):
                any_conn_works = True

        if not any_conn_works:
            errors.append(
                checks.Error(
                    'MySQL 5.7+ is required to use JSONField',
                    hint='At least one of your DB connections should be to '
                    'MySQL 5.7+',
                    obj=self,
                    id='django_mysql.E016',
                ), )
        return errors
Example #10
0
def check_mysqlversion(apps, schema_editor):
    errors = []
    any_conn_works = False
    conns = list(mysql_connections())
    found = 'Unknown version'
    for alias, conn in conns:
        if connection_is_mariadb(conn) and hasattr(conn, 'mysql_version'):
            if conn.mysql_version >= (10, 2, 7):
                any_conn_works = True
            else:
                found = 'MariaDB ' + '.'.join(
                    str(v) for v in conn.mysql_version)
        elif hasattr(conn, 'mysql_version'):
            if conn.mysql_version >= (5, 7):
                any_conn_works = True
            else:
                found = 'MySQL ' + '.'.join(str(v) for v in conn.mysql_version)

    if conns and not any_conn_works:
        raise ImproperlyConfigured(
            'As of pretix 2.2, you need MySQL 5.7+ or MariaDB 10.2.7+ to run pretix. However, we detected a '
            'database connection to {}'.format(found))
    return errors
def check_mysqlversion(apps, schema_editor):
    errors = []
    any_conn_works = False
    conns = list(mysql_connections())
    found = 'Unknown version'
    for alias, conn in conns:
        if connection_is_mariadb(conn) and hasattr(conn, 'mysql_version'):
            if conn.mysql_version >= (10, 2, 7):
                any_conn_works = True
            else:
                found = 'MariaDB ' + '.'.join(str(v) for v in conn.mysql_version)
        elif hasattr(conn, 'mysql_version'):
            if conn.mysql_version >= (5, 7):
                any_conn_works = True
            else:
                found = 'MySQL ' + '.'.join(str(v) for v in conn.mysql_version)

    if conns and not any_conn_works:
        raise ImproperlyConfigured(
            'As of pretix 2.2, you need MySQL 5.7+ or MariaDB 10.2.7+ to run pretix. However, we detected a '
            'database connection to {}'.format(found)
        )
    return errors