2018-03-20 03:20:50 -04:00
|
|
|
require 'migration/column_dropper'
|
2017-05-04 10:15:32 -04:00
|
|
|
|
2014-05-11 23:31:33 -04:00
|
|
|
# fix any bust caches post initial migration
|
2016-10-25 04:43:57 -04:00
|
|
|
ActiveRecord::Base.send(:subclasses).each { |m| m.reset_column_information }
|
2014-05-11 23:31:33 -04:00
|
|
|
|
2017-10-12 05:43:58 -04:00
|
|
|
SiteSetting.refresh!
|
2016-05-29 23:59:16 -04:00
|
|
|
uncat_id = SiteSetting.uncategorized_category_id
|
|
|
|
uncat_id = -1 unless Numeric === uncat_id
|
|
|
|
|
|
|
|
if uncat_id == -1 || !Category.exists?(uncat_id)
|
2013-10-24 19:31:33 -04:00
|
|
|
puts "Seeding uncategorized category!"
|
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
count = DB.exec "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
|
2014-07-10 11:28:49 -04:00
|
|
|
name = 'Uncategorized'
|
2018-06-19 02:13:14 -04:00
|
|
|
name << SecureRandom.hex if count > 0
|
2013-10-24 19:31:33 -04:00
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
result = DB.query_single "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)
|
2018-08-24 14:18:14 -04:00
|
|
|
VALUES ('#{name}', '0088CC', 'uncategorized', '', 'FFFFFF', -1, now(), now(), 1, '#{name.downcase}' )
|
2013-10-24 19:31:33 -04:00
|
|
|
RETURNING id
|
|
|
|
"
|
2018-06-19 02:13:14 -04:00
|
|
|
category_id = result.first.to_i
|
2013-10-24 19:31:33 -04:00
|
|
|
|
2018-06-19 02:13:14 -04:00
|
|
|
DB.exec "DELETE FROM site_settings where name = 'uncategorized_category_id'"
|
|
|
|
DB.exec "INSERT INTO site_settings(name, data_type, value, created_at, updated_at)
|
2013-10-24 19:31:33 -04:00
|
|
|
VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())"
|
|
|
|
end
|