I’m doing an upgrade on a site and it’s failing with PG::NotNullViolation: ERROR: column "private_message" contains null values. I can’t find where the private_message column exists. There are no non-official plugins.
oh. Wait. Here’s this:
(See full trace by running task with --trace)
I, [2020-08-18T18:19:13.253667 #1] INFO -- : == 20200818084329 UpdatePrivateMessageOnPostSearchData: migrating =============
-- execute("DELETE FROM post_search_data\nWHERE post_id IN (\n SELECT posts.id\n FROM posts\n LEFT JOIN topics ON topics.id = posts.topic_id\n WHERE topics.id IS NULL\n)\n")
-> 21.9072s
-- execute("DELETE FROM post_search_data\nWHERE post_id IN (\n SELECT post_search_data.post_id\n FROM post_search_data\n LEFT JOIN posts ON posts.id = post_search_data.post_id\n WHERE posts.id IS NULL\n)\n")
-> 47.2663s
-- execute("UPDATE post_search_data\nSET private_message = true\nFROM posts\nINNER JOIN topics ON topics.id = posts.topic_id AND topics.archetype = 'private_message'\nWHERE posts.id = post_search_data.post_id\n")
-> 107.2137s
-- execute("UPDATE post_search_data\nSET private_message = false\nFROM posts\nINNER JOIN topics ON topics.id = posts.topic_id AND topics.archetype <> 'private_message'\nWHERE posts.id = post_search_data.post_id\n")
-> 834.3738s
-- change_column_null(:post_search_data, :private_message, false)
Hmm this is odd… can you run the following queries for me in the Rails console and provide me with the results?
DB.query_single(<<~SQL)
SELECT COUNT(*) FROM post_search_data
SQL
DB.query_single(<<~SQL)
SELECT COUNT(*)
FROM post_search_data
LEFT JOIN posts ON posts.id = post_search_data.post_id
LEFT JOIN topics ON topics.id = posts.topic_id
WHERE topics.id IS NULL
SQL
DB.query_single(<<~SQL)
SELECT COUNT(*)
FROM post_search_data
LEFT JOIN posts ON posts.id = post_search_data.post_id
WHERE posts.id IS NULL
SQL
DB.query_single(<<~SQL)
SELECT COUNT(*)
FROM post_search_data
INNER JOIN posts ON posts.id = post_search_data.post_id
INNER JOIN topics ON topics.id = posts.topic_id
SQL
Sorry, Alan. Yes this did get resolved. Thanks for your help on this one!
For anyone else with this issue, if you do a plain-old ./launcher rebuild app you shouldn’t have any trouble except that your site will potentially be down for a long time while the bootstrap part of the rebuild migrates the database. This is the safe and easy option, and unless you’re a 2-container install, what you’ll do anyway.
I didn’t want to have the site down for the whole bootstrap. For this large forum (5M posts and ~50K pageviews/day?) my solution (that I figured out only with Alan’s help) was to bootstrap with post upgrade migrations off (migrations took virtually no time), crank up the new container and do the post upgrade migrations (migrations took 20-40 minutes–I wasn’t really paying attention to the clock).
If anyone else cares, I’ve since learned that doing the upgrade with docker_manager will do this much more smoothly, so that’s what I’d recommend if anyone else has a big forum and issues with bootstrapping.