Task status model + default task status generation
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProjectPostInitJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(project_id)
|
||||
project = Project.preparing.find(project_id)
|
||||
|
||||
create_tasks_number_sequence(project)
|
||||
project.update!(status: :ready)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_tasks_number_sequence(project)
|
||||
Project.connection.execute "CREATE SEQUENCE IF NOT EXISTS #{project.tasks_number_sequence_name} AS INT UNSIGNED"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,25 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Projects
|
||||
class PostInitJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
include Projects::CreateDefaultTaskStatuses
|
||||
|
||||
def perform(project_id)
|
||||
project = Project.preparing.find(project_id)
|
||||
|
||||
project.transaction do
|
||||
create_tasks_number_sequence(project)
|
||||
create_default_task_statuses(project)
|
||||
project.update!(status: :ready)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_tasks_number_sequence(project)
|
||||
Project.connection.execute "CREATE SEQUENCE IF NOT EXISTS #{project.tasks_number_sequence_name} AS INT UNSIGNED"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,12 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Project < ApplicationRecord
|
||||
enum :status, %i[preparing ready archived].index_by(&:itself), default: :preparing
|
||||
enum :status, %w[preparing ready archived].index_by(&:itself), default: :preparing
|
||||
|
||||
validates :name, :code, presence: true
|
||||
validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z]{2,}\z/ }
|
||||
|
||||
has_many :tasks, dependent: :restrict_with_exception
|
||||
has_many :task_statuses, dependent: :destroy
|
||||
|
||||
has_rich_text :description
|
||||
|
||||
@@ -35,7 +36,7 @@ class Project < ApplicationRecord
|
||||
private
|
||||
|
||||
def schedule_post_init_job
|
||||
ProjectPostInitJob.perform_later id
|
||||
Projects::PostInitJob.perform_later id
|
||||
end
|
||||
|
||||
def drop_tasks_number_sequence
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TaskStatus < ApplicationRecord
|
||||
belongs_to :project
|
||||
|
||||
enum :category, { backlog: 100, analysis: 1000, development: 20_000, fulfillment: 60_000 }
|
||||
|
||||
validates :name, presence: true, uniqueness: { scope: :project }
|
||||
validates :category, presence: true
|
||||
end
|
||||
Reference in New Issue
Block a user