Class: CreateHasMedia

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/active_record/templates/migration.rb

Class Method Summary collapse

Class Method Details

.downObject



32
33
34
35
# File 'lib/generators/active_record/templates/migration.rb', line 32

def self.down
  drop_table :media
  drop_table :media_links
end

.upObject



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
# File 'lib/generators/active_record/templates/migration.rb', line 2

def self.up
  create_table :media do |t|
    t.integer  :width
    t.integer  :height
    t.integer  :size
    t.string   :content_type  # required
    t.string   :url
    t.string   :filename      # required
    t.string   :thumbnail
    t.integer  :encode_status # required
    t.string   :type          # required
    t.string   :status
    t.string   :context       # required
    t.string   :file          # used by carrierwave
    t.timestamps
  end
  add_index :media, :encode_status
  add_index :media, [:type, :context]

  create_table :media_links do |t|
    t.integer :medium_id     # required
    t.integer :mediated_id   # required
    t.string  :mediated_type # required

    t.timestamps
  end
  add_index :media_links, :medium_id
  add_index :media_links, [:mediated_id, :mediated_type]
end