Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Wagtail id sequences are out of whack when restoring a Heroku Postgres instance from a rollback #392

Open
hancush opened this issue Nov 12, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@hancush
Copy link
Member

hancush commented Nov 12, 2024

Description

We had to restore the NOAH database from a rollback after some data loss. When we did this, the id sequences for pages, revisions, and subscriptions (from Wagtail) were out of whack. This created integrity errors like this when trying to access the CMS and manage pages programmatically:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "wagtailcore_pagerevision_pkey"
DETAIL:  Key (id)=(36) already exists.

python manage.py fixtree, with and without the --full flag, did not resolve the issue. I wound up having to connect to the database and reset the sequences by hand:

# in your terminal
heroku pg:psql -a tpc-ihs-noah-map
# once connected to postgres
select setval(pg_get_serial_sequence('wagtailcore_page', 'id'), coalesce(MAX(id), 1)) from wagtailcore_page;
select setval(pg_get_serial_sequence('wagtailcore_revision', 'id'), coalesce(MAX(id), 1)) from wagtailcore_revision;
select setval(pg_get_serial_sequence('wagtailcore_pagesubscription', 'id'), coalesce(MAX(id), 1)) from wagtailcore_pagesubscription;

Wanted to log this somewhere for posterity.

@hancush hancush added the bug Something isn't working label Nov 12, 2024
@hancush
Copy link
Member Author

hancush commented Nov 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant