Class: EnjoyGalleryCreateGallery

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/enjoy/gallery/migrations/templates/migration_gallery.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



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
# File 'lib/generators/enjoy/gallery/migrations/templates/migration_gallery.rb', line 2

def change
  ########### c #################
  create_table :enjoy_gallery_gallery_images do |t|
    t.integer :gallery_id
    t.integer :enjoy_gallery_imagable_id
    t.string :enjoy_gallery_imagable_type

    t.boolean :enabled, default: true, null: false

    if Enjoy::Gallery.config.localize
      t.column :name_translations, 'hstore', default: {}
    else
      t.string :name, null: false
    end

    t.attachment :image
    t.timestamps
  end

  add_index :enjoy_gallery_gallery_images, [:enabled]
  add_index :enjoy_gallery_gallery_images, [:gallery_id]
  add_index :enjoy_gallery_gallery_images, [:enjoy_gallery_imagable_id, :enjoy_gallery_imagable_type]



  ########### Galleries #################
  create_table :enjoy_gallery_gallery do |t|
    t.boolean :enabled, default: true, null: false

    if Enjoy::Gallery.config.localize
      t.column :name_translations, 'hstore', default: {}
    else
      t.string :name, null: false
    end

    t.integer :parent_id
    t.integer :lft
    t.integer :rgt
    t.integer :depth

    t.string :slug, null: false
    t.attachment :image
    t.timestamps
  end

  add_index :enjoy_gallery_galleries, :slug, unique: true
  add_index :enjoy_gallery_galleries, [:enabled, :lft]

end