Skip to content

Commit

Permalink
Removed MariaDB/MySQL Support (fossasia#49)
Browse files Browse the repository at this point in the history
cleanup: remove remaining mysql code, patch up dependencies, fix typos (fossasia#53)

Co-authored-by: Martin Bähr <[email protected]>
  • Loading branch information
Shivangi-ch and Martin Bähr committed May 21, 2024
1 parent b5d7f18 commit c67e595
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 92 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM python:3.8-bookworm
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
default-libmysqlclient-dev \
gettext \
git \
libffi-dev \
Expand Down Expand Up @@ -48,7 +47,6 @@ RUN pip3 install -U \
pip3 install \
-r requirements.txt \
-r requirements/memcached.txt \
-r requirements/mysql.txt \
gunicorn django-extensions ipython && \
rm -rf ~/.cache/pip

Expand Down
11 changes: 2 additions & 9 deletions doc/admin/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,23 @@ Database settings
Example::

[database]
backend=mysql
backend=postgresql
name=pretix
user=pretix
password=abcd
host=localhost
port=3306

``backend``
One of ``mysql``, ``sqlite3``, ``oracle`` and ``postgresql``.
One of ``sqlite3``, ``oracle`` and ``postgresql``.
Default: ``sqlite3``.

If you use MySQL, be sure to create your database using
``CREATE DATABASE <dbname> CHARACTER SET utf8;``. Otherwise, Unicode
support will not properly work.

``name``
The database's name. Default: ``db.sqlite3``.

``user``, ``password``, ``host``, ``port``
Connection details for the database connection. Empty by default.

``galera``
Indicates if the database backend is a MySQL/MariaDB Galera cluster and
turns on some optimizations/special case handlers. Default: ``False``

.. _`config-replica`:

Expand Down
29 changes: 1 addition & 28 deletions src/pretix/base/migrations/0102_auto_20181017_0024.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.core.exceptions import ImproperlyConfigured
from django.db import migrations, models
from django_mysql.checks import mysql_connections
from django_mysql.utils import connection_is_mariadb


def set_attendee_name_parts(apps, schema_editor):
Expand All @@ -24,39 +22,14 @@ def set_attendee_name_parts(apps, schema_editor):
ia.save(update_fields=['name_parts'])


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


class Migration(migrations.Migration):
dependencies = [
('pretixbase', '0101_auto_20181025_2255'),
]

operations = [
migrations.RunPython(
check_mysqlversion, migrations.RunPython.noop
migrations.RunPython.noop
),
migrations.RenameField(
model_name='cartposition',
Expand Down
21 changes: 1 addition & 20 deletions src/pretix/helpers/templatetags/jsonfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
from django.db import NotSupportedError
from django.db.models import Expression, JSONField

def mysql_compile_json_path(key_transforms):
path = ['$']
for key_transform in key_transforms:
try:
num = int(key_transform)
path.append('[{}]'.format(num))
except ValueError: # non-integer
path.append('.')
path.append(key_transform)
return ''.join(path)

def postgres_compile_json_path(key_transforms):
return "{" + ','.join(key_transforms) + "}"

Expand All @@ -41,17 +30,9 @@ def as_sql(self, compiler, connection, function=None, template=None, arg_joiner=
params.append(json_path)
template = '{} #> %s'.format(arg_sql)
return template, params
elif '.mysql' in connection.settings_dict['ENGINE']:
params = []
arg_sql, arg_params = compiler.compile(self.source_expression)
params.extend(arg_params)
json_path = mysql_compile_json_path(self.path)
params.append(json_path)
template = 'JSON_EXTRACT({}, %s)'.format(arg_sql)
return template, params
else:
raise NotSupportedError(
'Functions on JSONFields are only supported on PostgreSQL and MySQL at the moment.'
'Functions on JSONFields are only supported on PostgreSQL.'
)

def copy(self):
Expand Down
25 changes: 7 additions & 18 deletions src/pretix/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from urllib.parse import urlparse
from .settings_helpers import build_db_tls_config, build_redis_tls_config
import django.conf.locale
from django.core.exceptions import ImproperlyConfigured
from django.utils.crypto import get_random_string
from kombu import Queue
from pkg_resources import iter_entry_points
Expand Down Expand Up @@ -71,17 +72,11 @@
db_backend = config.get('database', 'backend', fallback='sqlite3')
if db_backend == 'postgresql_psycopg2':
db_backend = 'postgresql'
DATABASE_IS_GALERA = config.getboolean('database', 'galera', fallback=False)
if DATABASE_IS_GALERA and 'mysql' in db_backend:
db_options = {
'init_command': 'SET SESSION wsrep_sync_wait = 1;'
}
else:
db_options = {}
if db_backend == 'mysql':
raise ImproperlyConfigured("MySQL/MariaDB is not supported")

if 'mysql' in db_backend:
db_options['charset'] = 'utf8mb4'
JSON_FIELD_AVAILABLE = db_backend in ('mysql', 'postgresql')
JSON_FIELD_AVAILABLE = db_backend == 'postgresql'
db_options = {}

db_tls_config = build_db_tls_config(config, db_backend)
if (db_tls_config is not None):
Expand All @@ -98,10 +93,7 @@
'PORT': config.get('database', 'port', fallback=''),
'CONN_MAX_AGE': 0 if db_backend == 'sqlite3' else 120,
'OPTIONS': db_options,
'TEST': {
'CHARSET': 'utf8mb4',
'COLLATION': 'utf8mb4_unicode_ci',
} if 'mysql' in db_backend else {}
'TEST': {}
}
}
DATABASE_REPLICA = 'default'
Expand All @@ -116,10 +108,7 @@
'PORT': config.get('replica', 'port', fallback=DATABASES['default']['PORT']),
'CONN_MAX_AGE': 0 if db_backend == 'sqlite3' else 120,
'OPTIONS': db_options,
'TEST': {
'CHARSET': 'utf8mb4',
'COLLATION': 'utf8mb4_unicode_ci',
} if 'mysql' in db_backend else {}
'TEST': {}
}
DATABASE_ROUTERS = ['pretix.helpers.database.ReplicaRouter']

Expand Down
2 changes: 0 additions & 2 deletions src/requirements/mysql.txt

This file was deleted.

4 changes: 2 additions & 2 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def run(self):
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Framework :: Django :: 3.0'
'Framework :: Django :: 3.2'
],

keywords='tickets web shop ecommerce',
Expand All @@ -125,6 +125,7 @@ def run(self):
'django-hierarkey==1.0.*,>=1.0.4',
'django-filter==2.4.*',
'django-scopes==1.2.*',
'django-localflavor==3.0.*',
'reportlab>=3.5.65',
'Pillow==8.*',
'PyPDF2==1.26.*',
Expand Down Expand Up @@ -203,7 +204,6 @@ def run(self):
'freezegun',
],
'memcached': ['pylibmc'],
'mysql': ['mysqlclient'],
},

packages=find_packages(exclude=['tests', 'tests.*']),
Expand Down
5 changes: 1 addition & 4 deletions src/tests/api/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
format='json'
)
assert resp.status_code == 400
assert resp.content.decode() in [
'{"addons":["The minimum count needs to be equal to or greater than zero."]}',
'{"addons":[{"min_count":["Ensure this value is greater than or equal to 0."]}]}', # mysql
]
assert resp.content.decode() == '{"addons":["The minimum count needs to be equal to or greater than zero."]}'
with scopes_disabled():
assert 2 == Item.objects.all().count()

Expand Down
7 changes: 0 additions & 7 deletions src/tests/travis_mysql.cfg

This file was deleted.

0 comments on commit c67e595

Please sign in to comment.