|
70 | 70 | CREATED_BY=my-migrator node src/index.js member-profiles |
71 | 71 | ``` |
72 | 72 |
|
| 73 | + ## 🕒 Incremental Migration with Start Date |
| 74 | + |
| 75 | + The `--start-date` parameter unlocks incremental migrations by filtering records on their creation and update timestamps. Run a full import in advance, then rerun with a start date to pick up only the recent changes—keeping the final cut-over fast and predictable. |
| 76 | + |
| 77 | + ### 🛠️ Usage Examples |
| 78 | + |
| 79 | + ```bash |
| 80 | + node src/index.js resources ./data/challenge-api.resources.json --start-date=2024-01-15 |
| 81 | + node src/index.js resource-roles --start-date=2024-03-01 |
| 82 | + node src/migrateAll.js --start-date=2024-02-20 |
| 83 | + ``` |
| 84 | + |
| 85 | + ### 🔍 Filtering Behavior |
| 86 | + |
| 87 | + - Records are imported when `created`/`createdAt` **or** `updatedAt` is on or after the provided start date |
| 88 | + - Records missing **both** date fields are skipped when a start date is supplied |
| 89 | + - Records with both date fields present but older than the start date are skipped |
| 90 | + - Dates must use the ISO `YYYY-MM-DD` format |
| 91 | + - Without `--start-date`, all records are imported (default behavior) |
| 92 | + |
| 93 | + ### 🔄 Incremental Migration Workflow |
| 94 | + |
| 95 | + 1. **Bulk load ahead of time (Jan 1)** — seed the database without a start date: |
| 96 | + |
| 97 | + ```bash |
| 98 | + node src/migrateAll.js |
| 99 | + ``` |
| 100 | + |
| 101 | + 2. **Wait until the cut-over window (Mar 15)** — allow upstream systems to keep producing data as usual. |
| 102 | + |
| 103 | + 3. **Refresh with recent updates** — bring the target in sync by importing only records touched since Jan 1: |
| 104 | + |
| 105 | + ```bash |
| 106 | + node src/migrateAll.js --start-date=2024-01-01 |
| 107 | + ``` |
| 108 | + |
| 109 | + This staggered approach turns a multi-hour bulk migration into a quick incremental catch-up that typically completes in minutes. |
| 110 | + |
| 111 | + ### 📌 Model Support |
| 112 | + |
| 113 | + - `resources`: filters on `created` and `updatedAt` |
| 114 | + - `resource-roles`: filters on `createdAt` and `updatedAt` |
| 115 | + - `resource-role-phase-dependencies`: filters on `createdAt` and `updatedAt` |
| 116 | + |
73 | 117 | ## 🧩 Available Migration Steps |
74 | 118 |
|
75 | | - | Step | Auto Strategy | Description | |
76 | | - |-------------------------------------|---------------|---------------------------------------------------------------------------------------------------| |
77 | | - | `member-profiles` | ✅ | Auto strategy: uses `stream-json` (batch) for files larger than 3MB, and `loadJSON` (simple) otherwise | |
78 | | - | `member-stats` | ✅ | Auto strategy: uses `stream-json` (batch) for files larger than 3MB, and `loadJSON` (simple) otherwise | |
79 | | - | `resource-roles` | ❌ | Simple in-memory migration using `loadJSON`, not expected to be large | |
80 | | - | `resource-role-phase-dependencies` | ❌ | Simple in-memory migration using `loadJSON`, not expected to be large | |
81 | | - | `resources` | ✅ | Auto strategy for NDJSON files: uses `readline` + batch for files > 3 MB, otherwise simple line-by-line | |
| 119 | + | Step | Auto Strategy | Start Date Support | Description | |
| 120 | + |-------------------------------------|---------------|--------------------|---------------------------------------------------------------------------------------------------| |
| 121 | + | `member-profiles` | ✅ | ❌ | Auto strategy: uses `stream-json` (batch) for files larger than 3MB, and `loadJSON` (simple) otherwise | |
| 122 | + | `member-stats` | ✅ | ❌ | Auto strategy: uses `stream-json` (batch) for files larger than 3MB, and `loadJSON` (simple) otherwise | |
| 123 | + | `resource-roles` | ❌ | ✅ | Simple in-memory migration using `loadJSON`, not expected to be large | |
| 124 | + | `resource-role-phase-dependencies` | ❌ | ✅ | Simple in-memory migration using `loadJSON`, not expected to be large | |
| 125 | + | `resources` | ✅ | ✅ | Auto strategy for NDJSON files: uses `readline` + batch for files > 3 MB, otherwise simple line-by-line | |
82 | 126 |
|
83 | 127 | > ⚙️ **Why Auto Strategy?** |
84 | 128 | > |
@@ -110,9 +154,10 @@ You can now run all migration steps sequentially using the following script: |
110 | 154 |
|
111 | 155 | ```bash |
112 | 156 | node src/migrateAll.js |
| 157 | +node src/migrateAll.js --start-date=2024-01-15 |
113 | 158 | ``` |
114 | 159 |
|
115 | | -This script will automatically execute each step in order (`resource-roles`, `resource-role-phase-dependencies`, `resources`), logging progress and duration for each. Ideal for full dataset migration in one command. |
| 160 | +This script will automatically execute each step in order (`resource-roles`, `resource-role-phase-dependencies`, `resources`), logging progress and duration for each. When provided, the start date is passed to every step, so only records touched on or after the target date are processed—ideal for full imports followed by a quick incremental catch-up in one command. |
116 | 161 |
|
117 | 162 | ## 📒 Error Logs |
118 | 163 | All failed migrations are logged under the `logs/` folder by model: |
@@ -224,5 +269,3 @@ node src/validation/validateMemberProfiles.js > logs/memberprofile_validation.lo |
224 | 269 |
|
225 | 270 | --- |
226 | 271 |
|
227 | | -
|
228 | | -
|
|
0 commit comments