Skip to content

Instantly share code, notes, and snippets.

@andialbrecht
Last active January 4, 2016 16:08
Show Gist options
  • Save andialbrecht/8644979 to your computer and use it in GitHub Desktop.
Save andialbrecht/8644979 to your computer and use it in GitHub Desktop.
# Migrate from sentry-comments to build in notes.
#
# See also https://github.com/andialbrecht/sentry-comments/issues/11
# Especially when you're upgrading from Sentry 6.3.
#
# To run this script:
# sentry --config=your.conf.py shell
# >>> import migratecomments.py
# >>> migratecomments.migrate()
#
# After migration you can safely remove the sentry_comments plugin
# from your setup.
from django.contrib.auth import get_user_model
from sentry_comments.models import GroupComments
from sentry.models import Activity
from sentry.models import Group
User = get_user_model()
def migrate():
for gc in GroupComments.objects.all():
print('Migrating %d' % gc.pk)
try:
group = gc.group
except Group.DoesNotExist:
print('--> skipping. Group does not exist anymore.')
continue
user = User.objects.get(pk=gc.author.pk)
Activity.objects.create(
group=gc.group, event=None, project=gc.group.project,
type=Activity.NOTE, user=user,
data={'text': gc.message},
datetime=gc.created
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment