diff --git a/db/migrate/20161205095623_removing_intermediary_tables.rb b/db/migrate/20161205095623_removing_intermediary_tables.rb index 79f2f4f..5e44007 100644 --- a/db/migrate/20161205095623_removing_intermediary_tables.rb +++ b/db/migrate/20161205095623_removing_intermediary_tables.rb @@ -55,6 +55,7 @@ drop_table :comments change_table :new_plans do |t| + t.remove :project_id end drop_table :plans rename_table :new_plans, :plans @@ -79,6 +80,9 @@ rename_column :templates, :organisation_id, :org_id rename_column :users, :organisation_id, :org_id + #drop_table :projects + #drop_table :project_guidance + end def down diff --git a/db/migrate/20161208122123_single_group_for_guidance.rb b/db/migrate/20161208122123_single_group_for_guidance.rb new file mode 100644 index 0000000..4c02f86 --- /dev/null +++ b/db/migrate/20161208122123_single_group_for_guidance.rb @@ -0,0 +1,20 @@ +class SingleGroupForGuidance < ActiveRecord::Migration + def change + unless Rails.env.test? + Guidance.class_eval do + belongs_to :guidance_group, class_name: "GuidanceGroup", foreign_key: "guidance_group_id" + end + + Guidance.includes( :guidance_groups).all.each do |guidance| + guidance.guidance_group_id = guidance.guidance_groups.first.id unless guidance.guidance_groups.empty? + if guidance.guidance_group_id.nil? + guidance.destroy + else + guidance.save! + end + end + end + + drop_table :guidance_in_group + end +end