mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #2297 from ligthyear/custom-fields
Custom fields for Topic, Category, Post and Group
This commit is contained in:
28
db/migrate/20140425125742_add_custom_fields.rb
Normal file
28
db/migrate/20140425125742_add_custom_fields.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class AddCustomFields < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :category_custom_fields do |t|
|
||||
t.integer :category_id, null: false
|
||||
t.string :name, limit: 256, null: false
|
||||
t.text :value
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :group_custom_fields do |t|
|
||||
t.integer :group_id, null: false
|
||||
t.string :name, limit: 256, null: false
|
||||
t.text :value
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :post_custom_fields do |t|
|
||||
t.integer :post_id, null: false
|
||||
t.string :name, limit: 256, null: false
|
||||
t.text :value
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :category_custom_fields, [:category_id, :name]
|
||||
add_index :group_custom_fields, [:group_id, :name]
|
||||
add_index :post_custom_fields, [:post_id, :name]
|
||||
end
|
||||
end
|
||||
21
db/migrate/20140425135354_add_topic_custom_fields.rb
Normal file
21
db/migrate/20140425135354_add_topic_custom_fields.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class AddTopicCustomFields < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :topic_custom_fields do |t|
|
||||
t.integer :topic_id, null: false
|
||||
t.string :name, limit: 256, null: false
|
||||
t.text :value
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :topic_custom_fields, [:topic_id, :name]
|
||||
|
||||
# migrate meta_data into custom fields
|
||||
execute <<-SQL
|
||||
INSERT INTO topic_custom_fields(topic_id, name, value)
|
||||
SELECT id, (each(meta_data)).key, (each(meta_data)).value
|
||||
FROM topics WHERE meta_data <> ''
|
||||
SQL
|
||||
|
||||
remove_column :topics, :meta_data
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user