From 7615febc5d6d49f956894ec3d0776244bcf0405f Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Fri, 29 Dec 2023 11:27:45 +0000 Subject: [PATCH] Add food --- app/models/food.rb | 3 +++ config/database.yml | 7 +++++-- db/migrate/20231229112620_create_foods.rb | 9 +++++++++ db/schema.rb | 8 +++++++- test/fixtures/foods.yml | 5 +++++ 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 app/models/food.rb create mode 100644 db/migrate/20231229112620_create_foods.rb create mode 100644 test/fixtures/foods.yml diff --git a/app/models/food.rb b/app/models/food.rb new file mode 100644 index 0000000..b49d5aa --- /dev/null +++ b/app/models/food.rb @@ -0,0 +1,3 @@ +class Food < ApplicationRecord + validates :name, presence: true +end diff --git a/config/database.yml b/config/database.yml index 05cea76..63bccdb 100644 --- a/config/database.yml +++ b/config/database.yml @@ -3,12 +3,14 @@ default: &default encoding: unicode # For details on connection pooling, see Rails configuration guide # https://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: soc + host: localhost + username: postgres + password: postgres development: <<: *default database: soc_development + username: postgres password: postgres test: @@ -20,3 +22,4 @@ production: database: soc_production password: <%= ENV["POSTGRES_PASSWORD"] %> host: <%= ENV.fetch("DB_HOST") { 'localhost' } %> + username: soc diff --git a/db/migrate/20231229112620_create_foods.rb b/db/migrate/20231229112620_create_foods.rb new file mode 100644 index 0000000..30f983f --- /dev/null +++ b/db/migrate/20231229112620_create_foods.rb @@ -0,0 +1,9 @@ +class CreateFoods < ActiveRecord::Migration[7.1] + def change + create_table :foods do |t| + t.text :name, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 990a8c4..02fed34 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_10_19_192600) do +ActiveRecord::Schema[7.1].define(version: 2023_12_29_112620) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -63,6 +63,12 @@ ActiveRecord::Schema[7.1].define(version: 2023_10_19_192600) do t.index ["user_id"], name: "index_blog_posts_on_user_id" end + create_table "foods", force: :cascade do |t| + t.text "name", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "microposts", force: :cascade do |t| t.bigint "user_id", null: false t.datetime "created_at", null: false diff --git a/test/fixtures/foods.yml b/test/fixtures/foods.yml new file mode 100644 index 0000000..83d4ef4 --- /dev/null +++ b/test/fixtures/foods.yml @@ -0,0 +1,5 @@ +one: + name: Pizza + +two: + name: Banana