From 2b5e347a97306386e4b367e845ed8be0b1475241 Mon Sep 17 00:00:00 2001 From: Nahom Date: Mon, 26 Jun 2023 15:14:58 +0300 Subject: [PATCH 1/5] Setup database username and password --- config/database.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/database.yml b/config/database.yml index b4f9972..269f1d9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -20,6 +20,8 @@ default: &default # 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: postgres + password: <%= ENV["DB_PASSWORD"] %> development: <<: *default From 4b19e0635ecd87c681eb6d014fe5daa06cfae039 Mon Sep 17 00:00:00 2001 From: Nahom Date: Mon, 26 Jun 2023 15:36:56 +0300 Subject: [PATCH 2/5] Create users table --- db/migrate/20230626122939_create_users.rb | 9 +++++++++ db/schema.rb | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 db/migrate/20230626122939_create_users.rb create mode 100644 db/schema.rb diff --git a/db/migrate/20230626122939_create_users.rb b/db/migrate/20230626122939_create_users.rb new file mode 100644 index 0000000..dd02b09 --- /dev/null +++ b/db/migrate/20230626122939_create_users.rb @@ -0,0 +1,9 @@ +class CreateUsers < ActiveRecord::Migration[7.0] + def change + create_table :users do |t| + t.string :name + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..280349d --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,23 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[7.0].define(version: 2023_06_26_122939) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + + create_table "users", force: :cascade do |t| + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end From ed0650fd352135fc203b4660739d1142894f3b5c Mon Sep 17 00:00:00 2001 From: Nahom Date: Mon, 26 Jun 2023 15:48:31 +0300 Subject: [PATCH 3/5] Create foods table --- db/migrate/20230626124248_create_foods.rb | 12 ++++++++++++ db/migrate/20230626124654_add_user_ref_to_foods.rb | 5 +++++ db/schema.rb | 14 +++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230626124248_create_foods.rb create mode 100644 db/migrate/20230626124654_add_user_ref_to_foods.rb diff --git a/db/migrate/20230626124248_create_foods.rb b/db/migrate/20230626124248_create_foods.rb new file mode 100644 index 0000000..b3e9988 --- /dev/null +++ b/db/migrate/20230626124248_create_foods.rb @@ -0,0 +1,12 @@ +class CreateFoods < ActiveRecord::Migration[7.0] + def change + create_table :foods do |t| + t.string :name + t.string :measurement_unit + t.decimal :price + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20230626124654_add_user_ref_to_foods.rb b/db/migrate/20230626124654_add_user_ref_to_foods.rb new file mode 100644 index 0000000..a980c31 --- /dev/null +++ b/db/migrate/20230626124654_add_user_ref_to_foods.rb @@ -0,0 +1,5 @@ +class AddUserRefToFoods < ActiveRecord::Migration[7.0] + def change + add_reference :foods, :user, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 280349d..eb13aac 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,14 +10,26 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_06_26_122939) do +ActiveRecord::Schema[7.0].define(version: 2023_06_26_124654) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "foods", force: :cascade do |t| + t.string "name" + t.string "measurement_unit" + t.decimal "price" + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id", null: false + t.index ["user_id"], name: "index_foods_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false end + add_foreign_key "foods", "users" end From 844be59c52186b6e4e0d049e43a9a68266f95141 Mon Sep 17 00:00:00 2001 From: Nahom Date: Mon, 26 Jun 2023 15:57:55 +0300 Subject: [PATCH 4/5] Create recipes table --- db/migrate/20230626125519_create_recipes.rb | 13 +++++++++++++ .../20230626125630_add_user_ref_to_recipes.rb | 5 +++++ db/schema.rb | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230626125519_create_recipes.rb create mode 100644 db/migrate/20230626125630_add_user_ref_to_recipes.rb diff --git a/db/migrate/20230626125519_create_recipes.rb b/db/migrate/20230626125519_create_recipes.rb new file mode 100644 index 0000000..42dea56 --- /dev/null +++ b/db/migrate/20230626125519_create_recipes.rb @@ -0,0 +1,13 @@ +class CreateRecipes < ActiveRecord::Migration[7.0] + def change + create_table :recipes do |t| + t.string :name + t.integer :preparation_time + t.integer :cooking_time + t.text :description + t.boolean :public + + t.timestamps + end + end +end diff --git a/db/migrate/20230626125630_add_user_ref_to_recipes.rb b/db/migrate/20230626125630_add_user_ref_to_recipes.rb new file mode 100644 index 0000000..adba562 --- /dev/null +++ b/db/migrate/20230626125630_add_user_ref_to_recipes.rb @@ -0,0 +1,5 @@ +class AddUserRefToRecipes < ActiveRecord::Migration[7.0] + def change + add_reference :recipes, :user, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index eb13aac..450a5aa 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.0].define(version: 2023_06_26_124654) do +ActiveRecord::Schema[7.0].define(version: 2023_06_26_125630) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,6 +25,18 @@ t.index ["user_id"], name: "index_foods_on_user_id" end + create_table "recipes", force: :cascade do |t| + t.string "name" + t.integer "preparation_time" + t.integer "cooking_time" + t.text "description" + t.boolean "public" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "user_id", null: false + t.index ["user_id"], name: "index_recipes_on_user_id" + end + create_table "users", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -32,4 +44,5 @@ end add_foreign_key "foods", "users" + add_foreign_key "recipes", "users" end From 14a431f05fe63f0e3425338e472358fb37e94d91 Mon Sep 17 00:00:00 2001 From: Nahom Date: Mon, 26 Jun 2023 16:04:43 +0300 Subject: [PATCH 5/5] Create recipe_foods table --- db/migrate/20230626130009_create_recipe_foods.rb | 9 +++++++++ ...0230626130114_add_recipe_ref_to_recipe_foods.rb | 5 +++++ .../20230626130217_add_food_ref_to_recipe_foods.rb | 5 +++++ db/schema.rb | 14 +++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20230626130009_create_recipe_foods.rb create mode 100644 db/migrate/20230626130114_add_recipe_ref_to_recipe_foods.rb create mode 100644 db/migrate/20230626130217_add_food_ref_to_recipe_foods.rb diff --git a/db/migrate/20230626130009_create_recipe_foods.rb b/db/migrate/20230626130009_create_recipe_foods.rb new file mode 100644 index 0000000..9b20a2d --- /dev/null +++ b/db/migrate/20230626130009_create_recipe_foods.rb @@ -0,0 +1,9 @@ +class CreateRecipeFoods < ActiveRecord::Migration[7.0] + def change + create_table :recipe_foods do |t| + t.integer :quantity + + t.timestamps + end + end +end diff --git a/db/migrate/20230626130114_add_recipe_ref_to_recipe_foods.rb b/db/migrate/20230626130114_add_recipe_ref_to_recipe_foods.rb new file mode 100644 index 0000000..06700de --- /dev/null +++ b/db/migrate/20230626130114_add_recipe_ref_to_recipe_foods.rb @@ -0,0 +1,5 @@ +class AddRecipeRefToRecipeFoods < ActiveRecord::Migration[7.0] + def change + add_reference :recipe_foods, :recipe, null: false, foreign_key: true + end +end diff --git a/db/migrate/20230626130217_add_food_ref_to_recipe_foods.rb b/db/migrate/20230626130217_add_food_ref_to_recipe_foods.rb new file mode 100644 index 0000000..b1d4e12 --- /dev/null +++ b/db/migrate/20230626130217_add_food_ref_to_recipe_foods.rb @@ -0,0 +1,5 @@ +class AddFoodRefToRecipeFoods < ActiveRecord::Migration[7.0] + def change + add_reference :recipe_foods, :food, null: false, foreign_key: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 450a5aa..0603b64 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.0].define(version: 2023_06_26_125630) do +ActiveRecord::Schema[7.0].define(version: 2023_06_26_130217) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -25,6 +25,16 @@ t.index ["user_id"], name: "index_foods_on_user_id" end + create_table "recipe_foods", force: :cascade do |t| + t.integer "quantity" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.bigint "recipe_id", null: false + t.bigint "food_id", null: false + t.index ["food_id"], name: "index_recipe_foods_on_food_id" + t.index ["recipe_id"], name: "index_recipe_foods_on_recipe_id" + end + create_table "recipes", force: :cascade do |t| t.string "name" t.integer "preparation_time" @@ -44,5 +54,7 @@ end add_foreign_key "foods", "users" + add_foreign_key "recipe_foods", "foods" + add_foreign_key "recipe_foods", "recipes" add_foreign_key "recipes", "users" end