axfelix
(Alex Garnett)
May 3, 2022, 3:34pm
1
Had an automatic rebuild fail, looks like variations on this issue:
2022-05-03 15:30:54.370 UTC [1262] discourse@discourse LOG: duration: 1707.909 ms statement: INSERT INTO post_hotlinked_media (post_id, url, status, upload_id, created_at, updated_at)
SELECT
post_id,
obj.key AS url,
'downloaded',
obj.value::bigint AS upload_id,
pcf.created_at,
pcf.updated_at
FROM post_custom_fields pcf
JOIN json_each_text(pcf.value::json) obj ON true
JOIN uploads ON obj.value::bigint = uploads.id
WHERE name='downloaded_images'
ERROR: duplicate key value violates unique constraint "index_post_hotlinked_media_on_post_id_and_url_md5"
Had rebuilt less than a month ago with no errors so whatever introduced this seems to have been recent.
4 Likes
axfelix
(Alex Garnett)
May 3, 2022, 4:09pm
3
seems to be something to do with this recent commit?
# frozen_string_literal: true
class CreatePostHotlinkedMedia < ActiveRecord::Migration[6.1]
def change
reversible do |dir|
dir.up do
execute <<~SQL
CREATE TYPE hotlinked_media_status AS ENUM('downloaded', 'too_large', 'download_failed', 'upload_create_failed')
SQL
end
dir.down do
execute <<~SQL
DROP TYPE hotlinked_media_status
SQL
end
end
create_table :post_hotlinked_media do |t|
t.bigint :post_id, null: false
t.string :url, null: false
This file has been truncated. show original
@david
2 Likes
david
(David Taylor)
May 3, 2022, 4:15pm
4
Yep that’s it. I have a fix in the pipeline, should be merged in the next few minutes. Thanks for reporting @axfelix
discourse:main
← discourse:hotlinked-conflict
opened 03:54PM - 03 May 22 UTC
In the old custom_field-based system, it was possible for a url to be both 'down… loaded' and 'broken'. The new table enforces uniqueness, so we need to drop invalid data.
9 Likes
axfelix
(Alex Garnett)
May 3, 2022, 4:39pm
5
Thanks, that was fast!
Do I need to do anything special to pull this down? I’m still getting Caused by: ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_post_hotlinked_media_on_post_id_and_url_md5"
when running a launcher rebuild, even after doing a Docker prune.
david
(David Taylor)
May 3, 2022, 4:48pm
6
The fix just hit tests-passed a few seconds ago. If you rebuild now, it should work much better. Let us know how it goes.
5 Likes
david
(David Taylor)
May 3, 2022, 6:07pm
7
We found one more place which can cause this error. So if the first fix didn’t help, this one should
committed 05:51PM - 03 May 22 UTC
custom_field data on some sites has duplicate values for a given url key in the … JSON value. This is invalid, so we should drop the extra data.
(now live in tests-passed)
4 Likes
pfaffman
(Jay Pfaffman)
May 3, 2022, 7:31pm
8
On my development instance it does successfully migrate the database, but if I restore a backup from 2022-04-27-153103-v20220407195246.tar.gz
it fails:
[361/9020]
Migrating the database... EXCEPTION: /home/pfaffman/src/discourse-repos/discourse/lib/discourse.rb:126:in `exec': Failed to migrat
e database.
Ignoring /home/pfaffman/src/discourse-repos/discourse/db/schema_cache.yml because it has expired. The cu
rrent schema version is 20220407195246, but the one in the schema cache file is 20220428094027.
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
followed by some more of that with some of these:
ActiveRecord::StatementInvalid: PG::DuplicateObject: ERROR: type "hotlinked_media_status" already exist
1 Like
axfelix
(Alex Garnett)
May 3, 2022, 9:22pm
9
Just chiming in to say that the first fix worked for us after it passed tests!
2 Likes
david
(David Taylor)
May 3, 2022, 9:30pm
10
Alex Garnett:
the first fix worked
Great, thanks for confirming!
I opened a PR with a fix for that one:
discourse:main
← discourse:fix-restore-enums
opened 09:27PM - 03 May 22 UTC
c1db9687 introduced an postgres enum type. Our database restore logic did not ha… ndle custom types correctly, and would therefore raise a 'type already exists' error when restoring any backup.
This commit adds restore handling for enums, mirroring the similar logic for tables and views.
---
(This code is not tested by rspec, but it is tested by a regular internal job at CDCK, which correctly picked up on this issue)
4 Likes
pfaffman
(Jay Pfaffman)
May 4, 2022, 2:05pm
11
Finished!
[SUCCESS]
Restore done.
Thanks!
2 Likes