opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
79 stars 58 forks source link

feat: reindex elasticsearch after running migrations #7253

Closed naftis closed 2 days ago

naftis commented 2 days ago

7240

New dependencies introduced

rikukissa commented 2 days ago

Is it OK to install tsx instead of ts-node ? I got tired of esm-module issues with ts-node and tsx worked out of the box.

I think it is. Only thing it affects really is the sizes of our docker images. We need to find a solution that works for all packages

naftis commented 2 days ago

I tried again without tsx:

  1. first you get TypeError: Unknown file extension ".ts" for /root/Projects/opencrvs-core/packages/migration/src/reindex-search.ts

  2. with our ts-node version, solution is removing "type": "module" from the package.json. Then I got:

    @opencrvs/migration: ERROR: Unexpected token 'export' /root/Projects/opencrvs-core/packages/migration/build/dist/src/migrate-mongo-config-performance.js:25
    @opencrvs/migration: export default config;
    @opencrvs/migration: ^^^^^^
    @opencrvs/migration: SyntaxError: Unexpected token 'export'
  3. Installed latest ts-node. Added "type": "module" back. Migrations now work.

    $ node --loader ts-node/esm src/reindex-search.ts
    (node:21468) ExperimentalWarning: `--experimental-loader` may be removed in the future; instead use `register()`:
    --import 'data:text/javascript,import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("ts-node/esm", pathToFileURL("./"));'
    (Use `node --trace-warnings ...` to show where the warning was created)
    Reindexing search...
    ...done reindexing search with job id 52bd21fa-1acd-40b3-a117-29f30ae7ded8

    The deprecation warning here doesn't offer a pretty solution to get rid of it, but at least it works. It doesn't reduce the Docker image size though as our other ts-node versions are older.

  4. Reinstall tsx

    $ tsx src/reindex-search.ts
    Reindexing search...
    ...done reindexing search with job id 1cf41ebb-84dc-42bc-ac66-66bac01b5655
    Done in 1.38s.
naftis commented 2 days ago

I tested this with Mac. Not getting the error which leads us to use the ipv4-first fix ✅