cofacts / rumors-api

GraphQL API server for clients like rumors-site and rumors-line-bot
https://api.cofacts.tw
MIT License
109 stars 26 forks source link

Add status to article #293

Closed MrOrz closed 1 year ago

MrOrz commented 1 year ago
coveralls commented 1 year ago

Coverage Status

Coverage increased (+0.03%) to 87.833% when pulling dad137bd014c970973c99a20fbcb7251f971a1d6 on anti-seo-spam into 4f97b9f523fda6e90d9b8e4bb92630f838895980 on master.

MrOrz commented 1 year ago

Migration process

1. Update schema and reindex

npm run reload -- articles

Staging running result

docker@answerfamily:~/rumors-db$ date
Wed Dec  7 10:17:44 UTC 2022
docker@answerfamily:~/rumors-db$ npm run reload -- articles

> rumors-db@1.0.2 reload
> babel-node db/reloadSchema.js "articles"

Source:  articles_v1_2_0
Target:  articles_v1_3_0
Reindexed from articles_v1_2_0 to articles_v1_3_0 in 64 seconds.
Setup articles_v1_3_0 -> articles alias and remove articles_v1_2_0.
docker@answerfamily:~/rumors-db$ date
Wed Dec  7 10:19:02 UTC 2022

2. Migrate articles.status

Migration script: Add a status="NORMAL" to those articles which don't have a status.

curl -XPOST "http://$DB_URL/articles/_update_by_query" -H 'Content-Type: application/json' -d'
{
   "script": {
    "source": "ctx._source[\"status\"]=\"NORMAL\";",
    "lang": "painless"
  },
  "query": {
    "bool": {
          "must_not": {
              "exists": {
                  "field": "status"
              }
          }
      }
  }
}'

Before migration, all existing articles without status are not listed in UI and chatbot.

Result on staging (82sec)

{"took":82330,"timed_out":false,"total":96283,"updated":96283,"deleted":0,"batches":97,"version_conflicts":0,"noops":0,"retries":{"bulk":0,"search":0},"throttled_millis":0,"requests_per_second":-1.0,"throttled_until_millis":0,"failures":[]}

3. Update API code

docker-compose pull & docker-compose up -d

4. Migrate again

Run the migration again to migrate new articles created between 2 and 3.

MrOrz commented 1 year ago

DB migrated successfully.

圖片