-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(db): correct article read record created during deployment
- Loading branch information
1 parent
a1f5e98
commit ee3167a
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => {} |