diff --git a/app/models/project.rb b/app/models/project.rb new file mode 100644 index 0000000..663c3de --- /dev/null +++ b/app/models/project.rb @@ -0,0 +1,7 @@ +class Project < ApplicationRecord + validates :name, :code, presence: true + + has_many :tasks + + has_rich_text :description +end diff --git a/app/models/task.rb b/app/models/task.rb new file mode 100644 index 0000000..a09b0fa --- /dev/null +++ b/app/models/task.rb @@ -0,0 +1,8 @@ +class Task < ApplicationRecord + belongs_to :project + + validates :number, :title, presence: true + validates :number, numericality: { greater_than: 0 } + + has_rich_text :description +end diff --git a/db/migrate/20250621203845_create_projects.rb b/db/migrate/20250621203845_create_projects.rb new file mode 100644 index 0000000..44e530b --- /dev/null +++ b/db/migrate/20250621203845_create_projects.rb @@ -0,0 +1,12 @@ +class CreateProjects < ActiveRecord::Migration[8.0] + def change + create_table :projects do |t| + t.string :name, null: false + t.string :code, null: false + + t.timestamps + end + add_index :projects, :name + add_index :projects, :code, unique: true + end +end diff --git a/db/migrate/20250621203940_create_tasks.rb b/db/migrate/20250621203940_create_tasks.rb new file mode 100644 index 0000000..7250990 --- /dev/null +++ b/db/migrate/20250621203940_create_tasks.rb @@ -0,0 +1,11 @@ +class CreateTasks < ActiveRecord::Migration[8.0] + def change + create_table :tasks do |t| + t.references :project, null: false, foreign_key: true + t.integer :number, null: false + t.string :title, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 1baf278..51352bf 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.0].define(version: 2025_06_21_202543) do +ActiveRecord::Schema[8.0].define(version: 2025_06_21_203940) do create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.string "name", null: false t.text "body", size: :long @@ -49,6 +49,15 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_21_202543) do t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true end + create_table "projects", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| + t.string "name", null: false + t.string "code", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["code"], name: "index_projects_on_code", unique: true + t.index ["name"], name: "index_projects_on_name" + end + create_table "sessions", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.bigint "user_id", null: false t.string "ip_address" @@ -58,6 +67,15 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_21_202543) do t.index ["user_id"], name: "index_sessions_on_user_id" end + create_table "tasks", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| + t.bigint "project_id", null: false + t.integer "number", null: false + t.string "title", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["project_id"], name: "index_tasks_on_project_id" + end + create_table "users", charset: "utf8mb4", collation: "utf8mb4_uca1400_ai_ci", force: :cascade do |t| t.string "email_address", null: false t.string "password_digest", null: false @@ -69,4 +87,5 @@ ActiveRecord::Schema[8.0].define(version: 2025_06_21_202543) 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 "tasks", "projects" end