BUGFIX: orphan badge groupings

This commit is contained in:
Sam 2014-07-18 15:55:42 +10:00
parent c8284170ad
commit 4feedecce4
3 changed files with 6 additions and 2 deletions

View File

@ -181,7 +181,10 @@ SQL
end
def default_badge_grouping_id=(val)
self.badge_grouping_id ||= val
# allow to correct orphans
if !self.badge_grouping_id || self.badge_grouping_id < 0
self.badge_grouping_id = val
end
end
end

View File

@ -31,7 +31,7 @@ end
# BUGFIX
Badge.exec_sql 'UPDATE badges
SET badge_grouping_id = NULL
SET badge_grouping_id = -1
WHERE NOT EXISTS (
SELECT 1 FROM badge_groupings g
WHERE g.id = badge_grouping_id

View File

@ -1,5 +1,6 @@
class SetDefaultBadgeGrouping < ActiveRecord::Migration
def change
execute 'UPDATE badges SET badge_grouping_id = 5 WHERE badge_grouping_id IS NULL'
change_column :badges, :badge_grouping_id, :integer, null: false, default: 5
end
end