Class: HancockNewsCreateNews

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/hancock/news/migrations/templates/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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/generators/hancock/news/migrations/templates/news.rb', line 2

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

    t.boolean :published, default: true, null: false
    t.timestamp :publicate_time, null: false
    t.boolean :pinned, default: true, null: false

    if Hancock::News.config.localize
      t.column :name_translations, 'hstore', default: {}
      t.column :excerpt_html_translations, 'hstore', default: {}
      t.column :excerpt_clear_translations, 'hstore', default: {}
      t.column :content_html_translations, 'hstore', default: {}
      t.column :content_clear_translations, 'hstore', default: {}
    else
      t.string :name, null: false
      t.text :excerpt_html
      t.boolean :excerpt_clear, default: true, null: false
      t.text :content_html
      t.boolean :content_clear, default: true, null: false
    end

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

  add_index :hancock_news_news, :slug, unique: true
  add_index :hancock_news_news, [:enabled, :time]



  ######### news images ################
  # create_table :hancock_news_news_images do |t|
  #   t.boolean :enabled, default: true, null: false
  #   t.integer :hancock_news_news_id
  #
  #   if Hancock::News.config.localize
  #     t.column :name_translations, 'hstore', default: {}
  #   else
  #     t.string :name, null: false
  #   end
  #
  #   t.attachment :image
  #   t.timestamps
  # end
  #
  # add_index :hancock_news_news_images, [:enabled, :hancock_news_news_id]




  ########### news_categories #################
  create_table :hancock_news_categories do |t|
    t.boolean :enabled, default: true, null: false

    if Hancock::News.config.localize
      t.column :name_translations, 'hstore', default: {}
      t.column :excerpt_html_translations, 'hstore', default: {}
      t.column :excerpt_clear_translations, 'hstore', default: {}
      t.column :content_html_translations, 'hstore', default: {}
      t.column :content_clear_translations, 'hstore', default: {}
    else
      t.string :name, null: false
      t.text :excerpt_html
      t.boolean :excerpt_clear, default: true, null: false
      t.text :content_html
      t.boolean :content_clear, default: true, 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 :hancock_news_categories, :slug, unique: true
  add_index :hancock_news_categories, [:enabled, :lft]



  ######### news <-> news_category join table #############

  create_join_table :hancock_news_news, :hancock_news_categories, table_name: :hancock_news_news_categories

  add_foreign_key(:hancock_news_news_categories, :hancock_news_news, dependent: :delete)
  add_foreign_key(:hancock_news_news_categories, :hancock_news_categories, dependent: :delete)
end