From bf78009df8a2548b6d6f320a77cd1e295d469749 Mon Sep 17 00:00:00 2001 From: Artemiy Solopov Date: Sat, 25 Apr 2026 14:30:12 +0300 Subject: [PATCH] TaskStatus::Transition model --- app/models/task_status.rb | 4 ++++ app/models/task_status/transition.rb | 10 ++++++++++ ...20260425112121_create_task_status_transitions.rb | 10 ++++++++++ db/schema.rb | 13 ++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/models/task_status/transition.rb create mode 100644 db/migrate/20260425112121_create_task_status_transitions.rb diff --git a/app/models/task_status.rb b/app/models/task_status.rb index 6f516c9..ce9bd83 100644 --- a/app/models/task_status.rb +++ b/app/models/task_status.rb @@ -4,6 +4,10 @@ class TaskStatus < ApplicationRecord belongs_to :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 :color, %w[blue gray yellow green purple pink].index_by(&:itself), default: 'gray', scopes: false diff --git a/app/models/task_status/transition.rb b/app/models/task_status/transition.rb new file mode 100644 index 0000000..b40e179 --- /dev/null +++ b/app/models/task_status/transition.rb @@ -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 diff --git a/db/migrate/20260425112121_create_task_status_transitions.rb b/db/migrate/20260425112121_create_task_status_transitions.rb new file mode 100644 index 0000000..b01d720 --- /dev/null +++ b/db/migrate/20260425112121_create_task_status_transitions.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 2fdfb89..56ae9ac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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| t.text "body", size: :long 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" 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| t.string "color" 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_variant_records", "active_storage_blobs", column: "blob_id" 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", "task_statuses", column: "status_id" add_foreign_key "workflows", "projects"