Switch to a single joined table for Videos and Games
[cs356-p2-videostore.git] / db / migrate / 009_rentable_inheritance.rb
diff --git a/db/migrate/009_rentable_inheritance.rb b/db/migrate/009_rentable_inheritance.rb
new file mode 100644 (file)
index 0000000..d0c2593
--- /dev/null
@@ -0,0 +1,46 @@
+class RentableInheritance < ActiveRecord::Migration
+  def self.up
+    drop_table :games
+    drop_table :videos
+    drop_table :rentables
+    create_table :rentables do |t|
+      # for the inheritance
+      t.column :type, :string
+
+      # common columns
+      t.column :title, :string
+      t.column :newrelease, :boolean, :default => false
+
+      # video specific
+      t.column :video_genre, :integer
+      t.column :director, :integer
+      t.column :media, :integer
+
+      # game specific
+      t.column :game_genre, :integer
+      t.column :platform, :integer
+    end
+  end
+
+  def self.down
+    create_table :games do |t|
+      t.column :title, :string
+      t.column :platform, :integer
+      t.column :genre, :integer
+      t.column :rentable_id, :integer
+    end
+    
+    create_table :videos do |t|
+      t.column :title, :string
+      t.column :newrelease, :boolean, :default => false
+      t.column :director, :string
+      t.column :genre, :integer
+      t.column :rentable_id, :integer
+    end
+
+    drop_table :rentables
+    create_table :rentables do |t|
+      t.column :rtype, :string
+    end
+  end
+end