discourse/db/migrate/20120712150500_create_categories.rb

Failed to ignore revisions in .git-blame-ignore-revs.

31 lines
978 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class CreateCategories < ActiveRecord::Migration[4.2]
2013-02-06 03:16:51 +08:00
def up
create_table :categories do |t|
t.string :name, limit: 50, null: false
2018-08-25 02:18:14 +08:00
t.string :color, limit: 6, null: false, default: '0088CC'
2013-02-06 03:16:51 +08:00
t.integer :forum_thread_id, null: true
t.integer :top1_forum_thread_id, null: true
t.integer :top2_forum_thread_id, null: true
t.integer :top1_user_id, null: true
t.integer :top2_user_id, null: true
2013-02-26 00:42:20 +08:00
t.integer :forum_thread_count, null: false, default: 0
2017-08-07 23:48:36 +08:00
t.timestamps null: false
2013-02-06 03:16:51 +08:00
end
add_index :categories, :name, unique: true
add_index :categories, :forum_thread_count
execute "INSERT INTO categories (name, forum_thread_count, created_at, updated_At)
SELECT tag, count(*), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP from forum_threads
WHERE tag IS NOT NULL AND tag <> 'null'
GROUP BY tag"
end
def down
2013-02-26 00:42:20 +08:00
drop_table :categories
2013-02-06 03:16:51 +08:00
end
end