discourse/db/fixtures/001_categories.rb

25 lines
1 KiB
Ruby
Raw Normal View History

# fix any bust caches post initial migration
2014-05-14 22:19:53 -04:00
ActiveRecord::Base.send(:subclasses).each{|m| m.reset_column_information}
SiteSetting.refresh!
if SiteSetting.uncategorized_category_id == -1 || !Category.exists?(SiteSetting.uncategorized_category_id)
puts "Seeding uncategorized category!"
2014-07-10 11:28:49 -04:00
result = Category.exec_sql "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
name = 'Uncategorized'
if result.count > 0
name << SecureRandom.hex
end
result = Category.exec_sql "INSERT INTO categories
2014-08-26 08:25:23 -04:00
(name,color,slug,description,text_color, user_id, created_at, updated_at, position, name_lower)
VALUES ('#{name}', 'AB9364', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1, '#{name.downcase}' )
RETURNING id
"
category_id = result[0]["id"].to_i
Category.exec_sql "DELETE FROM site_settings where name = 'uncategorized_category_id'"
Category.exec_sql "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())"
end