-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
20140227201005_add_staff_category.rb
33 lines (26 loc) · 1.27 KB
/
20140227201005_add_staff_category.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class AddStaffCategory < ActiveRecord::Migration
def up
return if Rails.env.test?
I18n.backend.overrides_disabled do
result = Category.exec_sql "SELECT 1 FROM site_settings where name = 'staff_category_id'"
if result.count == 0
description = I18n.t('staff_category_description')
name = I18n.t('staff_category_name')
if Category.exec_sql("SELECT 1 FROM categories where name ilike :name", name: name).count == 0
result = Category.exec_sql "INSERT INTO categories
(name, color, text_color, created_at, updated_at, user_id, slug, description, read_restricted, position)
VALUES (:name, '283890', 'FFFFFF', now(), now(), -1, '', :description, true, 2)
RETURNING id", name: name, description: description
category_id = result[0]["id"].to_i
Category.exec_sql "UPDATE categories SET slug=:slug WHERE id=:category_id",
slug: Slug.for(name, "#{category_id}-category"), category_id: category_id
execute "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
VALUES ('staff_category_id', 3, #{category_id.to_i}, now(), now())"
end
end
end
end
def down
# Do nothing
end
end