Re running Seed Files - department-of-veterans-affairs/caseflow Wiki

Re-running Seed Files

Some seed files located in db/seeds can be manually run from the rails console to generate more data for testing. Listed below are instructions to manually run these seeds, as well as which seed files can and cannot be run.

In some rare cases, running a seed file can generate an ActiveRecord::RecordNotUnique: PG::UniqueViolation error. This is generally due to the way some objects are created in the seed files; most objects related to the service fakes are created from the Generators in lib/generators, while objects being persisted in the DBs are created with FactoryBot using the factories in spec/factories. The generators are set up to assign random values to their IDs, which can cause data collisions during seeding.

To re-run seeding files:

  1. Open a rails console (make c)
  2. Run the following commands:
    • RequestStore[:current_user] = User.system_user
    • Dir[Rails.root.join("db/seeds/*.rb")].sort.each { |f| require f }
  3. For the desired seed file, run the following command:
    • Seeds::{Seed_File_Name}.new.seed!

Seed files that can be re-run after initial seeding:

  • Tasks
  • Hearings
  • Jobs
  • Substitutions
  • DecisionIssues
  • CavcAmaAppeals
  • MTV
  • PriorityDistributions

When running the following seed files, some initial data will not be recreated:

  • Tasks
    • create_legacy_appeals_with_open_schedule_hearing_task will not add new legacy appeals
    • create_colocated_legacy_tasks will not add new tasks
    • create_legacy_appeal_at_acting_judge will not create new legacy appeals
    • create_legacy_issues_eligible_for_opt_in will not create new legacy issues or appeals

Seed files that can not/should not be run after initial seeding:

  • Annotations
  • Tags
  • Intake
    • This can be run again, but may error multiple times due to contention_reference_id uniqueness, which is caused by the VBMS service fakes
  • SanitizedJsonSeeds
  • Users
  • Dispatch
  • VeteransHealthAdministration
  • Education