Merge pull request #2297 from ligthyear/custom-fields

Custom fields for Topic, Category, Post and Group
This commit is contained in:
Sam
2014-04-30 13:15:50 +10:00
17 changed files with 453 additions and 33 deletions

View 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

View 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