From 2b29f0cc3a7e631dd84cde01561c32fd49efe15a Mon Sep 17 00:00:00 2001 From: Theodor Vararu Date: Wed, 16 Oct 2024 08:48:27 +0200 Subject: [PATCH] Update batches only if team exists The reference to `Team.first.id` breaks on an empty database because there are no teams. --- db/migrate/20241015090951_add_team_to_batches.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20241015090951_add_team_to_batches.rb b/db/migrate/20241015090951_add_team_to_batches.rb index b432aa89e..9edff33ed 100644 --- a/db/migrate/20241015090951_add_team_to_batches.rb +++ b/db/migrate/20241015090951_add_team_to_batches.rb @@ -3,7 +3,7 @@ class AddTeamToBatches < ActiveRecord::Migration[7.2] def up add_reference :batches, :team, foreign_key: true - Batch.update_all(team_id: Team.first.id) + Batch.update_all(team_id: Team.first.id) if Team.any? change_column_null :batches, :team_id, false add_index :batches, %i[team_id name expiry vaccine_id], unique: true end