From dbd849589be303e31395239bae5bea20fd87b4ef Mon Sep 17 00:00:00 2001 From: Artemiy Solopov Date: Sat, 21 Mar 2026 14:02:55 +0200 Subject: [PATCH] Workflow model --- app/models/task.rb | 1 + app/models/task_status.rb | 1 + app/models/workflow.rb | 11 +++++++++++ db/migrate/20260321114951_create_workflows.rb | 14 ++++++++++++++ ...21_add_workflow_id_to_statuses_and_tasks.rb | 6 ++++++ db/schema.rb | 18 +++++++++++++++++- 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 app/models/workflow.rb create mode 100644 db/migrate/20260321114951_create_workflows.rb create mode 100644 db/migrate/20260321115521_add_workflow_id_to_statuses_and_tasks.rb diff --git a/app/models/task.rb b/app/models/task.rb index 467273b..1b736d3 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -3,6 +3,7 @@ class Task < ApplicationRecord belongs_to :project belongs_to :status, class_name: 'TaskStatus' + belongs_to :workflow validates :number, :title, presence: true validates :number, numericality: { greater_than: 0 } diff --git a/app/models/task_status.rb b/app/models/task_status.rb index a13768d..8ba0a17 100644 --- a/app/models/task_status.rb +++ b/app/models/task_status.rb @@ -2,6 +2,7 @@ class TaskStatus < ApplicationRecord belongs_to :project + belongs_to :workflow enum :category, { backlog: 100, analysis: 1000, development: 20_000, fulfillment: 60_000 } diff --git a/app/models/workflow.rb b/app/models/workflow.rb new file mode 100644 index 0000000..e69b8b2 --- /dev/null +++ b/app/models/workflow.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class Workflow < ApplicationRecord + belongs_to :project + + has_many :tasks, dependent: :restrict_with_exception + has_mnay :statuses, dependent: :restrict_with_error + + enum :icon, { task: 'task', warning: 'warning' }, default: 'task', scopes: false + enum :color, { blue: 'blue', gray: 'gray', yellow: 'yellow', red: 'red' }, default: 'gray', scopes: false +end diff --git a/db/migrate/20260321114951_create_workflows.rb b/db/migrate/20260321114951_create_workflows.rb new file mode 100644 index 0000000..08a4958 --- /dev/null +++ b/db/migrate/20260321114951_create_workflows.rb @@ -0,0 +1,14 @@ +class CreateWorkflows < ActiveRecord::Migration[8.1] + def change + create_table :workflows do |t| + t.belongs_to :project, null: false, foreign_key: true + t.string :name, null: false + t.string :icon, null: false + t.string :color, null: false + + t.index %i[project_id name], unique: true + + t.timestamps + end + end +end diff --git a/db/migrate/20260321115521_add_workflow_id_to_statuses_and_tasks.rb b/db/migrate/20260321115521_add_workflow_id_to_statuses_and_tasks.rb new file mode 100644 index 0000000..68a03c4 --- /dev/null +++ b/db/migrate/20260321115521_add_workflow_id_to_statuses_and_tasks.rb @@ -0,0 +1,6 @@ +class AddWorkflowIdToStatusesAndTasks < ActiveRecord::Migration[8.1] + def change + add_belongs_to :tasks, :workflow + add_belongs_to :task_statuses, :workflow + end +end diff --git a/db/schema.rb b/db/schema.rb index f05bd18..a124fed 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_03_01_141927) do +ActiveRecord::Schema[8.1].define(version: 2026_03_21_115521) 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 @@ -75,9 +75,11 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_01_141927) do t.string "name", null: false t.bigint "project_id", null: false t.datetime "updated_at", null: false + t.bigint "workflow_id" 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" + t.index ["workflow_id"], name: "index_task_statuses_on_workflow_id" end create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| @@ -87,8 +89,10 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_01_141927) do t.bigint "status_id" t.string "title", null: false t.datetime "updated_at", null: false + t.bigint "workflow_id" t.index ["project_id"], name: "index_tasks_on_project_id" t.index ["status_id"], name: "index_tasks_on_status_id" + t.index ["workflow_id"], name: "index_tasks_on_workflow_id" end create_table "users", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| @@ -99,10 +103,22 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_01_141927) do t.index ["email_address"], name: "index_users_on_email_address", unique: true end + create_table "workflows", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| + t.string "color", null: false + t.datetime "created_at", null: false + t.string "icon", null: false + t.string "name", null: false + t.bigint "project_id", null: false + t.datetime "updated_at", null: false + t.index ["project_id", "name"], name: "index_workflows_on_project_id_and_name", unique: true + t.index ["project_id"], name: "index_workflows_on_project_id" + end + 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_statuses", "projects" add_foreign_key "tasks", "projects" add_foreign_key "tasks", "task_statuses", column: "status_id" + add_foreign_key "workflows", "projects" end