Used to update the database schema (tables, types, views)

  1. Create a migration at db/migrations/. You’ll then need to go update the file per your migration. See existing migrations for examples

    deno task db:migrate create my_new_migration
    
  2. Migrate to latest.

    # Running db:migrate:local *  task runs a db:migrate:* against both vha_dev and vha_test
    deno task switch:local
    deno task db:migrate local latest
    
    # Migrating production from your local machine
    # Heroku will migrate to latest automatically on deploy
    deno task switch:prod
    deno task db:migrate latest
    
  3. If this works, export the database’s types to db.d.ts by

    deno task db:codegen
    
  4. If this works, you’re done! If you notice any issues you can migrate down like so

    deno task db:migrate:down
    

Wiping the DB

While we have no live users, it’s often easier to wipe the DB and then apply your migrations from scratch. Reach out to the team in #engineering as you’re doing this

  1. Wipe the DB while on the main branch. This (should) clear all tables, types, views, etc. If it doesn’t, it means our down() functions need to be updated

    deno task db:migrate local reset
    
  2. Switch to your feature branch with the new migrations.

    git checkout feature-branch
    
  3. Migrate to latest.

    deno task db:migrate:latest
    

Seed files

deno task db:local seed load $target # loads a partilar seed, from tsv if available or from the definition otherwise
deno task db:local seed dump $target # dumps the contents of database tables to .tsv files
deno task db:local seed drop $target # truncate the corresponding tables from the database
deno task db:local seed recreate $target # reloads the seed from its definition and dumps .tsv files

When all hope is lost

deno task db:local reset