Skip to content

Commit

Permalink
fix(db): correct article read record created during deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
devformatters authored and Zeck Li committed Sep 4, 2020
1 parent a1f5e98 commit ee3167a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions db/migrations/20200904062843_correct_read_time_pt_2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Fix read records that created in the middle of deployment
* of fixing wrong read_time in article_read_count.
*/

exports.up = async (knex) => {
await knex.raw(`
UPDATE
article_read_count
SET
read_time = ROUND(read_time::NUMERIC/1000)
FROM (
SELECT
base.*
FROM (
SELECT
id,
updated_at,
read_time / COALESCE(NULLIF(timed_count, 0), 1) AS avg_time
FROM
article_read_count
) AS base
WHERE
base.updated_at >= '2020-07-31 12:30:00'
AND base.avg_time > 1800
) AS source
WHERE article_read_count.id = source.id
`)
}

exports.down = async (knex) => {}

0 comments on commit ee3167a

Please sign in to comment.