Skip to content

Commit

Permalink
Reset sequences after initial project create as ID might be invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Aug 27, 2013
1 parent b206222 commit f747166
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sentry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
UserOptionManager, TagKeyManager, TeamManager, UserManager)
from sentry.signals import buffer_incr_complete, regression_signal
from sentry.utils.cache import memoize
from sentry.utils.db import has_trending
from sentry.utils.db import has_trending, reset_sequences
from sentry.utils.http import absolute_uri
from sentry.utils.models import (
Model, GzippedDictField, BoundedIntegerField, BoundedPositiveIntegerField,
Expand Down Expand Up @@ -1217,6 +1217,8 @@ def create_default_project(created_models, verbosity=2, **kwargs):
owner=user,
)

reset_sequences('sentry')

if verbosity > 0:
print 'Created internal Sentry project (slug=%s, id=%s)' % (project.slug, project.id)

Expand Down
17 changes: 17 additions & 0 deletions src/sentry/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,20 @@ def attach_foreignkey(objects, field, related=[], database=None):

def table_exists(name, using=DEFAULT_DB_ALIAS):
return name in connections[using].introspection.table_names()


def reset_sequences(app='sentry'):
import os

os.environ['DJANGO_COLORS'] = 'nocolor'

from django.core.management import call_command
from django.db import connection
from StringIO import StringIO

commands = StringIO()
cursor = connection.cursor()

call_command('sqlsequencereset', app, stdout=commands)

cursor.execute(commands.getvalue())

0 comments on commit f747166

Please sign in to comment.