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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Project < ApplicationRecord
|
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 :name, :code, presence: true
|
||||||
validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z]{2,}\z/ }
|
validates :code, exclusion: { in: %w[new] }, uniqueness: true, format: { with: /\A[a-z]{2,}\z/ }
|
||||||
|
|
||||||
has_many :tasks, dependent: :restrict_with_exception
|
has_many :tasks, dependent: :restrict_with_exception
|
||||||
|
has_many :task_statuses, dependent: :destroy
|
||||||
|
|
||||||
has_rich_text :description
|
has_rich_text :description
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ class Project < ApplicationRecord
|
|||||||
private
|
private
|
||||||
|
|
||||||
def schedule_post_init_job
|
def schedule_post_init_job
|
||||||
ProjectPostInitJob.perform_later id
|
Projects::PostInitJob.perform_later id
|
||||||
end
|
end
|
||||||
|
|
||||||
def drop_tasks_number_sequence
|
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
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class CreateTaskStatuses < ActiveRecord::Migration[8.0]
|
||||||
|
def change
|
||||||
|
create_table :task_statuses do |t|
|
||||||
|
t.references :project, null: false, foreign_key: true
|
||||||
|
t.string :name, null: false
|
||||||
|
t.integer :category, limit: 2, unsigned: true, null: false
|
||||||
|
|
||||||
|
t.index %i[project_id name], unique: true
|
||||||
|
t.index %i[project_id category name]
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Generated
+13
-1
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_10_21_180400) do
|
ActiveRecord::Schema[8.0].define(version: 2025_10_21_204013) do
|
||||||
create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
t.string "name", null: false
|
||||||
t.text "body", size: :long
|
t.text "body", size: :long
|
||||||
@@ -69,6 +69,17 @@ ActiveRecord::Schema[8.0].define(version: 2025_10_21_180400) do
|
|||||||
t.index ["user_id"], name: "index_sessions_on_user_id"
|
t.index ["user_id"], name: "index_sessions_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "task_statuses", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
||||||
|
t.bigint "project_id", null: false
|
||||||
|
t.string "name", null: false
|
||||||
|
t.integer "category", limit: 2, null: false, unsigned: true
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["project_id", "category", "name"], name: "index_task_statuses_on_project_id_and_category_and_name"
|
||||||
|
t.index ["project_id", "name"], name: "index_task_statuses_on_project_id_and_name", unique: true
|
||||||
|
t.index ["project_id"], name: "index_task_statuses_on_project_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
|
||||||
t.bigint "project_id", null: false
|
t.bigint "project_id", null: false
|
||||||
t.integer "number", null: false
|
t.integer "number", null: false
|
||||||
@@ -89,5 +100,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_10_21_180400) do
|
|||||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||||
add_foreign_key "sessions", "users"
|
add_foreign_key "sessions", "users"
|
||||||
|
add_foreign_key "task_statuses", "projects"
|
||||||
add_foreign_key "tasks", "projects"
|
add_foreign_key "tasks", "projects"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Projects
|
||||||
|
module CreateDefaultTaskStatuses
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def create_default_task_statuses(project)
|
||||||
|
# TODO: make it configurable/templatable?
|
||||||
|
|
||||||
|
project.transaction do
|
||||||
|
project.task_statuses.create!(category: :backlog, name: 'Backlog')
|
||||||
|
project.task_statuses.create!(category: :analysis, name: 'To do')
|
||||||
|
project.task_statuses.create!(category: :development, name: 'In development')
|
||||||
|
project.task_statuses.create!(category: :fulfillment, name: 'Done')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user