From d5450746daea61376594d63f145cca15c25e93fb Mon Sep 17 00:00:00 2001 From: Vinoth Date: Thu, 8 Jan 2015 20:54:46 +0530 Subject: [PATCH] cleanup endorsements without valid skills, make endorsements delete if corresponding skill is deleted --- app/models/skill.rb | 2 +- .../20150108152023_cleanup_endorsements_without_skill.rb | 9 +++++++++ db/schema.rb | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20150108152023_cleanup_endorsements_without_skill.rb diff --git a/app/models/skill.rb b/app/models/skill.rb index 1b4b4a9d..4fd5049b 100644 --- a/app/models/skill.rb +++ b/app/models/skill.rb @@ -5,7 +5,7 @@ class Skill < ActiveRecord::Base BLANK = '' belongs_to :user - has_many :endorsements + has_many :endorsements, dependent: :delete_all validates_presence_of :tokenized validates_presence_of :user_id diff --git a/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb b/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb new file mode 100644 index 00000000..10becd3d --- /dev/null +++ b/db/migrate/20150108152023_cleanup_endorsements_without_skill.rb @@ -0,0 +1,9 @@ +class CleanupEndorsementsWithoutSkill < ActiveRecord::Migration + def up + Endorsement.delete_all(skill_id: [nil,'']) + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index 71863f0c..7c3a39e3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150103105333) do +ActiveRecord::Schema.define(:version => 20150108152023) do add_extension "citext" add_extension "hstore"