Skip to content

Instantly share code, notes, and snippets.

@karthikbgl
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karthikbgl/00398caef06797d5c205 to your computer and use it in GitHub Desktop.
Save karthikbgl/00398caef06797d5c205 to your computer and use it in GitHub Desktop.
Editing south migrations to run custom sql
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import DataMigration
from django.db import models
class Migration(DataMigration):
def forwards(self, orm):
db.start_transaction()
db.execute("""
UPDATE table_name
SET myfield = ('x' || lpad(browser_id,16,'0'))::bit(64)::bigint #converts hex to bigint in sql
WHERE myfield IS NOT NULL;
""")
db.commit_transaction()
db.start_transaction()
db.execute("ALTER TABLE table_name DROP COLUMN old_field")
db.commit_transaction()
def backwards(self, orm):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment