-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmdb.rb
106 lines (88 loc) · 3.89 KB
/
kmdb.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# In this assignment, you'll be using the domain model from hw1 (found in the hw1-solution.sql file)
# to create the database structure for "KMDB" (the Kellogg Movie Database).
# The end product will be a report that prints the movies and the top-billed
# cast for each movie in the database.
# To run this file, run the following command at your terminal prompt:
# `rails runner kmdb.rb`
# Requirements/assumptions
#
# - There will only be three movies in the database – the three films
# that make up Christopher Nolan's Batman trilogy.
# - Movie data includes the movie title, year released, MPAA rating,
# and studio.
# - There are many studios, and each studio produces many movies, but
# a movie belongs to a single studio.
# - An actor can be in multiple movies.
# - Everything you need to do in this assignment is marked with TODO!
# Rubric
#
# There are three deliverables for this assignment, all delivered within
# this repository and submitted via GitHub and Canvas:
# - Generate the models and migration files to match the domain model from hw1.
# Table and columns should match the domain model. Execute the migration
# files to create the tables in the database. (5 points)
# - Insert the "Batman" sample data using ruby code. Do not use hard-coded ids.
# Delete any existing data beforehand so that each run of this script does not
# create duplicate data. (5 points)
# - Query the data and loop through the results to display output similar to the
# sample "report" below. (10 points)
# Submission
#
# - "Use this template" to create a brand-new "hw2" repository in your
# personal GitHub account, e.g. https://github.com/<USERNAME>/hw2
# - Do the assignment, committing and syncing often
# - When done, commit and sync a final time before submitting the GitHub
# URL for the finished "hw2" repository as the "Website URL" for the
# Homework 2 assignment in Canvas
# Successful sample output is as shown:
# Movies
# ======
# Batman Begins 2005 PG-13 Warner Bros.
# The Dark Knight 2008 PG-13 Warner Bros.
# The Dark Knight Rises 2012 PG-13 Warner Bros.
# Top Cast
# ========
# Batman Begins Christian Bale Bruce Wayne
# Batman Begins Michael Caine Alfred
# Batman Begins Liam Neeson Ra's Al Ghul
# Batman Begins Katie Holmes Rachel Dawes
# Batman Begins Gary Oldman Commissioner Gordon
# The Dark Knight Christian Bale Bruce Wayne
# The Dark Knight Heath Ledger Joker
# The Dark Knight Aaron Eckhart Harvey Dent
# The Dark Knight Michael Caine Alfred
# The Dark Knight Maggie Gyllenhaal Rachel Dawes
# The Dark Knight Rises Christian Bale Bruce Wayne
# The Dark Knight Rises Gary Oldman Commissioner Gordon
# The Dark Knight Rises Tom Hardy Bane
# The Dark Knight Rises Joseph Gordon-Levitt John Blake
# The Dark Knight Rises Anne Hathaway Selina Kyle
# Delete existing data, so you'll start fresh each time this script is run.
# Use `Model.destroy_all` code.
# TODO!
studios.destroy_all
movies.destroy_all
actors.destroy_all
roles.destroy_all
# Generate models and tables, according to the domain model.
# TODO!
rails generate model Movie title:string year:integer rating:string studio:references
rails generate model Studio name:string
rails generate model Actor name:string
rails db:migrate
# Insert data into the database that reflects the sample data shown above.
# Do not use hard-coded foreign key IDs.
# TODO!
# Prints a header for the movies output
puts "Movies"
puts "======"
puts ""
# Query the movies data and loop through the results to display the movies output.
# TODO!
# Prints a header for the cast output
puts ""
puts "Top Cast"
puts "========"
puts ""
# Query the cast data and loop through the results to display the cast output for each movie.
# TODO!