Permalink
Browse files

Added models, migrations, and seed data

  • Loading branch information...
mattboldt committed Dec 27, 2018
1 parent 6b4dae1 commit 2dfe3298f153d2d43ed1e602d4ecefd23cc0462c
Showing with 66 additions and 7 deletions.
  1. +1 −0 Gemfile
  2. +3 −0 Gemfile.lock
  3. +3 −0 app/models/book.rb
  4. +3 −0 app/models/user.rb
  5. +10 −0 db/migrate/20181227042907_create_users.rb
  6. +10 −0 db/migrate/20181227042909_create_books.rb
  7. +30 −0 db/schema.rb
  8. +6 −7 db/seeds.rb
@@ -31,6 +31,7 @@ gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'faker'
end

group :development do
@@ -50,6 +50,8 @@ GEM
concurrent-ruby (1.1.4)
crass (1.0.4)
erubi (1.8.0)
faker (1.8.7)
i18n (>= 0.7)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
@@ -135,6 +137,7 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.1.0)
byebug
faker
listen (>= 3.0.5, < 3.2)
puma (~> 3.11)
rails (~> 5.2.2)
@@ -0,0 +1,3 @@
class Book < ApplicationRecord
belongs_to :user
end
@@ -0,0 +1,3 @@
class User < ApplicationRecord
has_many :books
end
@@ -0,0 +1,10 @@
class CreateUsers < ActiveRecord::Migration[5.2]
def change
create_table :users do |t|
t.string :email
t.string :name

t.timestamps
end
end
end
@@ -0,0 +1,10 @@
class CreateBooks < ActiveRecord::Migration[5.2]
def change
create_table :books do |t|
t.belongs_to :user, foreign_key: true
t.string :title

t.timestamps
end
end
end
@@ -0,0 +1,30 @@
# 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.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_12_27_042909) do

create_table "books", force: :cascade do |t|
t.integer "user_id"
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_books_on_user_id"
end

create_table "users", force: :cascade do |t|
t.string "email"
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

end
@@ -1,7 +1,6 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
5.times do
user = User.create(name: Faker::Name.name, email: Faker::Internet.email)
5.times do
user.books.create(title: Faker::Book.title)
end
end

0 comments on commit 2dfe329

Please sign in to comment.