1 # -*- coding: utf-8 -*-
3 from xml.dom import minidom
4 from datetime import datetime, timedelta
9 from django.utils.translation import ugettext as _
10 from django.template.defaultfilters import slugify
11 from forum.models.utils import dbsafe_encode
14 from django.utils.encoding import force_unicode
15 from django.db.utils import IntegrityError
18 from cPickle import loads, dumps
20 from pickle import loads, dumps
22 from copy import deepcopy
23 from base64 import b64encode, b64decode
24 from zlib import compress, decompress
26 from xml.sax import make_parser
27 from xml.sax.handler import ContentHandler
29 class SXTableHandler(ContentHandler):
30 def __init__(self, fname, callback):
35 self.fname = fname.lower()
36 self.callback = callback
38 def startElement(self, name, attrs):
39 if name.lower() == self.fname:
41 elif name.lower() == "row":
44 def characters(self, ch):
47 def endElement(self, name):
48 if name.lower() == self.fname:
50 elif name.lower() == "row":
51 self.callback(self.el_data)
57 self.el_data[name.lower()] = self.ch_data.strip()
62 def readTable(path, name, callback):
63 parser = make_parser()
64 handler = SXTableHandler(name, callback)
65 parser.setContentHandler(handler)
67 f = os.path.join(path, "%s.xml" % name)
71 def dbsafe_encode(value):
72 return force_unicode(b64encode(compress(dumps(deepcopy(value)))))
76 for node in el.childNodes:
77 if node.nodeType == node.TEXT_NODE:
81 msstrip = re.compile(r'^(.*)\.\d+')
83 noms = msstrip.match(ts)
87 return datetime(*time.strptime(ts, '%Y-%m-%dT%H:%M:%S')[0:6])
90 # return dict([(n.tagName.lower(), getText(n)) for n in el.childNodes if n.nodeType == el.ELEMENT_NODE])
92 #def readTable(dump, name):
93 # for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row'):
95 #return [readEl(e) for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row')]
97 google_accounts_lookup = re.compile(r'^https?://www.google.com/accounts/')
98 yahoo_accounts_lookup = re.compile(r'^https?://me.yahoo.com/a/')
101 re.compile(r'^https?://www.google.com/profiles/(?P<uname>\w+(\.\w+)*)/?$'),
102 re.compile(r'^https?://me.yahoo.com/(?P<uname>\w+(\.\w+)*)/?$'),
103 re.compile(r'^https?://openid.aol.com/(?P<uname>\w+(\.\w+)*)/?$'),
104 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).myopenid.com/?$'),
105 re.compile(r'^https?://flickr.com/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
106 re.compile(r'^https?://technorati.com/people/technorati/(?P<uname>\w+(\.\w+)*)/?$'),
107 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).wordpress.com/?$'),
108 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).blogspot.com/?$'),
109 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).livejournal.com/?$'),
110 re.compile(r'^https?://claimid.com/(?P<uname>\w+(\.\w+)*)/?$'),
111 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).pip.verisignlabs.com/?$'),
112 re.compile(r'^https?://getopenid.com/(?P<uname>\w+(\.\w+)*)/?$'),
113 re.compile(r'^https?://[\w\.]+/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
114 re.compile(r'^https?://(?P<uname>[\w\.]+)/?$'),
117 def final_username_attempt(sxu):
118 openid = sxu.get('openid', None)
121 if google_accounts_lookup.search(openid):
122 return UnknownGoogleUser(sxu.get('id'))
123 if yahoo_accounts_lookup.search(openid):
124 return UnknownYahooUser(sxu.get('id'))
126 for lookup in openid_lookups:
127 if lookup.search(openid):
128 return lookup.search(openid).group('uname')
130 return UnknownUser(sxu.get('id'))
132 class UnknownUser(object):
133 def __init__(self, id):
137 return _("user-%(id)s") % {'id': self._id}
139 def __unicode__(self):
140 return self.__str__()
142 def encode(self, *args):
143 return self.__str__()
145 class UnknownGoogleUser(UnknownUser):
147 return _("user-%(id)s (google)") % {'id': self._id}
149 class UnknownYahooUser(UnknownUser):
151 return _("user-%(id)s (yahoo)") % {'id': self._id}
154 class IdMapper(dict):
155 def __getitem__(self, key):
157 return super(IdMapper, self).get(key, 1)
159 def __setitem__(self, key, value):
160 super(IdMapper, self).__setitem__(int(key), int(value))
162 class IdIncrementer():
163 def __init__(self, initial):
169 openidre = re.compile('^https?\:\/\/')
170 def userimport(path, options):
171 #users = readTable(dump, "Users")
175 uidmapper = IdMapper()
178 owneruid = options.get('owneruid', None)
179 #check for empty values
186 if sxu.get('id') == '-1':
188 #print "\n".join(["%s : %s" % i for i in sxu.items()])
189 if int(sxu.get('id')) == int(owneruid):
190 osqau = orm.User.objects.get(id=1)
191 for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
192 openids.add(assoc.key)
193 uidmapper[owneruid] = 1
197 username = unicode(sxu.get('displayname',
198 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu)))))[:30]
200 if username in usernames:
201 #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:
202 # osqau = user_by_name[username]
204 # uidmapper[sxu.get('id')] = osqau.id
210 totest = "%s %d" % (username[:29 - len(str(inc))], inc)
212 if not totest in usernames:
216 sxbadges = sxu.get('badgesummary', None)
217 badges = {'1':'0', '2':'0', '3':'0'}
220 badges.update(dict([b.split('=') for b in sxbadges.split()]))
227 email = sxu.get('email', ''),
228 is_superuser = sxu.get('usertypeid') == '5',
229 is_staff = sxu.get('usertypeid') == '4',
231 date_joined = readTime(sxu.get('creationdate')),
232 last_seen = readTime(sxu.get('lastaccessdate')),
233 about = sxu.get('aboutme', ''),
234 date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None,
235 email_isvalid = int(sxu.get('usertypeid')) > 2,
236 website = sxu.get('websiteurl', ''),
237 reputation = int(sxu.get('reputation')),
238 gold = int(badges['1']),
239 silver = int(badges['2']),
240 bronze = int(badges['3']),
241 real_name = sxu.get('realname', '')[:30],
242 location = sxu.get('location', ''),
247 user_joins = orm.Action(
248 action_type = "userjoins",
249 action_date = osqau.date_joined,
254 rep = orm.ActionRepute(
257 date = osqau.date_joined,
263 orm.SubscriptionSettings.objects.get(user=osqau)
265 s = orm.SubscriptionSettings(user=osqau)
268 uidmapper[osqau.id] = osqau.id
270 new_about = sxu.get('aboutme', None)
271 if new_about and osqau.about != new_about:
273 osqau.about = "%s\n|\n%s" % (osqau.about, new_about)
275 osqau.about = new_about
277 osqau.username = sxu.get('displayname',
278 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu))))
279 osqau.email = sxu.get('email', '')
280 osqau.reputation += int(sxu.get('reputation'))
281 osqau.gold += int(badges['1'])
282 osqau.silver += int(badges['2'])
283 osqau.bronze += int(badges['3'])
285 osqau.date_joined = readTime(sxu.get('creationdate'))
286 osqau.website = sxu.get('websiteurl', '')
287 osqau.date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None
288 osqau.location = sxu.get('location', '')
289 osqau.real_name = sxu.get('realname', '')
291 #merged_users.append(osqau.id)
294 usernames.append(osqau.username)
296 openid = sxu.get('openid', None)
297 if openid and openidre.match(openid) and (not openid in openids):
298 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openid, provider="openidurl")
302 openidalt = sxu.get('openidalt', None)
303 if openidalt and openidre.match(openidalt) and (not openidalt in openids):
304 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openidalt, provider="openidurl")
306 openids.add(openidalt)
308 readTable(path, "Users", callback)
310 if uidmapper[-1] == -1:
315 def tagsimport(dump, uidmap):
316 #tags = readTable(dump, "Tags")
322 id = int(sxtag['id']),
323 name = sxtag['name'],
324 used_count = int(sxtag['count']),
325 created_by_id = uidmap[sxtag.get('userid', 1)],
329 tagmap[otag.name] = otag
331 readTable(dump, "Tags", callback)
335 def add_post_state(name, post, action):
336 if not "(%s)" % name in post.state_string:
337 post.state_string = "%s(%s)" % (post.state_string, name)
341 state = orm.NodeState.objects.get(node=post, state_type=name)
342 state.action = action
345 state = orm.NodeState(node=post, state_type=name, action=action)
348 def remove_post_state(name, post):
349 if "(%s)" % name in post.state_string:
351 state = orm.NodeState.objects.get(state_type=name, post=post)
355 post.state_string = "".join("(%s)" % s for s in re.findall('\w+', post.state_string) if s != name)
357 def postimport(dump, uidmap, tagmap):
362 #for h in readTable(dump, "PostHistory"):
363 # if not history.get(h.get('postid'), None):
364 # history[h.get('postid')] = []
366 # history[h.get('postid')].append(h)
368 #posts = readTable(dump, "Posts")
370 def callback(sxpost):
371 nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"
374 node_type = nodetype,
376 added_at = readTime(sxpost['creationdate']),
377 body = sxpost['body'],
378 score = sxpost.get('score', 0),
379 author_id = sxpost.get('deletiondate', None) and 1 or uidmap[sxpost.get('owneruserid', 1)]
384 create_action = orm.Action(
385 action_type = (nodetype == "nodetype") and "ask" or "answer",
386 user_id = post.author_id,
388 action_date = post.added_at
393 if sxpost.get('lasteditoruserid', None):
394 revise_action = orm.Action(
395 action_type = "revise",
396 user_id = uidmap[sxpost.get('lasteditoruserid')],
398 action_date = readTime(sxpost['lasteditdate']),
402 post.last_edited = revise_action
404 if sxpost.get('communityowneddate', None):
405 wikify_action = orm.Action(
406 action_type = "wikify",
409 action_date = readTime(sxpost['communityowneddate'])
413 add_post_state("wiki", post, wikify_action)
415 if sxpost.get('lastactivityuserid', None):
416 post.last_activity_by_id = uidmap[sxpost['lastactivityuserid']]
417 post.last_activity_at = readTime(sxpost['lastactivitydate'])
419 if sxpost.get('posttypeid') == '1': #question
420 post.node_type = "question"
421 post.title = sxpost['title']
423 tagnames = sxpost['tags'].replace(u'ö', '-').replace(u'é', '').replace(u'à ', '')
424 post.tagnames = tagnames
426 post.extra_count = sxpost.get('viewcount', 0)
428 add_tags_to_post(post, tagmap)
431 post.parent_id = sxpost['parentid']
435 all.append(int(post.id))
439 readTable(dump, "Posts", callback)
443 def comment_import(dump, uidmap, posts):
444 #comments = readTable(dump, "PostComments")
445 currid = IdIncrementer(max(posts))
452 node_type = "comment",
453 added_at = readTime(sxc['creationdate']),
454 author_id = uidmap[sxc.get('userid', 1)],
456 parent_id = sxc.get('postid'),
459 if sxc.get('deletiondate', None):
460 delete_action = orm.Action(
461 action_type = "delete",
462 user_id = uidmap[sxc['deletionuserid']],
463 action_date = readTime(sxc['deletiondate'])
466 oc.author_id = uidmap[sxc['deletionuserid']]
469 delete_action.node = oc
472 add_post_state("deleted", oc, delete_action)
474 oc.author_id = uidmap[sxc.get('userid', 1)]
477 create_action = orm.Action(
478 action_type = "comment",
479 user_id = oc.author_id,
481 action_date = oc.added_at
487 posts.append(int(oc.id))
488 mapping[int(sxc['id'])] = int(oc.id)
490 readTable(dump, "PostComments", callback)
491 return posts, mapping
494 def add_tags_to_post(post, tagmap):
495 tags = [tag for tag in [tagmap.get(name.strip()) for name in post.tagnames.split(u' ') if name] if tag]
496 post.tagnames = " ".join([t.name for t in tags]).strip()
498 create_and_activate_revision(post)
501 def create_and_activate_revision(post):
502 rev = orm.NodeRevision(
503 author_id = post.author_id,
506 revised_at = post.added_at,
508 summary = 'Initial revision',
509 tagnames = post.tagnames,
514 post.active_revision_id = rev.id
517 def post_vote_import(dump, uidmap, posts):
518 #votes = readTable(dump, "Posts2Votes")
521 def close_callback(r):
522 close_reasons[r['id']] = r['name']
524 readTable(dump, "CloseReasons", close_callback)
530 user_id=uidmap[sxv['userid']],
531 action_date = readTime(sxv['creationdate']),
534 if not int(sxv['postid']) in posts: return
535 node = orm.Node.objects.get(id=sxv['postid'])
538 if sxv['votetypeid'] == '1':
540 question = orm.Node.objects.get(id=answer.parent_id)
542 action.action_type = "acceptanswer"
547 question.extra_ref_id = answer.id
552 elif sxv['votetypeid'] in ('2', '3'):
553 if not (action.node.id, action.user_id) in user2vote:
554 user2vote.append((action.node.id, action.user_id))
556 action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
560 node_id = action.node.id,
561 user_id = action.user_id,
562 voted_at = action.action_date,
563 value = sxv['votetypeid'] == '2' and 1 or -1,
568 action.action_type = "unknown"
571 elif sxv['votetypeid'] in ('4', '12', '13'):
572 action.action_type = "flag"
577 user_id = action.user_id,
578 flagged_at = action.action_date,
585 elif sxv['votetypeid'] == '5':
586 action.action_type = "favorite"
589 elif sxv['votetypeid'] == '6':
590 action.action_type = "close"
591 action.extra = dbsafe_encode(close_reasons[sxv['comment']])
597 elif sxv['votetypeid'] == '7':
598 action.action_type = "unknown"
604 remove_post_state("closed", node)
606 elif sxv['votetypeid'] == '10':
607 action.action_type = "delete"
610 elif sxv['votetypeid'] == '11':
611 action.action_type = "unknown"
614 remove_post_state("deleted", node)
617 action.action_type = "unknown"
620 if sxv.get('targetrepchange', None):
621 rep = orm.ActionRepute(
623 date = action.action_date,
624 user_id = uidmap[sxv['targetuserid']],
625 value = int(sxv['targetrepchange'])
630 if sxv.get('voterrepchange', None):
631 rep = orm.ActionRepute(
633 date = action.action_date,
634 user_id = uidmap[sxv['userid']],
635 value = int(sxv['voterrepchange'])
640 if action.action_type in ("acceptanswer", "delete", "close"):
641 state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
642 add_post_state(state, node, action)
644 readTable(dump, "Posts2Votes", callback)
647 def comment_vote_import(dump, uidmap, comments):
648 #votes = readTable(dump, "Comments2Votes")
653 if sxv['votetypeid'] == "2":
654 comment_id = comments[int(sxv['postcommentid'])]
655 user_id = uidmap[sxv['userid']]
657 if not (comment_id, user_id) in user2vote:
658 user2vote.append((comment_id, user_id))
661 action_type = "voteupcomment",
663 action_date = readTime(sxv['creationdate']),
669 node_id = comment_id,
671 voted_at = action.action_date,
678 if not comment_id in comments2score:
679 comments2score[comment_id] = 1
681 comments2score[comment_id] += 1
683 readTable(dump, "Comments2Votes", callback)
685 for cid, score in comments2score.items():
686 orm.Node.objects.filter(id=cid).update(score=score)
689 def badges_import(dump, uidmap, post_list):
690 #node_ctype = orm['contenttypes.contenttype'].objects.get(name='node')
695 sxbadges[int(b['id'])] = b
697 readTable(dump, "Badges", sxcallback)
699 obadges = dict([(b.cls, b) for b in orm.Badge.objects.all()])
700 user_badge_count = {}
704 for id, sxb in sxbadges.items():
705 cls = "".join(sxb['name'].replace('&', 'And').split(' '))
708 sx_to_osqa[id] = obadges[cls]
716 sx_to_osqa[id] = osqab
721 badge = sx_to_osqa[int(sxa['badgeid'])]
723 user_id = uidmap[sxa['userid']]
724 if not user_badge_count.get(user_id, None):
725 user_badge_count[user_id] = 0
728 action_type = "award",
730 action_date = readTime(sxa['date'])
736 user_id = uidmap[sxa['userid']],
738 node_id = post_list[user_badge_count[user_id]],
739 awarded_at = action.action_date,
744 badge.awarded_count += 1
745 user_badge_count[user_id] += 1
747 readTable(dump, "Users2Badges", callback)
749 for badge in obadges.values():
752 def pages_import(dump, currid):
753 currid = IdIncrementer(currid)
755 #sx_pages = readTable(dump, "FlatPages")
763 body = b64decode(sxp['value']),
764 extra = dbsafe_encode({
765 'path': sxp['url'][1:],
766 'mimetype': sxp['contenttype'],
767 'template': (sxp['usemaster'] == "true") and "default" or "none",
770 'sidebar_wrap': True,
771 'sidebar_render': "html",
778 registry[sxp['url'][1:]] = page.id
780 create_action = orm.Action(
781 action_type = "newpage",
782 user_id = page.author_id,
788 if sxp['active'] == "true" and sxp['contenttype'] == "text/html":
789 pub_action = orm.Action(
790 action_type = "publish",
791 user_id = page.author_id,
796 add_post_state("published", page, pub_action)
798 readTable(dump, "FlatPages", callback)
800 kv = orm.KeyValue(key='STATIC_PAGE_REGISTRY', value=dbsafe_encode(registry))
804 u'theme.html.name': 'APP_TITLE',
805 u'theme.html.footer': 'CUSTOM_FOOTER',
806 u'theme.html.sidebar': 'SIDEBAR_UPPER_TEXT',
807 u'theme.html.sidebar-low': 'SIDEBAR_LOWER_TEXT',
808 u'theme.html.welcome': 'APP_INTRO',
809 u'theme.html.head': 'CUSTOM_HEAD',
810 u'theme.html.header': 'CUSTOM_HEADER',
811 u'theme.css': 'CUSTOM_CSS',
822 def html_decode(html):
823 html = force_unicode(html)
825 for args in html_codes:
826 html = html.replace(*args)
831 def static_import(dump):
832 #sx_sets = readTable(dump, "ThemeTextResources")
836 if unicode(set['name']) in sx2osqa_set_map:
838 kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
839 kv.value = dbsafe_encode(html_decode(set['value']))
842 key = sx2osqa_set_map[set['name']],
843 value = dbsafe_encode(html_decode(set['value']))
848 sx_unknown[set['name']] = html_decode(set['value'])
850 readTable(dump, "ThemeTextResources", callback)
852 unknown = orm.KeyValue(key='SXIMPORT_UNKNOWN_SETS', value=dbsafe_encode(sx_unknown))
855 def disable_triggers():
856 from south.db import db
857 if db.backend_name == "postgres":
858 db.execute_many(PG_DISABLE_TRIGGERS)
859 db.commit_transaction()
860 db.start_transaction()
862 def enable_triggers():
863 from south.db import db
864 if db.backend_name == "postgres":
865 db.start_transaction()
866 db.execute_many(PG_ENABLE_TRIGGERS)
867 db.commit_transaction()
869 def reset_sequences():
870 from south.db import db
871 if db.backend_name == "postgres":
872 db.start_transaction()
873 db.execute_many(PG_SEQUENCE_RESETS)
874 db.commit_transaction()
877 from south.db import db
878 if db.backend_name == "postgres":
879 db.start_transaction()
880 db.execute_many("UPDATE forum_noderevision set id = id WHERE TRUE;")
881 db.commit_transaction()
884 def sximport(dump, options):
887 triggers_disabled = True
889 triggers_disabled = False
891 uidmap = userimport(dump, options)
892 tagmap = tagsimport(dump, uidmap)
895 posts = postimport(dump, uidmap, tagmap)
898 posts, comments = comment_import(dump, uidmap, posts)
901 post_vote_import(dump, uidmap, posts)
904 comment_vote_import(dump, uidmap, comments)
907 badges_import(dump, uidmap, posts)
909 pages_import(dump, max(posts))
913 from south.db import db
914 db.commit_transaction()
918 if triggers_disabled:
923 PG_DISABLE_TRIGGERS = """
924 ALTER table auth_user DISABLE TRIGGER ALL;
925 ALTER table auth_user_groups DISABLE TRIGGER ALL;
926 ALTER table auth_user_user_permissions DISABLE TRIGGER ALL;
927 ALTER table forum_keyvalue DISABLE TRIGGER ALL;
928 ALTER table forum_action DISABLE TRIGGER ALL;
929 ALTER table forum_actionrepute DISABLE TRIGGER ALL;
930 ALTER table forum_subscriptionsettings DISABLE TRIGGER ALL;
931 ALTER table forum_validationhash DISABLE TRIGGER ALL;
932 ALTER table forum_authkeyuserassociation DISABLE TRIGGER ALL;
933 ALTER table forum_tag DISABLE TRIGGER ALL;
934 ALTER table forum_markedtag DISABLE TRIGGER ALL;
935 ALTER table forum_node DISABLE TRIGGER ALL;
936 ALTER table forum_nodestate DISABLE TRIGGER ALL;
937 ALTER table forum_node_tags DISABLE TRIGGER ALL;
938 ALTER table forum_noderevision DISABLE TRIGGER ALL;
939 ALTER table forum_node_tags DISABLE TRIGGER ALL;
940 ALTER table forum_questionsubscription DISABLE TRIGGER ALL;
941 ALTER table forum_vote DISABLE TRIGGER ALL;
942 ALTER table forum_flag DISABLE TRIGGER ALL;
943 ALTER table forum_badge DISABLE TRIGGER ALL;
944 ALTER table forum_award DISABLE TRIGGER ALL;
945 ALTER table forum_openidnonce DISABLE TRIGGER ALL;
946 ALTER table forum_openidassociation DISABLE TRIGGER ALL;
949 PG_ENABLE_TRIGGERS = """
950 ALTER table auth_user ENABLE TRIGGER ALL;
951 ALTER table auth_user_groups ENABLE TRIGGER ALL;
952 ALTER table auth_user_user_permissions ENABLE TRIGGER ALL;
953 ALTER table forum_keyvalue ENABLE TRIGGER ALL;
954 ALTER table forum_action ENABLE TRIGGER ALL;
955 ALTER table forum_actionrepute ENABLE TRIGGER ALL;
956 ALTER table forum_subscriptionsettings ENABLE TRIGGER ALL;
957 ALTER table forum_validationhash ENABLE TRIGGER ALL;
958 ALTER table forum_authkeyuserassociation ENABLE TRIGGER ALL;
959 ALTER table forum_tag ENABLE TRIGGER ALL;
960 ALTER table forum_markedtag ENABLE TRIGGER ALL;
961 ALTER table forum_node ENABLE TRIGGER ALL;
962 ALTER table forum_nodestate ENABLE TRIGGER ALL;
963 ALTER table forum_node_tags ENABLE TRIGGER ALL;
964 ALTER table forum_noderevision ENABLE TRIGGER ALL;
965 ALTER table forum_node_tags ENABLE TRIGGER ALL;
966 ALTER table forum_questionsubscription ENABLE TRIGGER ALL;
967 ALTER table forum_vote ENABLE TRIGGER ALL;
968 ALTER table forum_flag ENABLE TRIGGER ALL;
969 ALTER table forum_badge ENABLE TRIGGER ALL;
970 ALTER table forum_award ENABLE TRIGGER ALL;
971 ALTER table forum_openidnonce ENABLE TRIGGER ALL;
972 ALTER table forum_openidassociation ENABLE TRIGGER ALL;
975 PG_SEQUENCE_RESETS = """
976 SELECT setval('"auth_user_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user";
977 SELECT setval('"auth_user_groups_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_groups";
978 SELECT setval('"auth_user_user_permissions_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_user_permissions";
979 SELECT setval('"forum_keyvalue_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_keyvalue";
980 SELECT setval('"forum_action_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_action";
981 SELECT setval('"forum_actionrepute_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_actionrepute";
982 SELECT setval('"forum_subscriptionsettings_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_subscriptionsettings";
983 SELECT setval('"forum_validationhash_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_validationhash";
984 SELECT setval('"forum_authkeyuserassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_authkeyuserassociation";
985 SELECT setval('"forum_tag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_tag";
986 SELECT setval('"forum_markedtag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_markedtag";
987 SELECT setval('"forum_node_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node";
988 SELECT setval('"forum_nodestate_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_nodestate";
989 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
990 SELECT setval('"forum_noderevision_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_noderevision";
991 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
992 SELECT setval('"forum_questionsubscription_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_questionsubscription";
993 SELECT setval('"forum_vote_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_vote";
994 SELECT setval('"forum_flag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_flag";
995 SELECT setval('"forum_badge_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_badge";
996 SELECT setval('"forum_award_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_award";
997 SELECT setval('"forum_openidnonce_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidnonce";
998 SELECT setval('"forum_openidassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidassociation";