Skip to content

Commit

Permalink
Fix migration column caching.
Browse files Browse the repository at this point in the history
When this migration is run in the same process as
20170827091406_change_container_quota_items_columns_to_float.rb, that
migration does some column caching for its ContainerQuotaItem stub model
which ends up being inherited by this migration.  The symptom is that
this migration's stub model does not actually have the created_at
column, and thus never writes the value.  Later on when
change_column_null is called, the column has null values in it causing
that statement to fail.

https://bugzilla.redhat.com/show_bug.cgi?id=1515376
  • Loading branch information
Fryguy committed Nov 21, 2017
1 parent bdc5a90 commit ff649d4
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def change
add_index :container_quotas, :deleted_on

add_timestamps :container_quota_items, :null => true # temporarily for backfilling, then disallow nulls
ContainerQuotaItem.reset_column_information

reversible do |dir|
dir.up do
say_with_time("Backfilling container_quota_items timestamps from parent quotas") do
Expand All @@ -17,12 +19,13 @@ def change
now = Time.zone.now
ContainerQuotaItem.includes(:container_quota).find_each do |item|
# This also sets updated_at to migration time.
item.update_attributes(:created_at => item.container_quota.try(:created_on) || now)
item.update_attributes!(:created_at => item.container_quota.try(:created_on) || now)
end
end
end
# down: unnecessary, created_at/updated_at columns get deleted.
end

change_column_null :container_quota_items, :created_at, false
change_column_null :container_quota_items, :updated_at, false

Expand Down

0 comments on commit ff649d4

Please sign in to comment.