From 16adb83240bc295ac3791739a96d5b36411f60fb Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Fri, 29 Dec 2023 11:44:35 +0000 Subject: [PATCH] Add exercises --- app/models/exercise.rb | 3 +++ db/migrate/20231229114145_create_exercises.rb | 11 +++++++++++ db/schema.rb | 12 +++++++++++- test/fixtures/exercises.yml | 9 +++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/models/exercise.rb create mode 100644 db/migrate/20231229114145_create_exercises.rb create mode 100644 test/fixtures/exercises.yml diff --git a/app/models/exercise.rb b/app/models/exercise.rb new file mode 100644 index 0000000..09473e8 --- /dev/null +++ b/app/models/exercise.rb @@ -0,0 +1,3 @@ +class Exercise < ApplicationRecord + belongs_to :type +end diff --git a/db/migrate/20231229114145_create_exercises.rb b/db/migrate/20231229114145_create_exercises.rb new file mode 100644 index 0000000..aa63eaa --- /dev/null +++ b/db/migrate/20231229114145_create_exercises.rb @@ -0,0 +1,11 @@ +class CreateExercises < ActiveRecord::Migration[7.1] + def change + create_table :exercises do |t| + t.references :exercise_type, null: false, foreign_key: true + t.time :at + t.float :amount, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3afa1f7..3bb4496 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[7.1].define(version: 2023_12_29_112847) do +ActiveRecord::Schema[7.1].define(version: 2023_12_29_114145) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -70,6 +70,15 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_29_112847) do t.datetime "updated_at", null: false end + create_table "exercises", force: :cascade do |t| + t.bigint "exercise_type_id", null: false + t.time "at" + t.float "amount", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["exercise_type_id"], name: "index_exercises_on_exercise_type_id" + end + create_table "foods", force: :cascade do |t| t.text "name", null: false t.datetime "created_at", null: false @@ -119,5 +128,6 @@ ActiveRecord::Schema[7.1].define(version: 2023_12_29_112847) 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 "exercises", "exercise_types" add_foreign_key "microposts", "users" end diff --git a/test/fixtures/exercises.yml b/test/fixtures/exercises.yml new file mode 100644 index 0000000..2adc35f --- /dev/null +++ b/test/fixtures/exercises.yml @@ -0,0 +1,9 @@ +one: + exercise_type: running + at: 2023-12-29 11:41:45 + amount: 5 + +two: + exercise_type: cycling + at: 2023-12-29 11:41:45 + amount: 10.5