2014-01-22 00:05:46 -05:00
|
|
|
class AddMetaCategory < ActiveRecord::Migration
|
|
|
|
def up
|
|
|
|
unless Rails.env.test?
|
|
|
|
result = Category.exec_sql "SELECT 1 FROM site_settings where name = 'meta_category_id'"
|
|
|
|
if result.count == 0
|
|
|
|
description = I18n.t('meta_category_description')
|
|
|
|
name = I18n.t('meta_category_name')
|
2014-10-14 03:07:59 -04:00
|
|
|
|
|
|
|
if Category.exec_sql("SELECT 1 FROM categories where name ilike :name", name: name).count == 0
|
|
|
|
result = Category.exec_sql "INSERT INTO categories
|
2014-05-16 11:33:44 -04:00
|
|
|
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
|
2014-10-14 03:07:59 -04:00
|
|
|
VALUES (:name, '808281', 'FFFFFF', now(), now(), -1, :slug, :description, true, 1)
|
2015-04-13 10:50:41 -04:00
|
|
|
RETURNING id", name: name, slug: '', description: description
|
2014-10-14 03:07:59 -04:00
|
|
|
|
2014-01-22 00:05:46 -05:00
|
|
|
category_id = result[0]["id"].to_i
|
|
|
|
|
2015-04-13 10:50:41 -04:00
|
|
|
execute "UPDATE categories SET slug='#{Slug.for(name, "#{category_id}-category")}' WHERE id=#{category_id}"
|
2014-01-22 00:05:46 -05:00
|
|
|
execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
|
|
|
VALUES ('meta_category_id', 3, #{category_id}, now(), now())"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# Don't reverse this change. There is so much logic around deleting a category that it's messy
|
|
|
|
# to try to do in sql. The up method will just make sure never to create the category twice.
|
|
|
|
end
|
|
|
|
end
|