Discourse restore fails with relation already exists error

Through a series of unfortunate events, I seem to be unable to restore from my latest full backup.

Full story to come, but at the moment the problem I’m having is during a backup restore it throws this error:

Migrating the database…
EXCEPTION: rake db:migrate
Failed to migrate database.
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)

PG::DuplicateTable: ERROR:  relation “gamification_leaderboard_scores” already exists

This seems to be a problem with my plugins, but I’d appreciate some help deciphering the logs for a solution to allow the restore to work.

Anyway, this is what happened.

Earlier today I performed a Discourse update to bring it up to 2026.5.0-latest b0873d3ecd, which introduced some breaking change causing my primary theme to stop working. I should have checked compatibility before updating.

In a panic, I thought I would be able to restore from my last backup to revert back to a Discourse version compatible with the theme. Before the restore, I did take a full backup thinking that if anything went wrong I want as many restore points as possible.

Well, something went wrong during this first restore and Discourse came back up missing the last 15 days of content. Looking into it further, I found a topic on Meta that suggested to rename the backup file from 2026-04-28-033449-v20260420014648.sql.gz to 2026-04-28-033449-v20260407093145.sql.gz I’m not sure why this worked, but it at least got me back up to yesterday’s backup.

I still need to restore from my last full backup taken this morning, which is the one giving the error shown at the top.

This has happened with some other plugins. Somehow there’s a migration that created the table but the migration system doesn’t recognize that it ran.

I don’t know how to do it well enough to explain it to anyone. In broad strokes, You’d stop the restore before it migrates (there’s a switch for the restore command to do that) and drop the table, I think. If that makes sense, or almost makes sense you might be able to figure it out with help from https://ask.discourse.com/

If that doesn’t help and you’re in a hurry and have a budget, you can ask in Marketplace or email me. If you’re not in a hurry, or don’t have a budget, there’s a chance that someone can explain what to do in a way that you’d understand.