Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AIRAVATA-3583 Add index on file_path column
- Loading branch information
1 parent
2cc61db
commit 45aec2e
Showing
4 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
airavata_django_portal_sdk/migrations/0003_auto_20220225_1510.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters