Switch to a single joined table for Videos and Games
[cs356-p2-videostore.git] / db / migrate / 009_rentable_inheritance.rb
1 class RentableInheritance < ActiveRecord::Migration
2   def self.up
3     drop_table :games
4     drop_table :videos
5     drop_table :rentables
6     create_table :rentables do |t|
7       # for the inheritance
8       t.column :type, :string
9
10       # common columns
11       t.column :title, :string
12       t.column :newrelease, :boolean, :default => false
13
14       # video specific
15       t.column :video_genre, :integer
16       t.column :director, :integer
17       t.column :media, :integer
18
19       # game specific
20       t.column :game_genre, :integer
21       t.column :platform, :integer
22     end
23   end
24
25   def self.down
26     create_table :games do |t|
27       t.column :title, :string
28       t.column :platform, :integer
29       t.column :genre, :integer
30       t.column :rentable_id, :integer
31     end
32     
33     create_table :videos do |t|
34       t.column :title, :string
35       t.column :newrelease, :boolean, :default => false
36       t.column :director, :string
37       t.column :genre, :integer
38       t.column :rentable_id, :integer
39     end
40
41     drop_table :rentables
42     create_table :rentables do |t|
43       t.column :rtype, :string
44     end
45   end
46 end