Add diary entries

This commit is contained in:
Trevor Vallender 2023-12-29 12:16:30 +00:00
parent 16adb83240
commit 20ff7d1764
5 changed files with 70 additions and 1 deletions

11
app/models/diary_entry.rb Normal file
View File

@ -0,0 +1,11 @@
class DiaryEntry < ApplicationRecord
belongs_to :user
validates :date,
:pain_level,
:energy_level,
:mental_alertness_level,
:work_stress_level,
:life_stress_level,
presence: true
end

View File

@ -0,0 +1,17 @@
class CreateDiaryEntries < ActiveRecord::Migration[7.1]
def change
create_table :diary_entries do |t|
t.text :notes, null: false, default: ''
t.date :date, null: false
t.references :user, null: false, foreign_key: true
t.integer :pain_level, null: false
t.integer :energy_level, null: false
t.integer :mental_alertness_level, null: false
t.integer :work_stress_level, null: false
t.integer :life_stress_level, null: false
t.integer :sleep_quality_level, null: false
t.timestamps
end
end
end

18
db/schema.rb generated
View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2023_12_29_114145) do
ActiveRecord::Schema[7.1].define(version: 2023_12_29_114804) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -63,6 +63,21 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_29_114145) do
t.index ["user_id"], name: "index_blog_posts_on_user_id"
end
create_table "diary_entries", force: :cascade do |t|
t.text "notes", default: "", null: false
t.date "date", null: false
t.bigint "user_id", null: false
t.integer "pain_level", null: false
t.integer "energy_level", null: false
t.integer "mental_alertness_level", null: false
t.integer "work_stress_level", null: false
t.integer "life_stress_level", null: false
t.integer "sleep_quality_level", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_diary_entries_on_user_id"
end
create_table "exercise_types", force: :cascade do |t|
t.text "name", null: false
t.text "unit", null: false
@ -128,6 +143,7 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_29_114145) 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 "blog_posts", "users"
add_foreign_key "diary_entries", "users"
add_foreign_key "exercises", "exercise_types"
add_foreign_key "microposts", "users"
end

21
test/fixtures/diary_entries.yml vendored Normal file
View File

@ -0,0 +1,21 @@
one:
user: tsvallender
date: 2023-12-29
notes: Oh, what a day
exercise: one
pain_level: 10
energy_level: 10
mental_alertness_level: 10
work_stress_level: 10
life_stress_level: 10
two:
user: tsvallender
date: 2023-12-28
notes: Wow
exercise: two
pain_level: 1
energy_level: 1
mental_alertness_level: 1
work_stress_level: 1
life_stress_level: 1

View File

@ -0,0 +1,4 @@
require "test_helper"
class DiaryEntryTest < ActiveSupport::TestCase
end