Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit dfbf037

Browse files
committed
Update descriptions & description digest with SQL
So that last_updated isn't changed
1 parent b456a8e commit dfbf037

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

editorsnotes/main/migrations/0127_add_description_digest.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
from south.db import db
44
from south.v2 import DataMigration
55
from django.db import models
6+
from lxml import etree
67
from editorsnotes.main.models import Document
78

89
class Migration(DataMigration):
910

1011
def forwards(self, orm):
1112
"Write your forwards methods here."
1213
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
14+
digest_update_query = """
15+
UPDATE main_document
16+
SET description_digest = %s
17+
WHERE id = %s
18+
"""
1319
for document in orm['main.Document'].objects.all():
14-
digest = Document.hash_description(document.description)
15-
document.description_digest = digest
16-
document.save()
20+
db.execute(digest_update_query,
21+
params=[Document.hash_description(document.description),
22+
document.id])
1723

1824
duplicates_query = """
1925
SELECT project_id, description_digest, COUNT(description_digest) as occurences
@@ -34,9 +40,14 @@ def forwards(self, orm):
3440
last_el.tail += appended_text
3541
else:
3642
last_el.text += appended_text
37-
document.description = description
38-
document.description_digest = Document.hash_description(description)
39-
document.save()
43+
update_query = """
44+
UPDATE main_document
45+
SET description = %s, description_digest = %s
46+
WHERE id = %s
47+
"""
48+
db.execute(update_query, params=[etree.tostring(description),
49+
Document.hash_description(description),
50+
document.id])
4051
remaining_duplicates = db.execute(duplicates_query)
4152
assert not len(remaining_duplicates), "Still duplicates"
4253

0 commit comments

Comments
 (0)