From 7570f1cab77104d790f99796f9f239b5854a351e Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Fri, 7 Sep 2012 18:41:42 +0300 Subject: [PATCH] Set publish_without_qa to false for all platform repos when released. Fix mgration. Refs #631 --- app/models/platform.rb | 10 +++++----- ...906115648_add_publish_without_qa_to_repositories.rb | 5 +++-- db/schema.rb | 10 +++++----- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/models/platform.rb b/app/models/platform.rb index bd5856f3f..26dcbe5f1 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -28,13 +28,12 @@ class Platform < ActiveRecord::Base before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]} before_destroy :xml_rpc_destroy - after_update :freeze_platform + after_update :freeze_platform_and_update_repos + after_update :update_owner_relation after_create lambda { symlink_directory unless hidden? } after_destroy lambda { remove_symlink_directory unless hidden? } - after_update :update_owner_relation - scope :search_order, order("CHAR_LENGTH(name) ASC") scope :search, lambda {|q| where("name ILIKE ?", "%#{q.to_s.strip}%")} scope :by_visibilities, lambda {|v| where(:visibility => v)} @@ -230,10 +229,11 @@ class Platform < ActiveRecord::Base end later :xml_rpc_clone, :loner => true, :queue => :clone_build - def freeze_platform + def freeze_platform_and_update_repos if released_changed? && released == true - result = BuildServer.freeze(name) + result = BuildServer.freeze(name) raise "Failed freeze platform #{name} with code #{result}" if result != BuildServer::SUCCESS + repositories.update_all(:publish_without_qa => false) end end end diff --git a/db/migrate/20120906115648_add_publish_without_qa_to_repositories.rb b/db/migrate/20120906115648_add_publish_without_qa_to_repositories.rb index d1b1f2ca0..c3f83e01e 100644 --- a/db/migrate/20120906115648_add_publish_without_qa_to_repositories.rb +++ b/db/migrate/20120906115648_add_publish_without_qa_to_repositories.rb @@ -1,6 +1,7 @@ class AddPublishWithoutQaToRepositories < ActiveRecord::Migration class Platform < ActiveRecord::Base + has_many :repositories, :dependent => :destroy end class Repository < ActiveRecord::Base @@ -9,8 +10,8 @@ class AddPublishWithoutQaToRepositories < ActiveRecord::Migration def up add_column :repositories, :publish_without_qa, :boolean, :default => true - Repository.where('platforms.released is true').joins(:platform). - update_all(:publish_without_qa => false) + Platform.where(:released => true).each{|p| p.repositories.update_all(:publish_without_qa => false)} + Platform.where(:released => false).each{|p| p.repositories.update_all(:publish_without_qa => true)} end def down diff --git a/db/schema.rb b/db/schema.rb index 7447b19d8..e9375ad5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -411,11 +411,8 @@ ActiveRecord::Schema.define(:version => 20120906115648) do t.text "ssh_key" t.string "uname" t.string "role" - t.string "language", :default => "en" - t.integer "own_projects_count", :default => 0, :null => false - t.string "confirmation_token" - t.datetime "confirmed_at" - t.datetime "confirmation_sent_at" + t.string "language", :default => "en" + t.integer "own_projects_count", :default => 0, :null => false t.text "professional_experience" t.string "site" t.string "company" @@ -427,6 +424,9 @@ ActiveRecord::Schema.define(:version => 20120906115648) do t.integer "failed_attempts", :default => 0 t.string "unlock_token" t.datetime "locked_at" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" t.string "authentication_token" t.integer "build_priority", :default => 50 end