Skip to content
Permalink
Browse files
AIRAVATA-3583 Add index on file_path column
  • Loading branch information
machristie committed Feb 25, 2022
1 parent 2cc61db commit 45aec2e23cf7b0c8e1b1b3b2c3ab7994c818beca
Showing 4 changed files with 51 additions and 5 deletions.
@@ -0,0 +1,48 @@
# Generated by Django 2.2.17 on 2022-02-25 15:10

from django.db import connections, migrations


def create_user_files_index(apps, schema_editor):
# Create an index on file_path column
# Note: on MySQL/MariaDB, create the index on the first 255 characters of file_path
if connections.databases[schema_editor.connection.alias]['ENGINE'] == 'django.db.backends.mysql':
in_atomic_block = schema_editor.connection.in_atomic_block
schema_editor.connection.in_atomic_block = False
try:
schema_editor.execute('''
create index index_airavata_django_portal_sdk_userfiles_file_path on airavata_django_portal_sdk_userfiles (file_path(255));
''')
finally:
schema_editor.connection.in_atomic_block = in_atomic_block
else:
schema_editor.execute('''
create index index_airavata_django_portal_sdk_userfiles_file_path on airavata_django_portal_sdk_userfiles (file_path);
''')


def drop_user_files_index(apps, schema_editor):
if connections.databases[schema_editor.connection.alias]['ENGINE'] == 'django.db.backends.mysql':
in_atomic_block = schema_editor.connection.in_atomic_block
schema_editor.connection.in_atomic_block = False
try:
schema_editor.execute('''
drop index index_airavata_django_portal_sdk_userfiles_file_path on airavata_django_portal_sdk_userfiles;
''')
finally:
schema_editor.connection.in_atomic_block = in_atomic_block
else:
schema_editor.execute('''
drop index index_airavata_django_portal_sdk_userfiles_file_path on airavata_django_portal_sdk_userfiles;
''')


class Migration(migrations.Migration):

dependencies = [
('airavata_django_portal_sdk', '0002_userfiles_file_resource_id'),
]

operations = [
migrations.RunPython(create_user_files_index, drop_user_files_index)
]
@@ -13,8 +13,6 @@ class UserFiles(models.Model):

class Meta:
indexes = [
# FIXME: ideally we would include file_path in the index to make
# lookups faster, but Django/MariaDB don't support key length on a
# TEXT column which is required to create an index
# See also migration #0003 which adds an index on file_path
models.Index(fields=['username'], name='userfiles_username_idx')
]
@@ -2,7 +2,7 @@ airavata-python-sdk==1.0.1
bcrypt==3.1.7
cffi==1.14.1
cryptography==3.0
Django==2.2.17
Django==3.2.12
djangorestframework==3.10.3
google-api-python-client==1.12.8
grpcio-tools==1.34.1
@@ -10,7 +10,7 @@ def read(fname):

setup(
name="airavata-django-portal-sdk",
version="1.3.0",
version="1.3.1",
url="https://github.com/apache/airavata-django-portal-sdk",
author="Apache Software Foundation",
author_email="dev@airavata.apache.org",

0 comments on commit 45aec2e

Please sign in to comment.