Last active
August 29, 2015 14:06
-
-
Save karthikbgl/00398caef06797d5c205 to your computer and use it in GitHub Desktop.
Editing south migrations to run custom sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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