Skip to content

Commit

Permalink
move createcachetable to post migrate signal and remove dependent mig…
Browse files Browse the repository at this point in the history
…rations
  • Loading branch information
John Tordoff committed Jun 27, 2022
1 parent 1422ded commit 04fd68f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
6 changes: 5 additions & 1 deletion osf/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.apps import AppConfig as BaseAppConfig
from django.db.models.signals import post_migrate
from osf.migrations import update_permission_groups
from osf.migrations import update_permission_groups, create_cache_table


class AppConfig(BaseAppConfig):
Expand All @@ -16,3 +16,7 @@ def ready(self):
update_permission_groups,
dispatch_uid='osf.apps.update_permissions_groups'
)
post_migrate.connect(
create_cache_table,
dispatch_uid='osf.apps.create_cache_table'
)
11 changes: 0 additions & 11 deletions osf/migrations/0156_create_cache_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,4 @@ class Migration(migrations.Migration):
('osf', '0155_merge_20190115_1437'),
]
operations = [
migrations.RunSQL([
"""
CREATE TABLE "{}" (
"cache_key" varchar(255) NOT NULL PRIMARY KEY,
"value" text NOT NULL,
"expires" timestamp with time zone NOT NULL
);
""".format(settings.CACHES[settings.STORAGE_USAGE_CACHE_NAME]['LOCATION'])
], [
"""DROP TABLE "{}"; """.format(settings.CACHES[settings.STORAGE_USAGE_CACHE_NAME]['LOCATION'])
])
]
7 changes: 6 additions & 1 deletion osf/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import logging
from django.db.utils import ProgrammingError
from django.core.management import call_command
from api.base import settings

logger = logging.getLogger(__file__)

Expand Down Expand Up @@ -52,7 +54,6 @@ def get_admin_write_permissions():
'delete_preprintprovider',
'change_subject',
'change_maintenancestate',
'change_registrationschema',
'delete_maintenancestate',
'change_scheduledbanner',
'delete_scheduledbanner',
Expand Down Expand Up @@ -119,3 +120,7 @@ def update_permission_groups(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
update_admin_permissions(verbosity)
update_provider_auth_groups(verbosity)


def create_cache_table(*args, **kwargs):
call_command('createcachetable', tablename=settings.CACHES[settings.STORAGE_USAGE_CACHE_NAME]['LOCATION'])

0 comments on commit 04fd68f

Please sign in to comment.