I attempted to upgrade my Discourse instance, however due to a handful of issues, it seems to have failed in a partially applied state. When running ./launcher rebuild app, I get the following error message, which indicates to me a migration that was already (partially) applied:
I, [2022-03-24T21:13:16.043071 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::DuplicateColumn: ERROR: column "bookmarkable_id" of relation "bookmarks" already exists
Any guidance on if there’s a way to recover from this (or if I need to bite the bullet and do a fresh install) would be appreciated. Thanks!
I had a similar problem, but it seems unlikely my solution will help you.
You don’t have SKIP_POST_DEPLOYMENT_MIGRATIONS set in your app.yml do you? If so, you need to migrate the database with it set to zero and then rebuild, but I don’t think that’s your issue.
That’s what I thought. So there might be an actual problem that has to do with being able to migrate from one particular point to the current one. But that’s not supposed to happen.
I emptied all the tables that were giving me errors (one by one, in the end there were 7), until I could rebuild app without any error.
In your case it seems that the problem is a column:
PG::DuplicateColumn: ERROR: column "bookmarkable_id" of relation "bookmarks" already exists
Maybe you should look for which table it belongs to, to be able to empty it, or you can simply drop that column.
I believe that the problem is in that when migrating partially, those tables are already created, hence it cannot create them again and it returns an error. Perhaps a conditional could be added to this process, so that it does not give errors? (I am not an expert) @pfaffman
I think that you want to remove the bookmarkable_id column from the bookmarks table. So after you get into the container and into postgres like this:
cd /var/discourse
./launcher enter app
su - postgres
psql
Then you would
ALTER TABLE bookmarks
DROP COLUMN bookmarkable_id
DROP COLUMN bookmarkable_type;
But taking a database-only backup wouldn’t be a bad idea of the forum is running. If not, you can do a backup with discourse backup after the enter app line above.
This seems like a likely solution. You should be able to upgrade to this one and maybe then you can get to the current version? Something like that makes sense to me.