mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 04:38:47 +08:00
FIX: base import script was not updating first_post_created_at column
FEATURE: new rake task to update first_post_created_at column The not-equal operator (`<>`) in PostgreSQL does not compare values with NULL. We should instead use `IS DISTINCT FROM` when comparing values with NULL.
This commit is contained in:
@ -497,3 +497,22 @@ task 'import:file', [:file_name] => [:environment] do |_, args|
|
||||
ImportExport.import(args[:file_name])
|
||||
puts "", "Done", ""
|
||||
end
|
||||
|
||||
desc "Update first_post_created_at column in user_stats table"
|
||||
task "import:update_first_post_created_at" => :environment do
|
||||
puts "", "Updating first_post_created_at..."
|
||||
|
||||
DB.exec <<~SQL
|
||||
WITH sub AS (
|
||||
SELECT user_id, MIN(posts.created_at) AS first_post_created_at
|
||||
FROM posts
|
||||
GROUP BY user_id
|
||||
)
|
||||
UPDATE user_stats
|
||||
SET first_post_created_at = sub.first_post_created_at
|
||||
FROM user_stats u1
|
||||
JOIN sub ON sub.user_id = u1.user_id
|
||||
WHERE u1.user_id = user_stats.user_id
|
||||
AND user_stats.first_post_created_at IS DISTINCT FROM sub.first_post_created_at
|
||||
SQL
|
||||
end
|
||||
|
Reference in New Issue
Block a user