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
17 from cPickle import loads, dumps
19 from pickle import loads, dumps
21 from copy import deepcopy
22 from base64 import b64encode, b64decode
23 from zlib import compress, decompress
25 from xml.sax import make_parser
26 from xml.sax.handler import ContentHandler
28 class SXTableHandler(ContentHandler):
29 def __init__(self, fname, callback):
34 self.fname = fname.lower()
35 self.callback = callback
37 def startElement(self, name, attrs):
38 if name.lower() == self.fname:
40 elif name.lower() == "row":
43 def characters(self, ch):
46 def endElement(self, name):
47 if name.lower() == self.fname:
49 elif name.lower() == "row":
50 self.callback(self.el_data)
56 self.el_data[name.lower()] = self.ch_data.strip()
61 def readTable(path, name, callback):
62 parser = make_parser()
63 handler = SXTableHandler(name, callback)
64 parser.setContentHandler(handler)
66 f = os.path.join(path, "%s.xml" % name)
70 def dbsafe_encode(value):
71 return force_unicode(b64encode(compress(dumps(deepcopy(value)))))
75 for node in el.childNodes:
76 if node.nodeType == node.TEXT_NODE:
80 msstrip = re.compile(r'^(.*)\.\d+')
82 noms = msstrip.match(ts)
86 return datetime(*time.strptime(ts, '%Y-%m-%dT%H:%M:%S')[0:6])
89 # return dict([(n.tagName.lower(), getText(n)) for n in el.childNodes if n.nodeType == el.ELEMENT_NODE])
91 #def readTable(dump, name):
92 # for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row'):
94 #return [readEl(e) for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row')]
96 google_accounts_lookup = re.compile(r'^https?://www.google.com/accounts/')
97 yahoo_accounts_lookup = re.compile(r'^https?://me.yahoo.com/a/')
100 re.compile(r'^https?://www.google.com/profiles/(?P<uname>\w+(\.\w+)*)/?$'),
101 re.compile(r'^https?://me.yahoo.com/(?P<uname>\w+(\.\w+)*)/?$'),
102 re.compile(r'^https?://openid.aol.com/(?P<uname>\w+(\.\w+)*)/?$'),
103 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).myopenid.com/?$'),
104 re.compile(r'^https?://flickr.com/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
105 re.compile(r'^https?://technorati.com/people/technorati/(?P<uname>\w+(\.\w+)*)/?$'),
106 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).wordpress.com/?$'),
107 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).blogspot.com/?$'),
108 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).livejournal.com/?$'),
109 re.compile(r'^https?://claimid.com/(?P<uname>\w+(\.\w+)*)/?$'),
110 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).pip.verisignlabs.com/?$'),
111 re.compile(r'^https?://getopenid.com/(?P<uname>\w+(\.\w+)*)/?$'),
112 re.compile(r'^https?://[\w\.]+/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
113 re.compile(r'^https?://(?P<uname>[\w\.]+)/?$'),
116 def final_username_attempt(sxu):
117 openid = sxu.get('openid', None)
120 if google_accounts_lookup.search(openid):
121 return UnknownGoogleUser(sxu.get('id'))
122 if yahoo_accounts_lookup.search(openid):
123 return UnknownYahooUser(sxu.get('id'))
125 for lookup in openid_lookups:
126 if lookup.search(openid):
127 return lookup.search(openid).group('uname')
129 return UnknownUser(sxu.get('id'))
131 class UnknownUser(object):
132 def __init__(self, id):
136 return _("user-%(id)s") % {'id': self._id}
138 def __unicode__(self):
139 return self.__str__()
141 def encode(self, *args):
142 return self.__str__()
144 class UnknownGoogleUser(UnknownUser):
146 return _("user-%(id)s (google)") % {'id': self._id}
148 class UnknownYahooUser(UnknownUser):
150 return _("user-%(id)s (yahoo)") % {'id': self._id}
153 class IdMapper(dict):
154 def __getitem__(self, key):
156 return super(IdMapper, self).get(key, 1)
158 def __setitem__(self, key, value):
159 super(IdMapper, self).__setitem__(int(key), int(value))
161 class IdIncrementer():
162 def __init__(self, initial):
168 openidre = re.compile('^https?\:\/\/')
169 def userimport(path, options):
170 #users = readTable(dump, "Users")
174 uidmapper = IdMapper()
177 owneruid = options.get('owneruid', None)
178 #check for empty values
185 if sxu.get('id') == '-1':
187 #print "\n".join(["%s : %s" % i for i in sxu.items()])
188 if int(sxu.get('id')) == int(owneruid):
189 osqau = orm.User.objects.get(id=1)
190 for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
191 openids.add(assoc.key)
192 uidmapper[owneruid] = 1
196 username = unicode(sxu.get('displayname',
197 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu)))))[:30]
199 if username in usernames:
200 #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:
201 # osqau = user_by_name[username]
203 # uidmapper[sxu.get('id')] = osqau.id
209 totest = "%s %d" % (username[:29 - len(str(inc))], inc)
211 if not totest in usernames:
215 sxbadges = sxu.get('badgesummary', None)
216 badges = {'1':'0', '2':'0', '3':'0'}
219 badges.update(dict([b.split('=') for b in sxbadges.split()]))
226 email = sxu.get('email', ''),
227 is_superuser = sxu.get('usertypeid') == '5',
228 is_staff = sxu.get('usertypeid') == '4',
230 date_joined = readTime(sxu.get('creationdate')),
231 last_seen = readTime(sxu.get('lastaccessdate')),
232 about = sxu.get('aboutme', ''),
233 date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None,
234 email_isvalid = int(sxu.get('usertypeid')) > 2,
235 website = sxu.get('websiteurl', ''),
236 reputation = int(sxu.get('reputation')),
237 gold = int(badges['1']),
238 silver = int(badges['2']),
239 bronze = int(badges['3']),
240 real_name = sxu.get('realname', '')[:30],
241 location = sxu.get('location', ''),
246 user_joins = orm.Action(
247 action_type = "userjoins",
248 action_date = osqau.date_joined,
253 rep = orm.ActionRepute(
256 date = osqau.date_joined,
262 orm.SubscriptionSettings.objects.get(user=osqau)
264 s = orm.SubscriptionSettings(user=osqau)
267 uidmapper[osqau.id] = osqau.id
269 new_about = sxu.get('aboutme', None)
270 if new_about and osqau.about != new_about:
272 osqau.about = "%s\n|\n%s" % (osqau.about, new_about)
274 osqau.about = new_about
276 osqau.username = sxu.get('displayname',
277 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu))))
278 osqau.email = sxu.get('email', '')
279 osqau.reputation += int(sxu.get('reputation'))
280 osqau.gold += int(badges['1'])
281 osqau.silver += int(badges['2'])
282 osqau.bronze += int(badges['3'])
284 osqau.date_joined = readTime(sxu.get('creationdate'))
285 osqau.website = sxu.get('websiteurl', '')
286 osqau.date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None
287 osqau.location = sxu.get('location', '')
288 osqau.real_name = sxu.get('realname', '')
290 #merged_users.append(osqau.id)
293 usernames.append(osqau.username)
295 openid = sxu.get('openid', None)
296 if openid and openidre.match(openid) and (not openid in openids):
297 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openid, provider="openidurl")
301 openidalt = sxu.get('openidalt', None)
302 if openidalt and openidre.match(openidalt) and (not openidalt in openids):
303 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openidalt, provider="openidurl")
305 openids.add(openidalt)
307 readTable(path, "Users", callback)
309 if uidmapper[-1] == -1:
314 def tagsimport(dump, uidmap):
315 #tags = readTable(dump, "Tags")
321 id = int(sxtag['id']),
322 name = sxtag['name'],
323 used_count = int(sxtag['count']),
324 created_by_id = uidmap[sxtag.get('userid', 1)],
328 tagmap[otag.name] = otag
330 readTable(dump, "Tags", callback)
334 def add_post_state(name, post, action):
335 if not "(%s)" % name in post.state_string:
336 post.state_string = "%s(%s)" % (post.state_string, name)
340 state = orm.NodeState.objects.get(node=post, state_type=name)
341 state.action = action
344 state = orm.NodeState(node=post, state_type=name, action=action)
347 def remove_post_state(name, post):
348 if "(%s)" % name in post.state_string:
350 state = orm.NodeState.objects.get(state_type=name, post=post)
354 post.state_string = "".join("(%s)" % s for s in re.findall('\w+', post.state_string) if s != name)
356 def postimport(dump, uidmap, tagmap):
361 #for h in readTable(dump, "PostHistory"):
362 # if not history.get(h.get('postid'), None):
363 # history[h.get('postid')] = []
365 # history[h.get('postid')].append(h)
367 #posts = readTable(dump, "Posts")
369 def callback(sxpost):
370 nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"
373 node_type = nodetype,
375 added_at = readTime(sxpost['creationdate']),
376 body = sxpost['body'],
377 score = sxpost.get('score', 0),
378 author_id = sxpost.get('deletiondate', None) and 1 or uidmap[sxpost.get('owneruserid', 1)]
383 create_action = orm.Action(
384 action_type = (nodetype == "nodetype") and "ask" or "answer",
385 user_id = post.author_id,
387 action_date = post.added_at
392 if sxpost.get('lasteditoruserid', None):
393 revise_action = orm.Action(
394 action_type = "revise",
395 user_id = uidmap[sxpost.get('lasteditoruserid')],
397 action_date = readTime(sxpost['lasteditdate']),
401 post.last_edited = revise_action
403 if sxpost.get('communityowneddate', None):
404 wikify_action = orm.Action(
405 action_type = "wikify",
408 action_date = readTime(sxpost['communityowneddate'])
412 add_post_state("wiki", post, wikify_action)
414 if sxpost.get('lastactivityuserid', None):
415 post.last_activity_by_id = uidmap[sxpost['lastactivityuserid']]
416 post.last_activity_at = readTime(sxpost['lastactivitydate'])
418 if sxpost.get('posttypeid') == '1': #question
419 post.node_type = "question"
420 post.title = sxpost['title']
422 tagnames = sxpost['tags'].replace(u'ö', '-').replace(u'é', '').replace(u'à ', '')
423 post.tagnames = tagnames
425 post.extra_count = sxpost.get('viewcount', 0)
427 add_tags_to_post(post, tagmap)
430 post.parent_id = sxpost['parentid']
434 all.append(int(post.id))
438 readTable(dump, "Posts", callback)
442 def comment_import(dump, uidmap, posts):
443 #comments = readTable(dump, "PostComments")
444 currid = IdIncrementer(max(posts))
451 node_type = "comment",
452 added_at = readTime(sxc['creationdate']),
453 author_id = uidmap[sxc.get('userid', 1)],
455 parent_id = sxc.get('postid'),
458 if sxc.get('deletiondate', None):
459 delete_action = orm.Action(
460 action_type = "delete",
461 user_id = uidmap[sxc['deletionuserid']],
462 action_date = readTime(sxc['deletiondate'])
465 oc.author_id = uidmap[sxc['deletionuserid']]
468 delete_action.node = oc
471 add_post_state("deleted", oc, delete_action)
473 oc.author_id = uidmap[sxc.get('userid', 1)]
476 create_action = orm.Action(
477 action_type = "comment",
478 user_id = oc.author_id,
480 action_date = oc.added_at
486 posts.append(int(oc.id))
487 mapping[int(sxc['id'])] = int(oc.id)
489 readTable(dump, "PostComments", callback)
490 return posts, mapping
493 def add_tags_to_post(post, tagmap):
494 tags = [tag for tag in [tagmap.get(name.strip()) for name in post.tagnames.split(u' ') if name] if tag]
495 post.tagnames = " ".join([t.name for t in tags]).strip()
497 create_and_activate_revision(post)
500 def create_and_activate_revision(post):
501 rev = orm.NodeRevision(
502 author_id = post.author_id,
505 revised_at = post.added_at,
507 summary = 'Initial revision',
508 tagnames = post.tagnames,
513 post.active_revision_id = rev.id
516 def post_vote_import(dump, uidmap, posts):
517 #votes = readTable(dump, "Posts2Votes")
520 def close_callback(r):
521 close_reasons[r['id']] = r['name']
523 readTable(dump, "CloseReasons", close_callback)
529 user_id=uidmap[sxv['userid']],
530 action_date = readTime(sxv['creationdate']),
533 if not int(sxv['postid']) in posts: return
534 node = orm.Node.objects.get(id=sxv['postid'])
537 if sxv['votetypeid'] == '1':
539 question = orm.Node.objects.get(id=answer.parent_id)
541 action.action_type = "acceptanswer"
546 question.extra_ref_id = answer.id
551 elif sxv['votetypeid'] in ('2', '3'):
552 if not (action.node.id, action.user_id) in user2vote:
553 user2vote.append((action.node.id, action.user_id))
555 action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
559 node_id = action.node.id,
560 user_id = action.user_id,
561 voted_at = action.action_date,
562 value = sxv['votetypeid'] == '2' and 1 or -1,
567 action.action_type = "unknown"
570 elif sxv['votetypeid'] in ('4', '12', '13'):
571 action.action_type = "flag"
576 user_id = action.user_id,
577 flagged_at = action.action_date,
584 elif sxv['votetypeid'] == '5':
585 action.action_type = "favorite"
588 elif sxv['votetypeid'] == '6':
589 action.action_type = "close"
590 action.extra = dbsafe_encode(close_reasons[sxv['comment']])
596 elif sxv['votetypeid'] == '7':
597 action.action_type = "unknown"
603 remove_post_state("closed", node)
605 elif sxv['votetypeid'] == '10':
606 action.action_type = "delete"
609 elif sxv['votetypeid'] == '11':
610 action.action_type = "unknown"
613 remove_post_state("deleted", node)
616 action.action_type = "unknown"
619 if sxv.get('targetrepchange', None):
620 rep = orm.ActionRepute(
622 date = action.action_date,
623 user_id = uidmap[sxv['targetuserid']],
624 value = int(sxv['targetrepchange'])
629 if sxv.get('voterrepchange', None):
630 rep = orm.ActionRepute(
632 date = action.action_date,
633 user_id = uidmap[sxv['userid']],
634 value = int(sxv['voterrepchange'])
639 if action.action_type in ("acceptanswer", "delete", "close"):
640 state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
641 add_post_state(state, node, action)
643 readTable(dump, "Posts2Votes", callback)
646 def comment_vote_import(dump, uidmap, comments):
647 #votes = readTable(dump, "Comments2Votes")
652 if sxv['votetypeid'] == "2":
653 comment_id = comments[int(sxv['postcommentid'])]
654 user_id = uidmap[sxv['userid']]
656 if not (comment_id, user_id) in user2vote:
657 user2vote.append((comment_id, user_id))
660 action_type = "voteupcomment",
662 action_date = readTime(sxv['creationdate']),
668 node_id = comment_id,
670 voted_at = action.action_date,
677 if not comment_id in comments2score:
678 comments2score[comment_id] = 1
680 comments2score[comment_id] += 1
682 readTable(dump, "Comments2Votes", callback)
684 for cid, score in comments2score.items():
685 orm.Node.objects.filter(id=cid).update(score=score)
688 def badges_import(dump, uidmap, post_list):
689 #node_ctype = orm['contenttypes.contenttype'].objects.get(name='node')
694 sxbadges[int(b['id'])] = b
696 readTable(dump, "Badges", sxcallback)
698 obadges = dict([(b.cls, b) for b in orm.Badge.objects.all()])
699 user_badge_count = {}
703 for id, sxb in sxbadges.items():
704 cls = "".join(sxb['name'].replace('&', 'And').split(' '))
707 sx_to_osqa[id] = obadges[cls]
715 sx_to_osqa[id] = osqab
720 badge = sx_to_osqa[int(sxa['badgeid'])]
722 user_id = uidmap[sxa['userid']]
723 if not user_badge_count.get(user_id, None):
724 user_badge_count[user_id] = 0
727 action_type = "award",
729 action_date = readTime(sxa['date'])
735 user_id = uidmap[sxa['userid']],
737 node_id = post_list[user_badge_count[user_id]],
738 awarded_at = action.action_date,
743 badge.awarded_count += 1
744 user_badge_count[user_id] += 1
746 readTable(dump, "Users2Badges", callback)
748 for badge in obadges.values():
751 def pages_import(dump, currid):
752 currid = IdIncrementer(currid)
754 #sx_pages = readTable(dump, "FlatPages")
762 body = b64decode(sxp['value']),
763 extra = dbsafe_encode({
764 'path': sxp['url'][1:],
765 'mimetype': sxp['contenttype'],
766 'template': (sxp['usemaster'] == "true") and "default" or "none",
769 'sidebar_wrap': True,
770 'sidebar_render': "html",
777 registry[sxp['url'][1:]] = page.id
779 create_action = orm.Action(
780 action_type = "newpage",
781 user_id = page.author_id,
787 if sxp['active'] == "true" and sxp['contenttype'] == "text/html":
788 pub_action = orm.Action(
789 action_type = "publish",
790 user_id = page.author_id,
795 add_post_state("published", page, pub_action)
797 readTable(dump, "FlatPages", callback)
799 kv = orm.KeyValue(key='STATIC_PAGE_REGISTRY', value=dbsafe_encode(registry))
803 u'theme.html.name': 'APP_TITLE',
804 u'theme.html.footer': 'CUSTOM_FOOTER',
805 u'theme.html.sidebar': 'SIDEBAR_UPPER_TEXT',
806 u'theme.html.sidebar-low': 'SIDEBAR_LOWER_TEXT',
807 u'theme.html.welcome': 'APP_INTRO',
808 u'theme.html.head': 'CUSTOM_HEAD',
809 u'theme.html.header': 'CUSTOM_HEADER',
810 u'theme.css': 'CUSTOM_CSS',
821 def html_decode(html):
822 html = force_unicode(html)
824 for args in html_codes:
825 html = html.replace(*args)
830 def static_import(dump):
831 #sx_sets = readTable(dump, "ThemeTextResources")
835 if unicode(set['name']) in sx2osqa_set_map:
837 kv = orm.KeyValue.objects.get(key=sx2osqa_set_map[set['name']])
838 kv.value = dbsafe_encode(html_decode(set['value']))
841 key = sx2osqa_set_map[set['name']],
842 value = dbsafe_encode(html_decode(set['value']))
847 sx_unknown[set['name']] = html_decode(set['value'])
849 readTable(dump, "ThemeTextResources", callback)
851 unknown = orm.KeyValue(key='SXIMPORT_UNKNOWN_SETS', value=dbsafe_encode(sx_unknown))
854 def disable_triggers():
855 from south.db import db
856 if db.backend_name == "postgres":
857 db.execute_many(PG_DISABLE_TRIGGERS)
858 db.commit_transaction()
859 db.start_transaction()
861 def enable_triggers():
862 from south.db import db
863 if db.backend_name == "postgres":
864 db.start_transaction()
865 db.execute_many(PG_ENABLE_TRIGGERS)
866 db.commit_transaction()
868 def reset_sequences():
869 from south.db import db
870 if db.backend_name == "postgres":
871 db.start_transaction()
872 db.execute_many(PG_SEQUENCE_RESETS)
873 db.commit_transaction()
876 from south.db import db
877 if db.backend_name == "postgres":
878 db.start_transaction()
879 db.execute_many("UPDATE forum_noderevision set id = id WHERE TRUE;")
880 db.commit_transaction()
883 def sximport(dump, options):
886 triggers_disabled = True
888 triggers_disabled = False
890 uidmap = userimport(dump, options)
891 tagmap = tagsimport(dump, uidmap)
894 posts = postimport(dump, uidmap, tagmap)
897 posts, comments = comment_import(dump, uidmap, posts)
900 post_vote_import(dump, uidmap, posts)
903 comment_vote_import(dump, uidmap, comments)
906 badges_import(dump, uidmap, posts)
908 pages_import(dump, max(posts))
912 from south.db import db
913 db.commit_transaction()
917 if triggers_disabled:
922 PG_DISABLE_TRIGGERS = """
923 ALTER table auth_user DISABLE TRIGGER ALL;
924 ALTER table auth_user_groups DISABLE TRIGGER ALL;
925 ALTER table auth_user_user_permissions DISABLE TRIGGER ALL;
926 ALTER table forum_keyvalue DISABLE TRIGGER ALL;
927 ALTER table forum_action DISABLE TRIGGER ALL;
928 ALTER table forum_actionrepute DISABLE TRIGGER ALL;
929 ALTER table forum_subscriptionsettings DISABLE TRIGGER ALL;
930 ALTER table forum_validationhash DISABLE TRIGGER ALL;
931 ALTER table forum_authkeyuserassociation DISABLE TRIGGER ALL;
932 ALTER table forum_tag DISABLE TRIGGER ALL;
933 ALTER table forum_markedtag DISABLE TRIGGER ALL;
934 ALTER table forum_node DISABLE TRIGGER ALL;
935 ALTER table forum_nodestate DISABLE TRIGGER ALL;
936 ALTER table forum_node_tags DISABLE TRIGGER ALL;
937 ALTER table forum_noderevision DISABLE TRIGGER ALL;
938 ALTER table forum_node_tags DISABLE TRIGGER ALL;
939 ALTER table forum_questionsubscription DISABLE TRIGGER ALL;
940 ALTER table forum_vote DISABLE TRIGGER ALL;
941 ALTER table forum_flag DISABLE TRIGGER ALL;
942 ALTER table forum_badge DISABLE TRIGGER ALL;
943 ALTER table forum_award DISABLE TRIGGER ALL;
944 ALTER table forum_openidnonce DISABLE TRIGGER ALL;
945 ALTER table forum_openidassociation DISABLE TRIGGER ALL;
948 PG_ENABLE_TRIGGERS = """
949 ALTER table auth_user ENABLE TRIGGER ALL;
950 ALTER table auth_user_groups ENABLE TRIGGER ALL;
951 ALTER table auth_user_user_permissions ENABLE TRIGGER ALL;
952 ALTER table forum_keyvalue ENABLE TRIGGER ALL;
953 ALTER table forum_action ENABLE TRIGGER ALL;
954 ALTER table forum_actionrepute ENABLE TRIGGER ALL;
955 ALTER table forum_subscriptionsettings ENABLE TRIGGER ALL;
956 ALTER table forum_validationhash ENABLE TRIGGER ALL;
957 ALTER table forum_authkeyuserassociation ENABLE TRIGGER ALL;
958 ALTER table forum_tag ENABLE TRIGGER ALL;
959 ALTER table forum_markedtag ENABLE TRIGGER ALL;
960 ALTER table forum_node ENABLE TRIGGER ALL;
961 ALTER table forum_nodestate ENABLE TRIGGER ALL;
962 ALTER table forum_node_tags ENABLE TRIGGER ALL;
963 ALTER table forum_noderevision ENABLE TRIGGER ALL;
964 ALTER table forum_node_tags ENABLE TRIGGER ALL;
965 ALTER table forum_questionsubscription ENABLE TRIGGER ALL;
966 ALTER table forum_vote ENABLE TRIGGER ALL;
967 ALTER table forum_flag ENABLE TRIGGER ALL;
968 ALTER table forum_badge ENABLE TRIGGER ALL;
969 ALTER table forum_award ENABLE TRIGGER ALL;
970 ALTER table forum_openidnonce ENABLE TRIGGER ALL;
971 ALTER table forum_openidassociation ENABLE TRIGGER ALL;
974 PG_SEQUENCE_RESETS = """
975 SELECT setval('"auth_user_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user";
976 SELECT setval('"auth_user_groups_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_groups";
977 SELECT setval('"auth_user_user_permissions_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_user_permissions";
978 SELECT setval('"forum_keyvalue_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_keyvalue";
979 SELECT setval('"forum_action_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_action";
980 SELECT setval('"forum_actionrepute_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_actionrepute";
981 SELECT setval('"forum_subscriptionsettings_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_subscriptionsettings";
982 SELECT setval('"forum_validationhash_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_validationhash";
983 SELECT setval('"forum_authkeyuserassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_authkeyuserassociation";
984 SELECT setval('"forum_tag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_tag";
985 SELECT setval('"forum_markedtag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_markedtag";
986 SELECT setval('"forum_node_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node";
987 SELECT setval('"forum_nodestate_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_nodestate";
988 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
989 SELECT setval('"forum_noderevision_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_noderevision";
990 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
991 SELECT setval('"forum_questionsubscription_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_questionsubscription";
992 SELECT setval('"forum_vote_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_vote";
993 SELECT setval('"forum_flag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_flag";
994 SELECT setval('"forum_badge_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_badge";
995 SELECT setval('"forum_award_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_award";
996 SELECT setval('"forum_openidnonce_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidnonce";
997 SELECT setval('"forum_openidassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidassociation";