Shun Miyazawa 1 год назад
Родитель
Сommit
644ca4d52d
2 измененных файлов с 21 добавлено и 3 удалено
  1. 5 3
      bin/data-migrations/src/index.js
  2. 16 0
      bin/data-migrations/src/types.d.ts

+ 5 - 3
bin/data-migrations/src/index.js

@@ -5,13 +5,14 @@
 /**
 /**
  * @typedef {import('./types').MigrationModule} MigrationModule
  * @typedef {import('./types').MigrationModule} MigrationModule
  * @typedef {import('./types').ReplaceLatestRevisions} ReplaceLatestRevisions
  * @typedef {import('./types').ReplaceLatestRevisions} ReplaceLatestRevisions
+ * @typedef {import('./types').Operatioins } Operations
  */
  */
 
 
 var pagesCollection = db.getCollection('pages');
 var pagesCollection = db.getCollection('pages');
 var revisionsCollection = db.getCollection('revisions');
 var revisionsCollection = db.getCollection('revisions');
 
 
-var batchSize = process.env.BATCH_SIZE ?? 100; // default 100 revisions in 1 bulkwrite
-var batchSizeInterval = process.env.BATCH_INTERVAL ?? 3000; // default 3 sec
+var batchSize = Number(process.env.BATCH_SIZE ?? 100); // default 100 revisions in 1 bulkwrite
+var batchSizeInterval = Number(process.env.BATCH_INTERVAL ?? 3000); // default 3 sec
 
 
 var migrationModule = process.env.MIGRATION_MODULE;
 var migrationModule = process.env.MIGRATION_MODULE;
 
 
@@ -31,8 +32,9 @@ function replaceLatestRevisions(body, migrationModules) {
   return replacedBody;
   return replacedBody;
 }
 }
 
 
+/** @type {Operations} */
 var operations = [];
 var operations = [];
-pagesCollection.find({}).forEach((doc) => {
+pagesCollection.find({}).forEach((/** @type {any} */ doc) => {
   if (doc.revision) {
   if (doc.revision) {
     try {
     try {
       var revision = revisionsCollection.findOne({ _id: doc.revision });
       var revision = revisionsCollection.findOne({ _id: doc.revision });

+ 16 - 0
bin/data-migrations/src/types.d.ts

@@ -1,2 +1,18 @@
 export type MigrationModule = (body: string) => string;
 export type MigrationModule = (body: string) => string;
 export type ReplaceLatestRevisions = (body: string, migrationModules: MigrationModule[]) => string;
 export type ReplaceLatestRevisions = (body: string, migrationModules: MigrationModule[]) => string;
+
+export type Operatioins = Array<
+  {
+    updateOne: {
+      filter: { _id: string }
+      update: { $set: { body: string }}
+    }
+  }
+>
+
+export declare global {
+  const db;
+  const sleep;
+
+  function print(arg: string): void;
+}