1 # -*- coding: utf-8 -*-
3 from datetime import datetime
8 from django.utils.translation import ugettext as _
10 from django.utils.encoding import force_unicode
13 from cPickle import loads, dumps
15 from pickle import loads, dumps
17 from copy import deepcopy
18 from base64 import b64encode, b64decode
19 from zlib import compress, decompress
21 from xml.sax import make_parser
22 from xml.sax.handler import ContentHandler
25 from django.conf import settings
26 from south.orm import FakeORM
28 get_migration_number_re = re.compile(r'^((\d+)_.*)\.py$')
30 migrations_folder = os.path.join(settings.SITE_SRC_ROOT, 'forum/migrations')
35 for f in os.listdir(migrations_folder):
36 if os.path.isfile(os.path.join(migrations_folder, f)):
37 m = get_migration_number_re.match(f)
40 found = int(m.group(2))
42 if found > highest_number:
43 highest_number = found
44 highest_file = m.group(1)
46 mod = __import__('forum.migrations.%s' % highest_file, globals(), locals(), ['forum.migrations'])
47 return FakeORM(getattr(mod, 'Migration'), "forum")
51 class SXTableHandler(ContentHandler):
52 def __init__(self, fname, callback):
57 self.fname = fname.lower()
58 self.callback = callback
60 def startElement(self, name, attrs):
61 if name.lower() == self.fname:
63 elif name.lower() == "row":
66 def characters(self, ch):
69 def endElement(self, name):
70 if name.lower() == self.fname:
72 elif name.lower() == "row":
73 self.callback(self.el_data)
79 self.el_data[name.lower()] = self.ch_data.strip()
84 def readTable(path, name, callback):
85 parser = make_parser()
86 handler = SXTableHandler(name, callback)
87 parser.setContentHandler(handler)
89 f = os.path.join(path, "%s.xml" % name)
93 def dbsafe_encode(value):
94 return force_unicode(b64encode(compress(dumps(deepcopy(value)))))
98 for node in el.childNodes:
99 if node.nodeType == node.TEXT_NODE:
103 msstrip = re.compile(r'^(.*)\.\d+')
105 noms = msstrip.match(ts)
109 return datetime(*time.strptime(ts, '%Y-%m-%dT%H:%M:%S')[0:6])
112 # return dict([(n.tagName.lower(), getText(n)) for n in el.childNodes if n.nodeType == el.ELEMENT_NODE])
114 #def readTable(dump, name):
115 # for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row'):
117 #return [readEl(e) for e in minidom.parseString(dump.read("%s.xml" % name)).getElementsByTagName('row')]
119 google_accounts_lookup = re.compile(r'^https?://www.google.com/accounts/')
120 yahoo_accounts_lookup = re.compile(r'^https?://me.yahoo.com/a/')
123 re.compile(r'^https?://www.google.com/profiles/(?P<uname>\w+(\.\w+)*)/?$'),
124 re.compile(r'^https?://me.yahoo.com/(?P<uname>\w+(\.\w+)*)/?$'),
125 re.compile(r'^https?://openid.aol.com/(?P<uname>\w+(\.\w+)*)/?$'),
126 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).myopenid.com/?$'),
127 re.compile(r'^https?://flickr.com/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
128 re.compile(r'^https?://technorati.com/people/technorati/(?P<uname>\w+(\.\w+)*)/?$'),
129 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).wordpress.com/?$'),
130 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).blogspot.com/?$'),
131 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).livejournal.com/?$'),
132 re.compile(r'^https?://claimid.com/(?P<uname>\w+(\.\w+)*)/?$'),
133 re.compile(r'^https?://(?P<uname>\w+(\.\w+)*).pip.verisignlabs.com/?$'),
134 re.compile(r'^https?://getopenid.com/(?P<uname>\w+(\.\w+)*)/?$'),
135 re.compile(r'^https?://[\w\.]+/(\w+/)*(?P<uname>\w+(\.\w+)*)/?$'),
136 re.compile(r'^https?://(?P<uname>[\w\.]+)/?$'),
139 def final_username_attempt(sxu):
140 openid = sxu.get('openid', None)
143 if google_accounts_lookup.search(openid):
144 return UnknownGoogleUser(sxu.get('id'))
145 if yahoo_accounts_lookup.search(openid):
146 return UnknownYahooUser(sxu.get('id'))
148 for lookup in openid_lookups:
149 if lookup.search(openid):
150 return lookup.search(openid).group('uname')
152 return UnknownUser(sxu.get('id'))
154 class UnknownUser(object):
155 def __init__(self, id):
159 return _("user-%(id)s") % {'id': self._id}
161 def __unicode__(self):
162 return self.__str__()
164 def encode(self, *args):
165 return self.__str__()
167 class UnknownGoogleUser(UnknownUser):
169 return _("user-%(id)s (google)") % {'id': self._id}
171 class UnknownYahooUser(UnknownUser):
173 return _("user-%(id)s (yahoo)") % {'id': self._id}
176 class IdMapper(dict):
181 def __getitem__(self, key):
183 return super(IdMapper, self).get(key, self.default)
185 def __setitem__(self, key, value):
186 super(IdMapper, self).__setitem__(int(key), int(value))
188 class IdIncrementer():
189 def __init__(self, initial):
195 openidre = re.compile('^https?\:\/\/')
196 def userimport(path, options):
200 uidmapper = IdMapper()
202 authenticated_user = options.get('authenticated_user', None)
203 owneruid = options.get('owneruid', None)
204 #check for empty values
208 owneruid = int(owneruid)
212 set_mapper_defaults = False
214 if sxu.get('id') == '-1':
216 #print "\n".join(["%s : %s" % i for i in sxu.items()])
218 if (owneruid and (int(sxu.get('id')) == owneruid)) or (
219 (not owneruid) and len(uidmapper)):
221 set_mapper_defaults = True
223 if authenticated_user:
224 osqau = orm.User.objects.get(id=authenticated_user.id)
226 for assoc in orm.AuthKeyUserAssociation.objects.filter(user=osqau):
227 openids.add(assoc.key)
229 uidmapper[owneruid] = osqau.id
232 sxbadges = sxu.get('badgesummary', None)
233 badges = {'1':'0', '2':'0', '3':'0'}
236 badges.update(dict([b.split('=') for b in sxbadges.split()]))
239 username = unicode(sxu.get('displayname',
240 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu)))))[:30]
242 if username in usernames:
243 #if options.get('mergesimilar', False) and sxu.get('email', 'INVALID') == user_by_name[username].email:
244 # osqau = user_by_name[username]
246 # uidmapper[sxu.get('id')] = osqau.id
252 totest = "%s %d" % (username[:29 - len(str(inc))], inc)
254 if not totest in usernames:
262 email = sxu.get('email', ''),
263 is_superuser = sxu.get('usertypeid') == '5',
264 is_staff = sxu.get('usertypeid') == '4',
266 date_joined = readTime(sxu.get('creationdate')),
267 last_seen = readTime(sxu.get('lastaccessdate')),
268 about = sxu.get('aboutme', ''),
269 date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None,
270 email_isvalid = int(sxu.get('usertypeid')) > 2,
271 website = sxu.get('websiteurl', ''),
272 reputation = int(sxu.get('reputation')),
273 gold = int(badges['1']),
274 silver = int(badges['2']),
275 bronze = int(badges['3']),
276 real_name = sxu.get('realname', '')[:30],
277 location = sxu.get('location', ''),
282 user_joins = orm.Action(
283 action_type = "userjoins",
284 action_date = osqau.date_joined,
289 rep = orm.ActionRepute(
292 date = osqau.date_joined,
298 orm.SubscriptionSettings.objects.get(user=osqau)
300 s = orm.SubscriptionSettings(user=osqau)
303 uidmapper[osqau.id] = osqau.id
305 new_about = sxu.get('aboutme', None)
306 if new_about and osqau.about != new_about:
308 osqau.about = "%s\n|\n%s" % (osqau.about, new_about)
310 osqau.about = new_about
312 osqau.username = sxu.get('displayname',
313 sxu.get('displaynamecleaned', sxu.get('realname', final_username_attempt(sxu))))
314 osqau.email = sxu.get('email', '')
315 osqau.reputation += int(sxu.get('reputation'))
316 osqau.gold += int(badges['1'])
317 osqau.silver += int(badges['2'])
318 osqau.bronze += int(badges['3'])
320 osqau.date_joined = readTime(sxu.get('creationdate'))
321 osqau.website = sxu.get('websiteurl', '')
322 osqau.date_of_birth = sxu.get('birthday', None) and readTime(sxu['birthday']) or None
323 osqau.location = sxu.get('location', '')
324 osqau.real_name = sxu.get('realname', '')
326 #merged_users.append(osqau.id)
329 if set_mapper_defaults:
330 uidmapper[-1] = osqau.id
331 uidmapper.default = osqau.id
333 usernames.append(osqau.username)
335 openid = sxu.get('openid', None)
336 if openid and openidre.match(openid) and (not openid in openids):
337 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openid, provider="openidurl")
341 openidalt = sxu.get('openidalt', None)
342 if openidalt and openidre.match(openidalt) and (not openidalt in openids):
343 assoc = orm.AuthKeyUserAssociation(user=osqau, key=openidalt, provider="openidurl")
345 openids.add(openidalt)
347 readTable(path, "Users", callback)
349 #if uidmapper[-1] == -1:
354 def tagsimport(dump, uidmap):
360 id = int(sxtag['id']),
361 name = sxtag['name'],
362 used_count = int(sxtag['count']),
363 created_by_id = uidmap[sxtag.get('userid', 1)],
367 tagmap[otag.name] = otag
369 readTable(dump, "Tags", callback)
373 def add_post_state(name, post, action):
374 if not "(%s)" % name in post.state_string:
375 post.state_string = "%s(%s)" % (post.state_string, name)
379 state = orm.NodeState.objects.get(node=post, state_type=name)
380 state.action = action
383 state = orm.NodeState(node=post, state_type=name, action=action)
386 def remove_post_state(name, post):
387 if "(%s)" % name in post.state_string:
389 state = orm.NodeState.objects.get(state_type=name, post=post)
393 post.state_string = "".join("(%s)" % s for s in re.findall('\w+', post.state_string) if s != name)
395 def postimport(dump, uidmap, tagmap):
398 def callback(sxpost):
399 nodetype = (sxpost.get('posttypeid') == '1') and "nodetype" or "answer"
402 node_type = nodetype,
404 added_at = readTime(sxpost['creationdate']),
405 body = sxpost['body'],
406 score = sxpost.get('score', 0),
407 author_id = sxpost.get('deletiondate', None) and 1 or uidmap[sxpost.get('owneruserid', 1)]
412 create_action = orm.Action(
413 action_type = (nodetype == "nodetype") and "ask" or "answer",
414 user_id = post.author_id,
416 action_date = post.added_at
421 if sxpost.get('lasteditoruserid', None):
422 revise_action = orm.Action(
423 action_type = "revise",
424 user_id = uidmap[sxpost.get('lasteditoruserid')],
426 action_date = readTime(sxpost['lasteditdate']),
430 post.last_edited = revise_action
432 if sxpost.get('communityowneddate', None):
433 wikify_action = orm.Action(
434 action_type = "wikify",
437 action_date = readTime(sxpost['communityowneddate'])
441 add_post_state("wiki", post, wikify_action)
443 if sxpost.get('lastactivityuserid', None):
444 post.last_activity_by_id = uidmap[sxpost['lastactivityuserid']]
445 post.last_activity_at = readTime(sxpost['lastactivitydate'])
447 if sxpost.get('posttypeid') == '1': #question
448 post.node_type = "question"
449 post.title = sxpost['title']
451 tagnames = sxpost['tags'].replace(u'ö', '-').replace(u'é', '').replace(u'à ', '')
452 post.tagnames = tagnames
454 post.extra_count = sxpost.get('viewcount', 0)
456 add_tags_to_post(post, tagmap)
459 post.parent_id = sxpost['parentid']
463 all.append(int(post.id))
464 create_and_activate_revision(post)
468 readTable(dump, "Posts", callback)
472 def comment_import(dump, uidmap, posts):
473 currid = IdIncrementer(max(posts))
480 node_type = "comment",
481 added_at = readTime(sxc['creationdate']),
482 author_id = uidmap[sxc.get('userid', 1)],
484 parent_id = sxc.get('postid'),
487 if sxc.get('deletiondate', None):
488 delete_action = orm.Action(
489 action_type = "delete",
490 user_id = uidmap[sxc['deletionuserid']],
491 action_date = readTime(sxc['deletiondate'])
494 oc.author_id = uidmap[sxc['deletionuserid']]
497 delete_action.node = oc
500 add_post_state("deleted", oc, delete_action)
502 oc.author_id = uidmap[sxc.get('userid', 1)]
505 create_action = orm.Action(
506 action_type = "comment",
507 user_id = oc.author_id,
509 action_date = oc.added_at
512 create_and_activate_revision(oc)
517 posts.append(int(oc.id))
518 mapping[int(sxc['id'])] = int(oc.id)
520 readTable(dump, "PostComments", callback)
521 return posts, mapping
524 def add_tags_to_post(post, tagmap):
525 tags = [tag for tag in [tagmap.get(name.strip()) for name in post.tagnames.split(u' ') if name] if tag]
526 post.tagnames = " ".join([t.name for t in tags]).strip()
530 def create_and_activate_revision(post):
531 rev = orm.NodeRevision(
532 author_id = post.author_id,
535 revised_at = post.added_at,
537 summary = 'Initial revision',
538 tagnames = post.tagnames,
543 post.active_revision_id = rev.id
546 def post_vote_import(dump, uidmap, posts):
549 def close_callback(r):
550 close_reasons[r['id']] = r['name']
552 readTable(dump, "CloseReasons", close_callback)
558 user_id=uidmap[sxv['userid']],
559 action_date = readTime(sxv['creationdate']),
562 if not int(sxv['postid']) in posts: return
563 node = orm.Node.objects.get(id=sxv['postid'])
566 if sxv['votetypeid'] == '1':
568 question = orm.Node.objects.get(id=answer.parent_id)
570 action.action_type = "acceptanswer"
575 question.extra_ref_id = answer.id
580 elif sxv['votetypeid'] in ('2', '3'):
581 if not (action.node.id, action.user_id) in user2vote:
582 user2vote.append((action.node.id, action.user_id))
584 action.action_type = (sxv['votetypeid'] == '2') and "voteup" or "votedown"
588 node_id = action.node.id,
589 user_id = action.user_id,
590 voted_at = action.action_date,
591 value = sxv['votetypeid'] == '2' and 1 or -1,
596 action.action_type = "unknown"
599 elif sxv['votetypeid'] in ('4', '12', '13'):
600 action.action_type = "flag"
605 user_id = action.user_id,
606 flagged_at = action.action_date,
613 elif sxv['votetypeid'] == '5':
614 action.action_type = "favorite"
617 elif sxv['votetypeid'] == '6':
618 action.action_type = "close"
619 action.extra = dbsafe_encode(close_reasons[sxv['comment']])
625 elif sxv['votetypeid'] == '7':
626 action.action_type = "unknown"
632 remove_post_state("closed", node)
634 elif sxv['votetypeid'] == '10':
635 action.action_type = "delete"
638 elif sxv['votetypeid'] == '11':
639 action.action_type = "unknown"
642 remove_post_state("deleted", node)
645 action.action_type = "unknown"
648 if sxv.get('targetrepchange', None):
649 rep = orm.ActionRepute(
651 date = action.action_date,
652 user_id = uidmap[sxv['targetuserid']],
653 value = int(sxv['targetrepchange'])
658 if sxv.get('voterrepchange', None):
659 rep = orm.ActionRepute(
661 date = action.action_date,
662 user_id = uidmap[sxv['userid']],
663 value = int(sxv['voterrepchange'])
668 if action.action_type in ("acceptanswer", "delete", "close"):
669 state = {"acceptanswer": "accepted", "delete": "deleted", "close": "closed"}[action.action_type]
670 add_post_state(state, node, action)
672 readTable(dump, "Posts2Votes", callback)
675 def comment_vote_import(dump, uidmap, comments):
680 if sxv['votetypeid'] == "2":
681 comment_id = comments[int(sxv['postcommentid'])]
682 user_id = uidmap[sxv['userid']]
684 if not (comment_id, user_id) in user2vote:
685 user2vote.append((comment_id, user_id))
688 action_type = "voteupcomment",
690 action_date = readTime(sxv['creationdate']),
696 node_id = comment_id,
698 voted_at = action.action_date,
705 if not comment_id in comments2score:
706 comments2score[comment_id] = 1
708 comments2score[comment_id] += 1
710 readTable(dump, "Comments2Votes", callback)
712 for cid, score in comments2score.items():
713 orm.Node.objects.filter(id=cid).update(score=score)
716 def badges_import(dump, uidmap, post_list):
721 sxbadges[int(b['id'])] = b
723 readTable(dump, "Badges", sxcallback)
725 obadges = dict([(b.cls, b) for b in orm.Badge.objects.all()])
726 user_badge_count = {}
730 for id, sxb in sxbadges.items():
731 cls = "".join(sxb['name'].replace('&', 'And').split(' '))
734 sx_to_osqa[id] = obadges[cls]
742 sx_to_osqa[id] = osqab
747 badge = sx_to_osqa[int(sxa['badgeid'])]
749 user_id = uidmap[sxa['userid']]
750 if not user_badge_count.get(user_id, None):
751 user_badge_count[user_id] = 0
754 action_type = "award",
756 action_date = readTime(sxa['date'])
762 user_id = uidmap[sxa['userid']],
764 node_id = post_list[user_badge_count[user_id]],
765 awarded_at = action.action_date,
770 badge.awarded_count += 1
772 user_badge_count[user_id] += 1
774 readTable(dump, "Users2Badges", callback)
776 for badge in obadges.values():
779 def save_setting(k, v):
781 kv = orm.KeyValue.objects.get(key=k)
784 kv = orm.KeyValue(key = k, value = v)
789 def pages_import(dump, currid):
790 currid = IdIncrementer(currid)
799 body = b64decode(sxp['value']),
800 extra = dbsafe_encode({
801 'path': sxp['url'][1:],
802 'mimetype': sxp['contenttype'],
803 'template': (sxp['usemaster'] == "true") and "default" or "none",
806 'sidebar_wrap': True,
807 'sidebar_render': "html",
813 create_and_activate_revision(page)
816 registry[sxp['url'][1:]] = page.id
818 create_action = orm.Action(
819 action_type = "newpage",
820 user_id = page.author_id,
826 if sxp['active'] == "true" and sxp['contenttype'] == "text/html":
827 pub_action = orm.Action(
828 action_type = "publish",
829 user_id = page.author_id,
834 add_post_state("published", page, pub_action)
836 readTable(dump, "FlatPages", callback)
838 save_setting('STATIC_PAGE_REGISTRY', dbsafe_encode(registry))
841 u'theme.html.name': 'APP_TITLE',
842 u'theme.html.footer': 'CUSTOM_FOOTER',
843 u'theme.html.sidebar': 'SIDEBAR_UPPER_TEXT',
844 u'theme.html.sidebar-low': 'SIDEBAR_LOWER_TEXT',
845 u'theme.html.welcome': 'APP_INTRO',
846 u'theme.html.head': 'CUSTOM_HEAD',
847 u'theme.html.header': 'CUSTOM_HEADER',
848 u'theme.css': 'CUSTOM_CSS',
859 def html_decode(html):
860 html = force_unicode(html)
862 for args in html_codes:
863 html = html.replace(*args)
868 def static_import(dump):
872 if unicode(set['name']) in sx2osqa_set_map:
873 save_setting(sx2osqa_set_map[set['name']], dbsafe_encode(html_decode(set['value'])))
875 sx_unknown[set['name']] = html_decode(set['value'])
877 readTable(dump, "ThemeTextResources", callback)
879 save_setting('SXIMPORT_UNKNOWN_SETS', dbsafe_encode(sx_unknown))
881 def disable_triggers():
882 from south.db import db
883 if db.backend_name == "postgres":
884 db.execute_many(PG_DISABLE_TRIGGERS)
885 db.commit_transaction()
886 db.start_transaction()
888 def enable_triggers():
889 from south.db import db
890 if db.backend_name == "postgres":
891 db.start_transaction()
892 db.execute_many(PG_ENABLE_TRIGGERS)
893 db.commit_transaction()
895 def reset_sequences():
896 from south.db import db
897 if db.backend_name == "postgres":
898 db.start_transaction()
899 db.execute_many(PG_SEQUENCE_RESETS)
900 db.commit_transaction()
903 from south.db import db
904 if db.backend_name == "postgres":
905 db.start_transaction()
906 db.execute_many("UPDATE forum_noderevision set id = id WHERE TRUE;")
907 db.commit_transaction()
910 def sximport(dump, options):
913 triggers_disabled = True
915 triggers_disabled = False
917 uidmap = userimport(dump, options)
918 tagmap = tagsimport(dump, uidmap)
921 posts = postimport(dump, uidmap, tagmap)
924 posts, comments = comment_import(dump, uidmap, posts)
927 post_vote_import(dump, uidmap, posts)
930 comment_vote_import(dump, uidmap, comments)
933 badges_import(dump, uidmap, posts)
935 pages_import(dump, max(posts))
939 from south.db import db
940 db.commit_transaction()
944 if triggers_disabled:
949 PG_DISABLE_TRIGGERS = """
950 ALTER table auth_user DISABLE TRIGGER ALL;
951 ALTER table auth_user_groups DISABLE TRIGGER ALL;
952 ALTER table auth_user_user_permissions DISABLE TRIGGER ALL;
953 ALTER table forum_keyvalue DISABLE TRIGGER ALL;
954 ALTER table forum_action DISABLE TRIGGER ALL;
955 ALTER table forum_actionrepute DISABLE TRIGGER ALL;
956 ALTER table forum_subscriptionsettings DISABLE TRIGGER ALL;
957 ALTER table forum_validationhash DISABLE TRIGGER ALL;
958 ALTER table forum_authkeyuserassociation DISABLE TRIGGER ALL;
959 ALTER table forum_tag DISABLE TRIGGER ALL;
960 ALTER table forum_markedtag DISABLE TRIGGER ALL;
961 ALTER table forum_node DISABLE TRIGGER ALL;
962 ALTER table forum_nodestate DISABLE TRIGGER ALL;
963 ALTER table forum_node_tags DISABLE TRIGGER ALL;
964 ALTER table forum_noderevision DISABLE TRIGGER ALL;
965 ALTER table forum_node_tags DISABLE TRIGGER ALL;
966 ALTER table forum_questionsubscription DISABLE TRIGGER ALL;
967 ALTER table forum_vote DISABLE TRIGGER ALL;
968 ALTER table forum_flag DISABLE TRIGGER ALL;
969 ALTER table forum_badge DISABLE TRIGGER ALL;
970 ALTER table forum_award DISABLE TRIGGER ALL;
971 ALTER table forum_openidnonce DISABLE TRIGGER ALL;
972 ALTER table forum_openidassociation DISABLE TRIGGER ALL;
975 PG_ENABLE_TRIGGERS = """
976 ALTER table auth_user ENABLE TRIGGER ALL;
977 ALTER table auth_user_groups ENABLE TRIGGER ALL;
978 ALTER table auth_user_user_permissions ENABLE TRIGGER ALL;
979 ALTER table forum_keyvalue ENABLE TRIGGER ALL;
980 ALTER table forum_action ENABLE TRIGGER ALL;
981 ALTER table forum_actionrepute ENABLE TRIGGER ALL;
982 ALTER table forum_subscriptionsettings ENABLE TRIGGER ALL;
983 ALTER table forum_validationhash ENABLE TRIGGER ALL;
984 ALTER table forum_authkeyuserassociation ENABLE TRIGGER ALL;
985 ALTER table forum_tag ENABLE TRIGGER ALL;
986 ALTER table forum_markedtag ENABLE TRIGGER ALL;
987 ALTER table forum_node ENABLE TRIGGER ALL;
988 ALTER table forum_nodestate ENABLE TRIGGER ALL;
989 ALTER table forum_node_tags ENABLE TRIGGER ALL;
990 ALTER table forum_noderevision ENABLE TRIGGER ALL;
991 ALTER table forum_node_tags ENABLE TRIGGER ALL;
992 ALTER table forum_questionsubscription ENABLE TRIGGER ALL;
993 ALTER table forum_vote ENABLE TRIGGER ALL;
994 ALTER table forum_flag ENABLE TRIGGER ALL;
995 ALTER table forum_badge ENABLE TRIGGER ALL;
996 ALTER table forum_award ENABLE TRIGGER ALL;
997 ALTER table forum_openidnonce ENABLE TRIGGER ALL;
998 ALTER table forum_openidassociation ENABLE TRIGGER ALL;
1001 PG_SEQUENCE_RESETS = """
1002 SELECT setval('"auth_user_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user";
1003 SELECT setval('"auth_user_groups_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_groups";
1004 SELECT setval('"auth_user_user_permissions_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "auth_user_user_permissions";
1005 SELECT setval('"forum_keyvalue_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_keyvalue";
1006 SELECT setval('"forum_action_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_action";
1007 SELECT setval('"forum_actionrepute_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_actionrepute";
1008 SELECT setval('"forum_subscriptionsettings_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_subscriptionsettings";
1009 SELECT setval('"forum_validationhash_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_validationhash";
1010 SELECT setval('"forum_authkeyuserassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_authkeyuserassociation";
1011 SELECT setval('"forum_tag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_tag";
1012 SELECT setval('"forum_markedtag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_markedtag";
1013 SELECT setval('"forum_node_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node";
1014 SELECT setval('"forum_nodestate_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_nodestate";
1015 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
1016 SELECT setval('"forum_noderevision_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_noderevision";
1017 SELECT setval('"forum_node_tags_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_node_tags";
1018 SELECT setval('"forum_questionsubscription_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_questionsubscription";
1019 SELECT setval('"forum_vote_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_vote";
1020 SELECT setval('"forum_flag_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_flag";
1021 SELECT setval('"forum_badge_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_badge";
1022 SELECT setval('"forum_award_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_award";
1023 SELECT setval('"forum_openidnonce_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidnonce";
1024 SELECT setval('"forum_openidassociation_id_seq"', coalesce(max("id"), 1) + 2, max("id") IS NOT null) FROM "forum_openidassociation";