Skip to content

Commit

Permalink
adjust data structure for movies / crews
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack Siri committed May 1, 2015
1 parent 2fd7929 commit b92af6e
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 13 deletions.
4 changes: 1 addition & 3 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def initialize(msg = "That Relationship Type doesn't exist")

def add_many(type, data)
if type.in? ['Genre', 'Crew']
type_plural = type.downcase.pluralize

self.send("#{type_plural}=", data.map do |g|
self.send("#{type.downcase.pluralize}=", data.map do |g|
type.classify.constantize.where(name: g).first_or_create!
end)
else
Expand Down
4 changes: 4 additions & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Role < ActiveRecord::Base
belongs_to :movie
belongs_to :crew
end
10 changes: 10 additions & 0 deletions db/migrate/20150501101641_add_fields_to_movies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddFieldsToMovies < ActiveRecord::Migration
def change
add_column :movies, :country, :string
add_column :movies, :year, :integer
add_column :movies, :review, :float
add_column :movies, :rating, :string
add_column :movies, :runtime, :integer
add_column :movies, :language, :string
end
end
13 changes: 13 additions & 0 deletions db/migrate/20150501102555_create_roles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateRoles < ActiveRecord::Migration
def change
create_table :roles do |t|
t.references :movie, index: true
t.references :crew, index: true
t.string :job

t.timestamps null: false
end
add_foreign_key :roles, :movies
add_foreign_key :roles, :crews
end
end
5 changes: 5 additions & 0 deletions db/migrate/20150501102639_drop_crews_movies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DropCrewsMovies < ActiveRecord::Migration
def change
drop_table :crews_movies
end
end
5 changes: 5 additions & 0 deletions db/migrate/20150501104039_add_release_date_to_movies.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReleaseDateToMovies < ActiveRecord::Migration
def change
add_column :movies, :release_date, :date
end
end
30 changes: 21 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150501072034) do
ActiveRecord::Schema.define(version: 20150501104039) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -23,14 +23,6 @@
t.datetime "updated_at", null: false
end

create_table "crews_movies", id: false, force: :cascade do |t|
t.integer "crew_id"
t.integer "movie_id"
end

add_index "crews_movies", ["crew_id"], name: "index_crews_movies_on_crew_id", using: :btree
add_index "crews_movies", ["movie_id"], name: "index_crews_movies_on_movie_id", using: :btree

create_table "genres", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
Expand All @@ -48,8 +40,28 @@
create_table "movies", force: :cascade do |t|
t.string "name"
t.text "synopsis"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "country"
t.integer "year"
t.float "review"
t.string "rating"
t.integer "runtime"
t.string "language"
t.date "release_date"
end

create_table "roles", force: :cascade do |t|
t.integer "movie_id"
t.integer "crew_id"
t.string "job"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "roles", ["crew_id"], name: "index_roles_on_crew_id", using: :btree
add_index "roles", ["movie_id"], name: "index_roles_on_movie_id", using: :btree

add_foreign_key "roles", "crews"
add_foreign_key "roles", "movies"
end
7 changes: 6 additions & 1 deletion lib/tasks/omdb.thor
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'thor'
require File.expand_path('config/environment.rb')

class Omdb < Thor
def import
movies = Sequel.connect('postgres://zacksiri@localhost:5432/omdb')[:movies]
movies.each do |movie|

Movie.create do |m|
m.name = movie[:Title]
m.synopsis = movie[:FullPlot] unless movie[:FullPlot] == 'N/A'
m.year =
end
end
end
end
11 changes: 11 additions & 0 deletions test/fixtures/roles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
movie_id:
crew_id:
job: MyString

two:
movie_id:
crew_id:
job: MyString
7 changes: 7 additions & 0 deletions test/models/role_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class RoleTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit b92af6e

Please sign in to comment.