old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.15 on 2018-11-12 17:18
  from __future__ import unicode_literals
  
  from django.db import migrations, connection
  
  
  def reverse_func(state, schema):
      with connection.cursor() as cursor:
          cursor.execute(
              """
              UPDATE osf_pagecounter
              SET (action, guid_id, file_id, version) = ('download', NULL, NULL, NULL);
              """
          )
  
  def separate_pagecounter_id(state, schema):
      """
      Splits the data in pagecounter _id field of form action:guid_id:file_id:version into
      four new columns: action(char), guid(fk), file(fk), version(int)
      """
      with connection.cursor() as cursor:
          cursor.execute(
              """
              UPDATE osf_pagecounter PC
              SET (action, guid_id, file_id, version) = (split_part(PC._id, ':', 1), G.id, F.id, NULLIF(split_part(PC._id, ':', 4), '')::int)
              FROM osf_guid G, osf_basefilenode F
              WHERE PC._id LIKE '%' || G._id || '%'
              AND PC._id LIKE '%' || F._id || '%';
              """
          )
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('osf', '0144_pagecounter_index'),
      ]
  
      operations = [
          migrations.RunPython(
              separate_pagecounter_id, reverse_func
          ),
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.15 on 2018-11-12 17:18
  from __future__ import unicode_literals
  from django.db import migrations
  
  
  reverse_func = [
      """
      UPDATE osf_pagecounter
      SET (action, guid_id, file_id, version) = ('download', NULL, NULL, NULL);
      """
  ]
  
  # Splits the data in pagecounter _id field of form action:guid_id:file_id:version into
  # four new columns: action(char), guid(fk), file(fk), version(int)
  separate_pagecounter_id = [
      """
      UPDATE osf_pagecounter PC
      SET (action, guid_id, file_id, version) = (split_part(PC._id, ':', 1), G.id, F.id, NULLIF(split_part(PC._id, ':', 4), '')::int)
      FROM osf_guid G, osf_basefilenode F
      WHERE PC._id LIKE '%' || G._id || '%'
      AND PC._id LIKE '%' || F._id || '%';
      """
  ]
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('osf', '0144_pagecounter_index'),
      ]
  
      operations = [
          migrations.RunSQL(
              separate_pagecounter_id, reverse_func
          ),
      ]
  
subject: Call RunSQL instead of RunPython in pagecounter data migration.