Skip to content

Commit

Permalink
add db setup command file
Browse files Browse the repository at this point in the history
  • Loading branch information
jasylwong committed Feb 28, 2020
1 parent 26f089f commit a9b4386
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
4 changes: 2 additions & 2 deletions db/migrate/20200224210239_create_bookings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CreateBookings < ActiveRecord::Migration[6.0]
def change
create_table :bookings do |t|
t.date :booking_date
t.references :users, foreign_key: true
t.references :spaces, foreign_key: true
t.references :user, foreign_key: true
t.references :space, foreign_key: true
t.boolean :confirmed
end
end
Expand Down
12 changes: 6 additions & 6 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

create_table "bookings", force: :cascade do |t|
t.date "booking_date"
t.bigint "users_id"
t.bigint "spaces_id"
t.bigint "user_id"
t.bigint "space_id"
t.boolean "confirmed"
t.index ["spaces_id"], name: "index_bookings_on_spaces_id"
t.index ["users_id"], name: "index_bookings_on_users_id"
t.index ["space_id"], name: "index_bookings_on_space_id"
t.index ["user_id"], name: "index_bookings_on_user_id"
end

create_table "spaces", force: :cascade do |t|
Expand All @@ -42,7 +42,7 @@
t.index ["email"], name: "index_users_on_email", unique: true
end

add_foreign_key "bookings", "spaces", column: "spaces_id"
add_foreign_key "bookings", "users", column: "users_id"
add_foreign_key "bookings", "spaces"
add_foreign_key "bookings", "users"
add_foreign_key "spaces", "users"
end
41 changes: 41 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# User seeds -----------------------------------------
user_list = [
["Jason", "[email protected]", "password"],
["Jack", "[email protected]", "PASSWORD"],
["Megan", "[email protected]", "megz1234"],
["Dafna", "[email protected]", "test!!"],
["Ziad", "[email protected]", "2nd_test"]
]

user_list.each do |name, email, password|
User.create( name: name, email: email, password: password)
end

# Space seeds -----------------------------------------
space_list = [
["Casa Bonita", "Muy buena", 50, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 1)],
["Space 2", "Great!", 45, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-02-12", "2020-04-13", User.find_by(id: 1)],
["Rad resort", "Totally rad", 30, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 1)],
["Happy house", "Very happy", 75, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 2)],
["Cat Castle", "Lots of cats", 99.99, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 2)],
["Misty Mountain", "Somewhat foggy", 13, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 3)],
["Fab flat", "Ab fab", 66, "https://si.wsj.net/public/resources/images/B3-DM067_RIGHTS_IM_20190319162958.jpg", "2020-03-11", "2020-04-11", User.find_by(id: 4)]
]

space_list.each do |name, description, price, url, from, to, user |
Space.create( name: name, description: description, price: price, photo_url: url, available_from: from, available_to: to, user: user)
end

# Booking seeds -----------------------------------------
booking_list = [
["2020-04-12", User.find_by(id: 5), Space.find_by(id: 1), "false"],
["2020-05-05", User.find_by(id: 5), Space.find_by(id: 2), "false"],
["2020-06-28", User.find_by(id: 1), Space.find_by(id: 4), "false"],
["2021-03-01", User.find_by(id: 2), Space.find_by(id: 3), "false"],
["2020-11-19", User.find_by(id: 4), Space.find_by(id: 2), "false"],
["2020-08-25", User.find_by(id: 3), Space.find_by(id: 6), "true"]
]

booking_list.each do |date, user, space, confirmed|
Booking.create( booking_date: date, user: user, space_id: space, confirmed: confirmed)
end
6 changes: 6 additions & 0 deletions db/setup.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cd /Users/student/Programming/Makers/Projects/MakersBnB

RACK_ENV=development rake db:drop
RACK_ENV=development rake db:create
RACK_ENV=development rake db:migrate
RACK_ENV=development rake db:seed

0 comments on commit a9b4386

Please sign in to comment.