2017-08-30 23:06:56 -05:00
|
|
|
class AddStaffCategory < ActiveRecord::Migration[4.2]
|
2014-02-27 16:38:01 -06:00
|
|
|
def up
|
2015-11-14 15:11:22 -06:00
|
|
|
return if Rails.env.test?
|
|
|
|
|
2015-11-19 15:36:59 -06:00
|
|
|
I18n.overrides_disabled do
|
2018-06-19 01:13:14 -05:00
|
|
|
result = DB.exec "SELECT 1 FROM site_settings where name = 'staff_category_id'"
|
|
|
|
if result == 0
|
2014-02-27 16:38:01 -06:00
|
|
|
description = I18n.t('staff_category_description')
|
|
|
|
name = I18n.t('staff_category_name')
|
2015-05-28 01:55:23 -05:00
|
|
|
|
2018-06-19 01:13:14 -05:00
|
|
|
if DB.exec("SELECT 1 FROM categories where name ilike :name", name: name) == 0
|
2015-05-28 01:55:23 -05:00
|
|
|
|
2018-06-19 01:13:14 -05:00
|
|
|
result = DB.query_single "INSERT INTO categories
|
2014-05-16 10:33:44 -05:00
|
|
|
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
|
2018-08-24 13:18:14 -05:00
|
|
|
VALUES (:name, 'E45735', 'FFFFFF', now(), now(), -1, '', :description, true, 2)
|
2015-05-28 01:55:23 -05:00
|
|
|
RETURNING id", name: name, description: description
|
|
|
|
|
2018-06-19 01:13:14 -05:00
|
|
|
category_id = result.first.to_i
|
2014-02-27 16:38:01 -06:00
|
|
|
|
2018-06-19 01:13:14 -05:00
|
|
|
DB.exec "UPDATE categories SET slug=:slug WHERE id=:category_id",
|
2015-05-28 01:55:23 -05:00
|
|
|
slug: Slug.for(name, "#{category_id}-category"), category_id: category_id
|
|
|
|
|
2018-06-19 01:13:14 -05:00
|
|
|
DB.exec "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
2015-05-28 01:55:23 -05:00
|
|
|
VALUES ('staff_category_id', 3, #{category_id.to_i}, now(), now())"
|
2014-02-27 16:38:01 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
# Do nothing
|
|
|
|
end
|
|
|
|
end
|