Yuki Takei 2a7fb1b83f remove all of rest eslint suppressions 2 months ago
..
src 2a7fb1b83f remove all of rest eslint suppressions 2 months ago
README.md 114944ee67 https://github.com/weseek/growi -> https://github.com/growilabs/growi 6 months ago
tsconfig.json d8e3d33a28 manage bin directory with biome 2 months ago

README.md

Migration of page body

Warning Migration in this way is applied only to the latest revision. Past revisions are not applied.

Usage

git clone https://github.com/growilabs/growi
cd growi/bin/data-migrations

NETWORK=growi_devcontainer_default
MONGO_URI=mongodb://growi-devcontainer_mongo-1/growi

docker run --rm \
  --network $NETWORK \
  -v "$(pwd)"/src:/opt \
  -w /opt \
  -e MIGRATION_MODULE=v60x \
  mongo:8.0 \
  /bin/mongosh $MONGO_URI index.js

Note This script uses MongoDB 8.0 Docker image, but mongosh has backward compatibility and can connect to any MongoDB server version 4.2 or greater. See MongoDB Shell documentation for details.

Variables

Variable Description Default
NETWORK Network in docker compose of MongoDB server -
MONGO_URI URI that can connect to MongoDB -

Environment variables

Required

Variable Description Default
MIGRATION_MODULE Specify migration module -

The value of MIGRATION_MODULE is one of the following.

  • v60x/drawio: Migration for Draw.io notation only( reference)
  • v60x/plantuml: Migration for PlantUML notation only( reference)
  • v60x/tsv: Migration for table notation by TSV only( reference)
  • v60x/csv: Migration for table notation by CSV only( reference)
  • v60x/bracketlink: Migration for only page links within GROWI( reference)
  • v60x or v60x/index: Migration for all notations in v6.0.x series
  • v61x/mdcont: Migration for mdcont notation only(reference)
  • v61x or v61x/index: Migration for all notations in v6.1.x series
  • v70x/bootstrap5: Migration for Bootstrap4 to Bootstrap5
  • v70x or v70x/index: Migration for all notations in v7.0.x series
  • custom: You can define your own processors and apply them to revision (see "Advanced" below for details)

Optional

Variable Description Default
BATCH_SIZE Number of revisions to be processed at one time(revision) 100
BATCH_INTERVAL Interval after batch processing(ms) 3000

※The BATCH_INTERVAL is for server load control. If you don't mind the load of the MongoDB, there is no problem to reduce it.

Advanced

By creating a function in growi/bin/data-migrations/src/migrations/custom.js that replaces a specific regular expression, you can replace all specific strings in the latest revisions for all pages.

The following function replaces the string foo with the string bar.

module.exports = [
  (body) => {
  var fooRegExp = /foo/g; // foo regex
  return body.replace(fooRegExp, 'bar'); // replace to bar
  },
];

By passing custom in the environment variable MIGRATION_MODULE and executing it, you can apply the custom.js to all the latest revisions.

git clone https://github.com/growilabs/growi
cd growi/bin/data-migrations

NETWORK=growi_devcontainer_default \
MONGO_URI=mongodb://growi-devcontainer_mongo-1/growi
docker run --rm \
  --network $NETWORK \
  -v "$(pwd)"/src:/opt \
  -w /opt \
  -e MIGRATION_MODULE=custom \
  mongo:8.0 \
  /bin/mongosh $MONGO_URI index.js