Skip to content

Commit

Permalink
Merge branch 'feature/django_upgrade' of https://github.com/CenterFor…
Browse files Browse the repository at this point in the history
…OpenScience/osf.io into signals-citation-styles

* 'feature/django_upgrade' of https://github.com/CenterForOpenScience/osf.io:
  move createcachetable to post migrate signal (CenterForOpenScience#9944)

# Conflicts:
#	osf/apps.py
#	osf/migrations/__init__.py
  • Loading branch information
John Tordoff committed Jun 27, 2022
2 parents 02cb8f2 + 222ce09 commit 04c45ae
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, update_citation_styles
from osf.migrations import update_permission_groups, create_cache_table, update_citation_styles


class AppConfig(BaseAppConfig):
Expand All @@ -20,3 +20,7 @@ def ready(self):
update_citation_styles,
dispatch_uid='osf.apps.update_citation_styles'
)
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
Expand Up @@ -9,6 +9,8 @@
import logging
from django.apps import apps
from django.db.utils import ProgrammingError
from django.core.management import call_command
from api.base import settings

logger = logging.getLogger(__file__)
from django.db import transaction
Expand Down Expand Up @@ -235,3 +237,8 @@ def update_citation_styles(sender, verbosity=0, **kwargs):
if getattr(sender, 'label', None) == 'osf':
if 'pytest' not in sys.modules:
ensure_citation_styles()


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 04c45ae

Please sign in to comment.