🔧 updated migrations scripts to support mysql

This commit is contained in:
Abdullah Adeel 2022-01-21 15:19:19 +05:00
parent 5563073bf3
commit b1e86eec17

View File

@ -25,6 +25,7 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name):
# greater than the maximum value.
max_id = site_model.objects.order_by('-id').first().id
with connection.cursor() as cursor:
{% if cookiecutter.database_engine == 'postgresql' -%}
cursor.execute("SELECT last_value from django_site_id_seq")
(current_id,) = cursor.fetchone()
if current_id <= max_id:
@ -32,6 +33,15 @@ def _update_or_create_site_with_sequence(site_model, connection, domain, name):
"alter sequence django_site_id_seq restart with %s",
[max_id + 1],
)
{% elif cookiecutter.database_engine == 'mysql' -%}
cursor.execute("SELECT MAX(id) FROM django_site")
(current_id,) = cursor.fetchone()
if current_id <= max_id:
cursor.execute(
"ALTER TABLE django_site AUTO_INCREMENT=%s",
[max_id + 1],
)
{% endif -%}
def update_site_forward(apps, schema_editor):