#276: added RepositoryStatus model, migrations

This commit is contained in:
Vokhmin Alexey V 2013-08-22 20:12:54 +04:00
parent 54cadb0526
commit f5c1509281
5 changed files with 83 additions and 0 deletions

View File

@ -3,6 +3,15 @@ class Platform < ActiveRecord::Base
VISIBILITIES = %w(open hidden)
NAME_PATTERN = /[\w\-\.]+/
READY = RepositoryStatus::READY
WAITING_FOR_REGENERATION = RepositoryStatus::WAITING_FOR_REGENERATION
REGENERATING = RepositoryStatus::REGENERATING
HUMAN_STATUSES = { READY => :ready,
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
REGENERATING => :regenerating
}.freeze
belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
belongs_to :owner, :polymorphic => true
@ -60,6 +69,21 @@ class Platform < ActiveRecord::Base
include Modules::Models::Owner
state_machine :status, :initial => :ready do
event :ready do
transition :regenerating => :ready
end
event :regenerate do
transition :waiting_for_regeneration => :regenerating
transition :ready => :waiting_for_regeneration
end
HUMAN_STATUSES.each do |code,name|
state name, :value => code
end
end
def clear
system("rm -Rf #{ APP_CONFIG['root_path'] }/platforms/#{ self.name }/repository/*")
end

View File

@ -12,6 +12,7 @@ class Repository < ActiveRecord::Base
has_many :project_to_repositories, :dependent => :destroy, :validate => true
has_many :projects, :through => :project_to_repositories
has_one :key_pair, :dependent => :destroy
has_one :repository_statuses, :dependent => :destroy
has_many :build_lists, :foreign_key => :save_to_repository_id, :dependent => :destroy

View File

@ -0,0 +1,37 @@
class RepositoryStatus < ActiveRecord::Base
READY = 0
WAITING_FOR_REGENERATION = 100
REGENERATING = 200
PUBLISH = 300
HUMAN_STATUSES = { READY => :ready,
WAITING_FOR_REGENERATION => :waiting_for_regeneration,
REGENERATING => :regenerating,
PUBLISH => :publish
}.freeze
validates :repository_id, :platform_id, :presence => true
validates :repository_id, :uniqueness => {:scope => :platform_id}
attr_accessible :last_regenerated_at, :last_regenerated_status, :platform_id, :repository_id, :status
state_machine :status, :initial => :ready do
event :ready do
transition [:regenerating, :publish] => :ready
end
event :regenerate do
transition :waiting_for_regeneration => :regenerating
transition :ready => :waiting_for_regeneration
end
event :publish_packages do
transition :ready => :publish
end
HUMAN_STATUSES.each do |code,name|
state name, :value => code
end
end
end

View File

@ -0,0 +1,14 @@
class CreateRepositoryStatuses < ActiveRecord::Migration
def change
create_table :repository_statuses do |t|
t.integer :repository_id, :null => false
t.integer :platform_id, :null => false
t.integer :status
t.datetime :last_regenerated_at
t.integer :last_regenerated_status
t.timestamps
end
add_index :repository_statuses, [:repository_id, :platform_id], :unique => true
end
end

View File

@ -0,0 +1,7 @@
class AddStatusToPlatform < ActiveRecord::Migration
def change
add_column :platforms, :status, :integer
add_column :platforms, :last_regenerated_at, :datetime
add_column :platforms, :last_regenerated_status, :integer
end
end