Class: RocketCmsCreateNews

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/rocket_cms/templates/migration_news.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
# File 'lib/generators/rocket_cms/templates/migration_news.rb', line 2

def change
  create_table :news do |t|
    t.boolean :enabled, default: true, null: false
    t.timestamp :time, null: false

    if RocketCMS.config.localize
      t.column :name_translations, 'hstore', default: {}
      t.column :excerpt_translations, 'hstore', default: {}
      t.column :content_translations, 'hstore', default: {}
    else
      t.string :name, null: false
      t.text :excerpt
      t.text :content
    end

    t.string :slug, null: false
    if RocketCMS.shrine?
      t.jsonb :image_data
    elsif RocketCMS.paperclip?
      t.attachment :image
    end
    t.timestamps
  end

  add_index :news, :slug, unique: true
  add_index :news, [:enabled, :time]
end