FIX: prevents duplicate error on instragam migration (#7178)
Previous instagram records didn’t have unique index, as a result it's seems like in some cases we have duplicate ids, which is causing issues with the associated_accounts which does have unique index. It's sorted by `updated_at DESC` on the thought that the most recent one is more likely to be the one we want to keep.
This commit is contained in:
parent
a6a52d1523
commit
93490fbfaf
|
@ -9,15 +9,19 @@ class MigrateInstagramUserInfo < ActiveRecord::Migration[5.2]
|
||||||
last_used,
|
last_used,
|
||||||
created_at,
|
created_at,
|
||||||
updated_at
|
updated_at
|
||||||
) SELECT
|
)
|
||||||
'instagram',
|
SELECT
|
||||||
instagram_user_id,
|
'instagram',
|
||||||
user_id,
|
instagram_user_id,
|
||||||
json_build_object('nickname', screen_name),
|
user_id,
|
||||||
updated_at,
|
json_build_object('nickname', screen_name),
|
||||||
created_at,
|
updated_at,
|
||||||
updated_at
|
created_at,
|
||||||
FROM instagram_user_infos
|
updated_at
|
||||||
|
FROM instagram_user_infos
|
||||||
|
ORDER BY updated_at DESC
|
||||||
|
ON CONFLICT (provider_name, provider_uid)
|
||||||
|
DO NOTHING
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue