2017-08-31 00:06:56 -04:00
|
|
|
class AddLoungeCategory < ActiveRecord::Migration[4.2]
|
2014-01-20 15:49:43 -05:00
|
|
|
def up
|
2015-11-14 16:11:22 -05:00
|
|
|
return if Rails.env.test?
|
|
|
|
|
2015-11-19 16:36:59 -05:00
|
|
|
I18n.overrides_disabled do
|
2018-06-19 02:13:14 -04:00
|
|
|
result = DB.exec "SELECT 1 FROM site_settings where name = 'lounge_category_id'"
|
|
|
|
if result == 0
|
2015-11-14 16:13:02 -05:00
|
|
|
description = I18n.t('vip_category_description')
|
2014-01-20 15:49:43 -05:00
|
|
|
|
2015-11-14 16:13:02 -05:00
|
|
|
default_name = I18n.t('vip_category_name')
|
2018-06-19 02:13:14 -04:00
|
|
|
name = if DB.exec("SELECT 1 FROM categories where name = '#{default_name}'") == 0
|
2014-01-20 15:49:43 -05:00
|
|
|
default_name
|
|
|
|
else
|
|
|
|
"CHANGE_ME"
|
|
|
|
end
|
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
result = DB.query_single "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)
|
2018-08-24 14:18:14 -04:00
|
|
|
VALUES (:name, 'A461EF', '652D90', now(), now(), -1, '', :description, true, 3)
|
2015-05-28 02:55:23 -04:00
|
|
|
RETURNING id", name: name, description: description
|
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
category_id = result.first.to_i
|
2014-01-20 15:49:43 -05:00
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
DB.exec "UPDATE categories SET slug = :slug
|
2015-05-28 02:55:23 -04:00
|
|
|
WHERE id = :category_id",
|
|
|
|
slug: Slug.for(name, "#{category_id}-category"), category_id: category_id
|
|
|
|
|
2014-01-20 15:49:43 -05:00
|
|
|
execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
2015-05-28 02:55:23 -04:00
|
|
|
VALUES ('lounge_category_id', 3, #{category_id.to_i}, now(), now())"
|
2014-01-20 15:49:43 -05:00
|
|
|
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
|