Skip to content

Commit

Permalink
Merge pull request Katello#2718 from daviddavis/fix-repos-cv-migration
Browse files Browse the repository at this point in the history
Fixing 20121112144229_repository_add_content_view.rb
  • Loading branch information
David Davis committed Aug 5, 2013
2 parents 2ada16f + 8fa0bf6 commit 7b06099
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion db/migrate/20121112144229_repository_add_content_view.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
class RepositoryAddContentView < ActiveRecord::Migration
class Organization < ActiveRecord::Base
has_many :environments, :class_name => "KTEnvironment", :dependent => :destroy, :inverse_of => :organization
end
class KTEnvironment < ActiveRecord::Base
self.table_name = "environments"
has_many :repositories, :through => :environment_products
belongs_to :organization, :inverse_of => :environments
has_many :environment_products, :foreign_key => "environment_id"

def default_content_view
ContentView.find_find_by_id(default_content_view_id)
end
end
class EnvironmentProduct < ActiveRecord::Base
has_many :repositories
belongs_to :environment, :class_name => "KTEnvironment"
end
class Repository < ActiveRecord::Base
belongs_to :environment_product
belongs_to :content_view_version
end
class ContentViewVersion < ActiveRecord::Base
has_many :repositories, :dependent => :destroy
belongs_to :content_view
end
class ContentView < ActiveRecord::Base
include Ext::LabelFromName
has_many :content_view_versions, :dependent => :destroy
end

def self.up
add_column :repositories, :content_view_version_id, :integer, :null=>true
add_index :repositories, :content_view_version_id
Expand All @@ -9,7 +39,7 @@ def self.up
User.current = User.hidden.first
KTEnvironment.all.each do |env|
view = ContentView.create!(:name=>"Default View for #{env.name}",
:organization=>env.organization, :default=>true)
:organization_id=>env.organization_id, :default=>true)
env.default_content_view_id = view.id
env.save!
version = ContentViewVersion.create!(:version=>1, :content_view=>view)
Expand Down

0 comments on commit 7b06099

Please sign in to comment.