Skip to content

Database Updates

Tiffany edited this page Mar 3, 2023 · 4 revisions

This page exists as a guide to help the developer target what changes need to be made with a database model update.

When making a change to a model schema:

Model Schemas

In models/apd.js, apdSchema is the base model for an APD. It may contain other nested schemas, such as:

  • activitySchema found in models/apdActivity.js as the base activity model
  • budgetSchema found in models/budget.js as the base budget model

Because this project sets up APD of different types (HITECH, MMIS), there are also schemas for the types that expand (by inheritance) on the base schemas. That also means you can overwrite fields (if necessary) that exist in the base schema by whatever schema is inheriting the base.

Example (not an exhaustive list):

Base schema Schema that inherits base schema APD Type
apdSchema hitechSchema HITECH
apdSchema mmisSchema MMIS
activitySchema hitechActivitySchema HITECH
activitySchema mmisActivitySchema MMIS
budgetSchema hitechBudgetSchema HITECH
budgetSchema mmisBudgetSchema MMIS

Seed Files

Seed files exist in both seeds/development and seeds/testing directories

API Files

Relevant updates could include files for when a new APD is created (post.data.js which is the APD-type-shared structure, and possibly the file that contains APD-type-specific structure, like post.mmis.data.js)

Migrations

Create a migration file

  1. Create a scaffolding migration file From the api directory, run: (file name should describe update and should have “mongoose” prefix for Mongo-related changes)
yarn run make-migrate mongoose-example-file
  1. Modify the migration file - this code will update existing data in the database to conform to your model changes
  2. Use the up method to change the current database items to match your new model
  3. Use the down method to change the database items back to how they were before the migration ran

Test the migration file

Test this by running the migration. The command must be run inside the container: so you should either attach to the container and run it as

yarn migrate

or to run it from your local terminal run

docker compose exec api yarn migrate

Test this multiple times on the same data to ensure this has consistent results. You can delete the migration file from postgres locally, rerun the seed to reset the data, then add the migration file back and repeat.

Run the migration file

From the api directory, run as explained above.

How we work

eAPD documentation

Design documentation

Technical documentation

Operations and Support documentation

Recovery Plans

Operations Runbooks

Quality Documentation

Clone this wiki locally