Skip to content

Commit

Permalink
move createcachetable to post migrate signal (#9944)
Browse files Browse the repository at this point in the history
Use management command in post-migrate signal to create cache table instead of in Raw SQL in migrations
Co-authored-by: John Tordoff <>
  • Loading branch information
Johnetordoff authored and cslzchen committed Sep 1, 2022
1 parent 6ed443d commit 61068e0
Show file tree
Hide file tree
Showing 3 changed files with 12 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'
)
12 changes: 0 additions & 12 deletions osf/migrations/0156_create_cache_table.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
from django.conf import settings


class Migration(migrations.Migration):
dependencies = [
('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: 7 additions & 0 deletions 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 @@ -119,3 +121,8 @@ 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(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
call_command('createcachetable', tablename=settings.CACHES[settings.STORAGE_USAGE_CACHE_NAME]['LOCATION'])

0 comments on commit 61068e0

Please sign in to comment.