TaskStatus::Transition model

This commit is contained in:
2026-04-25 14:30:12 +03:00
parent b1038c0d66
commit bf78009df8
4 changed files with 36 additions and 1 deletions
+4
View File
@@ -4,6 +4,10 @@ class TaskStatus < ApplicationRecord
belongs_to :workflow belongs_to :workflow
has_one :project, through: :workflow has_one :project, through: :workflow
has_many :from_transitions, class_name: 'TaskStatus::Transition', inverse_of: :from, dependent: :destroy
has_many :to_transitions, class_name: 'TaskStatus::Transition', inverse_of: :to, dependent: :destroy
has_many :next_statuses, class_name: 'TaskStatus', through: :from_transitions, source: :to
enum :icon, %w[new achived done circle_dash hammer play tool].index_by(&:itself), default: 'new', scopes: false enum :icon, %w[new achived done circle_dash hammer play tool].index_by(&:itself), default: 'new', scopes: false
enum :color, %w[blue gray yellow green purple pink].index_by(&:itself), default: 'gray', scopes: false enum :color, %w[blue gray yellow green purple pink].index_by(&:itself), default: 'gray', scopes: false
+10
View File
@@ -0,0 +1,10 @@
# frozen_string_literal: true
class TaskStatus
class Transition < ApplicationRecord
self.table_name = 'task_status_transitions'
belongs_to :from, class_name: '::TaskStatus'
belongs_to :to, class_name: '::TaskStatus'
end
end
@@ -0,0 +1,10 @@
class CreateTaskStatusTransitions < ActiveRecord::Migration[8.1]
def change
create_table :task_status_transitions do |t|
t.belongs_to :from, null: false, foreign_key: { to_table: :task_statuses }
t.belongs_to :to, null: false, foreign_key: { to_table: :task_statuses }
t.timestamps
end
end
end
Generated
+12 -1
View File
@@ -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.1].define(version: 2026_04_04_215813) do ActiveRecord::Schema[8.1].define(version: 2026_04_25_112121) 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.text "body", size: :long t.text "body", size: :long
t.datetime "created_at", null: false t.datetime "created_at", null: false
@@ -69,6 +69,15 @@ ActiveRecord::Schema[8.1].define(version: 2026_04_04_215813) 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_status_transitions", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
t.datetime "created_at", null: false
t.bigint "from_id", null: false
t.bigint "to_id", null: false
t.datetime "updated_at", null: false
t.index ["from_id"], name: "index_task_status_transitions_on_from_id"
t.index ["to_id"], name: "index_task_status_transitions_on_to_id"
end
create_table "task_statuses", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| create_table "task_statuses", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t|
t.string "color" t.string "color"
t.datetime "created_at", null: false t.datetime "created_at", null: false
@@ -116,6 +125,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_04_04_215813) 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_status_transitions", "task_statuses", column: "from_id"
add_foreign_key "task_status_transitions", "task_statuses", column: "to_id"
add_foreign_key "tasks", "projects" add_foreign_key "tasks", "projects"
add_foreign_key "tasks", "task_statuses", column: "status_id" add_foreign_key "tasks", "task_statuses", column: "status_id"
add_foreign_key "workflows", "projects" add_foreign_key "workflows", "projects"