You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,6 +123,8 @@ how to deploy a test version of the schema documentation. This requires some bas
123
123
- Anyone who is involved in writing migrations or otherwise checking data from MongoDB against the schema should be comfortable running make `make-rdf`.
124
124
- The main [Makefile](Makefile) should in general not be edited. Instead, edits should be made to [project.Makefile](project.Makefile) (advanced contributors only)
125
125
126
+
> Advanced testing instructions for migrators can be found [here](nmdc_schema/migrators/README.md).
127
+
126
128
### Recording Decisions
127
129
128
130
- Use the [NMDC ADR Log](https://github.com/microbiomedata/NMDC_documentation/tree/main/decisions)
*[Summary of steps to test a migrator with a local copy of the MongoDB database](#summary-of-steps-to-test-a-migrator-with-a-local-copy-of-the-mongodb-database)
20
+
*[Running a migrator with Docker step-by-step](#running-a-migrator-with-docker-step-by-step)
21
+
*[Summary of steps to test a migrator with the API](#summary-of-steps-to-test-a-migrator-with-the-api)
22
+
*[Running a migrator with project.Makefile step-by-step](#running-a-migrator-with-projectmakefile-step-by-step)
23
+
24
+
12
25
## Contents
13
26
14
27
This directory contains the following things:
@@ -241,14 +254,16 @@ To add MongoDB transaction support with commit/rollback functionality to your mi
241
254
242
255
## Testing the migrator
243
256
244
-
##### Summary of steps to test a migrator:
257
+
There are two documented ways to test migrators against copies of the database. One way involves loading a database dump into a containerized MongoDB server and running the migrator against that database and another uses the runtime API to gather collections of interest via `project.Makfile`. Either way is a valid way to test migrators, but you should understand what each version is doing to ensure you are testing properly.
258
+
259
+
### Summary of steps to test a migrator with a local copy of the MongoDB database:
245
260
246
261
1. Create a local copy of the MongoDB database with a schema that conforms to the release from which you are migrating.
247
262
2. Check that the database has been loaded correctly.
248
263
3. Run the migrator against the test database.
249
264
4. Run validation checks against the migrated database.
250
265
251
-
##### Running a migrator step-by-step:
266
+
### Running a migrator with Docker step-by-step:
252
267
253
268
1. **Set up Docker environment and MongoDB database**
% make run-migrator MIGRATOR=migrator_from_1_0_0_to_EXAMPLE ACTION=commit
341
356
```
357
+
358
+
### Summary of steps to test a migrator with the API:
359
+
360
+
1. Run `make` command to test docstring and generate new schema file.
361
+
2. Create a local copy of the latest schema release.
362
+
3. Run API request to create a local copy of collections of interest.
363
+
4. Run the migrator against the test database.
364
+
5. Run validation checks against the migrated database.
365
+
366
+
All local files are saved to `local/`
367
+
368
+
### Running a migrator with project.Makefile step-by-step:
369
+
370
+
1. **Run doctests and create a local copy of the schema according to your local instance**
371
+
372
+
Each migrator should contain docstring tests. This step is important to catch syntax errors AND to **generate a new schema yaml file** to use in the local database tests. To run the docstring test and generate a new schema file run. This step also validates the schema and the example data in this repo.
373
+
374
+
```bash
375
+
% make squeaky-clean test all
376
+
```
377
+
378
+
2. **Run the test-migrator-on-database command with appropriate params**
379
+
380
+
The `test-migrator-on-database` command combines 3 separate commands into one. Using parameters, it removes the need to directly edit `project.Makefile` each time you test a new migrator.
381
+
The following parameters are available:
382
+
383
+
- SELECTED_COLLECTIONS - specify the collections you want to download (i.e. collections that your migrator changes), each one separated by a space. The default is all collections EXCEPT `functional_annotation_agg`.
384
+
- MIGRATOR - the name of the migrator file. DO NOT INCLUDE `.py` EXT
385
+
- ENV - whether to gather data from the prod or dev runtime API environment. The default is prod.
386
+
387
+
**For testing partial migrators, you must reference the file that wraps the partials, not individual partials. All collections modified in any of the partial migrators should be selected in the SELECTED_COLLECTIONS parameter**
388
+
389
+
For example, if I wanted to test `migrator_from_11_6_1_to_11_7_0` and only download the `data_object_set` collection from the production database, I would run:
390
+
391
+
```bash
392
+
% make test-migrator-on-database MIGRATOR=migrator_from_11_6_1_to_11_7_0 SELECTED_COLLECTIONS=data_object_set
393
+
```
394
+
395
+
To download data via the _development_ instance of the NMDC Runtime and run the tests:
396
+
397
+
```bash
398
+
% make test-migrator-on-database MIGRATOR=migrator_from_11_6_1_to_11_7_0 SELECTED_COLLECTIONS=data_object_set ENV=dev
399
+
```
400
+
401
+
To specify multiple collections, separate their names with spaces:
402
+
403
+
```bash
404
+
% make test-migrator-on-database MIGRATOR=migrator_from_11_6_1_to_11_7_0 SELECTED_COLLECTIONS=data_object_set biosample_set ENV=dev
405
+
```
406
+
407
+
408
+
409
+
410
+
> **NOTE**
411
+
>`% make rdf-clean` will delete locally generated files from the testing process. This can be helpful if a bug was identified and the `make` commands need to be rerun after a change.
412
+
413
+
414
+
That's it! Errors will output to `local/mongo_via_api_as_nmdc_database_validation.log` and there will be an alert in the terminal if this occurs.
415
+
416
+
3. **In-depth discussion of test-migrator**
417
+
418
+
As mentioned, the `test-migrator-on-database`command is comprised of three commands. Each command can be run separately outside of `test-migrator-on-database`. This may come in handy when you want to test a change to the migrator, but do not want to download the database again (saves time).
419
+
420
+
- `% make local/mongo_via_api_as_unvalidated_nmdc_database.yaml SELECTED_COLLECTIONS=`
421
+
* This command creates a local dump of the selected collections and saves it to the path local/mongo_via_api_as_unvalidated_nmdc_database.yaml
422
+
- `% make local/mongo_via_api_as_nmdc_database_after_migrator.yaml MIGRATOR=`
423
+
* This command runs the migrator on the collections in`local/mongo_via_api_as_unvalidated_nmdc_database.yaml` and saves the changes to file path `local/mongo_via_api_as_nmdc_database_after_migrator.yaml`
424
+
- `% make local/mongo_via_api_as_nmdc_database_validation.log`
425
+
* This commands validates the migrated collections against `nmdc_schema/nmdc_materialized_patterns.yaml` on the branch. This file will have been recompiled with your schema changes after running `make squeaky-clean test all`. It is important to test against your changes, as this will be the newest version of the schema.
426
+
427
+
You can also test against the most recently-released schema (as opposed to a local branch). The steps for doing that are shown below. They involve making local changes to the file, `project.Makefile`. The changes involve the variable, `$(LATEST_TAG_SCHEMA_FILE)`, which contains the path to the most recent schema release file after it is downloaded from GitHub and is used for testing.
428
+
429
+
- In `local/mongo_via_api_as_unvalidated_nmdc_database.yaml` replace `--schema-source` with `$(LATEST_TAG_SCHEMA_FILE)`
430
+
- Replace `local/mongo_via_api_as_nmdc_database_after_migrator.yaml: nmdc_schema/nmdc_materialized_patterns.yaml` with `local/mongo_via_api_as_nmdc_database_after_migrator.yaml: $(LATEST_TAG_SCHEMA_FILE)`
431
+
- Replace `local/mongo_via_api_as_nmdc_database_validation.log: nmdc_schema/nmdc_materialized_patterns.yaml` with `local/mongo_via_api_as_nmdc_database_validation.log: $(LATEST_TAG_SCHEMA_FILE)`
432
+
433
+
> Remember not to commit these local changes as this will interfere with others' testing processes.
0 commit comments