mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Remove MariaDB support (#3381)
This commit is contained in:
@@ -24,7 +24,7 @@ Django, for theoretically very valid reasons, creates migrations for *every sing
|
||||
we change on a model. Even the `help_text`! This makes sense, as we don't know if any
|
||||
database backend unknown to us might actually use this information for its database schema.
|
||||
|
||||
However, pretix only supports PostgreSQL, MySQL, MariaDB and SQLite and we can be pretty
|
||||
However, pretix only supports PostgreSQL and SQLite and we can be pretty
|
||||
certain that some changes to models will never require a change to the database. In this case,
|
||||
not creating a migration for certain changes will save us some performance while applying them
|
||||
*and* allow for a cleaner git history. Win-win!
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.db import migrations, models
|
||||
from django_mysql.checks import mysql_connections
|
||||
|
||||
|
||||
def set_attendee_name_parts(apps, schema_editor):
|
||||
@@ -24,40 +23,12 @@ 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 hasattr(conn, 'mysql_is_mariadb') and conn.mysql_is_mariadb 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.RenameField(
|
||||
model_name='cartposition',
|
||||
old_name='attendee_name',
|
||||
|
||||
@@ -50,6 +50,6 @@ class Migration(migrations.Migration):
|
||||
],
|
||||
options={
|
||||
'unique_together': {('event', 'secret')},
|
||||
} if 'mysql' not in settings.DATABASES['default']['ENGINE'] else {}
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
@@ -3116,11 +3116,7 @@ class BlockedTicketSecret(models.Model):
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
if 'mysql' not in settings.DATABASES['default']['ENGINE']:
|
||||
# MySQL does not support indexes on TextField(). Django knows this and just ignores db_index, but it will
|
||||
# not silently ignore the UNIQUE index, causing this table to fail. I'm so glad we're deprecating MySQL
|
||||
# in a few months, so we'll just live without an unique index until then.
|
||||
unique_together = (('event', 'secret'),)
|
||||
unique_together = (('event', 'secret'),)
|
||||
|
||||
|
||||
@receiver(post_delete, sender=CachedTicket)
|
||||
|
||||
@@ -423,17 +423,6 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if "mysql" in settings.DATABASES.default.ENGINE and not request.organizer %}
|
||||
<div class="alert alert-warning">
|
||||
{% blocktrans trimmed %}
|
||||
You are using MySQL or MariaDB as your database backend for pretix.
|
||||
Starting in pretix 5.0, these will no longer be supported and you will need to migrate to PostgreSQL.
|
||||
Please see the pretix administrator documentation for a migration guide, and the pretix 4.16
|
||||
release notes for more information.
|
||||
{% endblocktrans %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if debug_warning %}
|
||||
<div class="alert alert-danger">
|
||||
{% trans "pretix is running in debug mode. For security reasons, please never run debug mode on a production instance." %}
|
||||
|
||||
@@ -93,7 +93,7 @@ class OrderSearch(PaginationMixin, ListView):
|
||||
|
||||
if self.filter_form.use_query_hack():
|
||||
"""
|
||||
We need to work around a bug in PostgreSQL's (and likely MySQL's) query plan optimizer here.
|
||||
We need to work around a bug in PostgreSQL's query plan optimizer here.
|
||||
The database lacks statistical data to predict how common our search filter is and therefore
|
||||
assumes that it is cheaper to first ORDER *all* orders in the system (since we got an index on
|
||||
datetime), then filter out with a full scan until OFFSET/LIMIT condition is fulfilled. If we
|
||||
@@ -167,7 +167,7 @@ class PaymentSearch(PaginationMixin, ListView):
|
||||
|
||||
if self.filter_form.cleaned_data.get('query'):
|
||||
"""
|
||||
We need to work around a bug in PostgreSQL's (and likely MySQL's) query plan optimizer here.
|
||||
We need to work around a bug in PostgreSQL's query plan optimizer here.
|
||||
The database lacks statistical data to predict how common our search filter is and therefore
|
||||
assumes that it is cheaper to first ORDER *all* orders in the system (since we got an index on
|
||||
datetime), then filter out with a full scan until OFFSET/LIMIT condition is fulfilled. If we
|
||||
|
||||
@@ -29,7 +29,7 @@ def postgres_compile_json_path(key_transforms):
|
||||
return "{" + ','.join(key_transforms) + "}"
|
||||
|
||||
|
||||
def mysql_compile_json_path(key_transforms):
|
||||
def sqlite_compile_json_path(key_transforms):
|
||||
path = ['$']
|
||||
for key_transform in key_transforms:
|
||||
try:
|
||||
@@ -41,9 +41,6 @@ def mysql_compile_json_path(key_transforms):
|
||||
return ''.join(path)
|
||||
|
||||
|
||||
sqlite_compile_json_path = mysql_compile_json_path
|
||||
|
||||
|
||||
class JSONExtract(Expression):
|
||||
def __init__(self, expression, *path, output_field=JSONField(), **extra):
|
||||
super().__init__(output_field=output_field)
|
||||
@@ -66,14 +63,6 @@ class JSONExtract(Expression):
|
||||
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
|
||||
elif '.sqlite' in connection.settings_dict['ENGINE']:
|
||||
params = []
|
||||
arg_sql, arg_params = compiler.compile(self.source_expression)
|
||||
@@ -84,7 +73,7 @@ class JSONExtract(Expression):
|
||||
return template, params
|
||||
else:
|
||||
raise NotSupportedError(
|
||||
'Functions on JSONFields are only supported on SQLite, PostgreSQL, and MySQL at the moment.'
|
||||
'Functions on JSONFields are only supported on SQLite and PostgreSQL at the moment.'
|
||||
)
|
||||
|
||||
def copy(self):
|
||||
|
||||
@@ -110,16 +110,11 @@ PRETIX_AUTH_BACKENDS = config.get('pretix', 'auth_backends', fallback='pretix.ba
|
||||
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 = {}
|
||||
elif 'mysql' in db_backend:
|
||||
print("pretix does no longer support running on MySQL/MariaDB")
|
||||
sys.exit(1)
|
||||
|
||||
if 'mysql' in db_backend:
|
||||
db_options['charset'] = 'utf8mb4'
|
||||
db_options = {}
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
@@ -132,10 +127,7 @@ DATABASES = {
|
||||
'CONN_MAX_AGE': 0 if db_backend == 'sqlite3' else 120,
|
||||
'CONN_HEALTH_CHECKS': db_backend != 'sqlite3', # Will only be used from Django 4.1 onwards
|
||||
'OPTIONS': db_options,
|
||||
'TEST': {
|
||||
'CHARSET': 'utf8mb4',
|
||||
'COLLATION': 'utf8mb4_unicode_ci',
|
||||
} if 'mysql' in db_backend else {}
|
||||
'TEST': {}
|
||||
}
|
||||
}
|
||||
DATABASE_REPLICA = 'default'
|
||||
@@ -150,10 +142,7 @@ if config.has_section('replica'):
|
||||
'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']
|
||||
|
||||
|
||||
@@ -835,7 +835,7 @@ def test_item_create_with_addon(token_client, organizer, event, item, category,
|
||||
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
|
||||
'{"addons":[{"min_count":["Ensure this value is greater than or equal to 0."]}]}',
|
||||
]
|
||||
with scopes_disabled():
|
||||
assert 2 == Item.objects.all().count()
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
[database]
|
||||
backend=mysql
|
||||
name=pretix
|
||||
user=root
|
||||
password=
|
||||
host=127.0.0.1
|
||||
port=3306
|
||||
Reference in New Issue
Block a user