2017-05-04 22:15:32 +08:00
|
|
|
require 'column_dropper'
|
|
|
|
|
2014-05-12 11:31:33 +08:00
|
|
|
# fix any bust caches post initial migration
|
2016-10-25 16:43:57 +08:00
|
|
|
ActiveRecord::Base.send(:subclasses).each { |m| m.reset_column_information }
|
2014-05-12 11:31:33 +08:00
|
|
|
|
2017-10-12 17:43:58 +08:00
|
|
|
SiteSetting.refresh!
|
2016-05-30 11:59:16 +08:00
|
|
|
uncat_id = SiteSetting.uncategorized_category_id
|
|
|
|
uncat_id = -1 unless Numeric === uncat_id
|
|
|
|
|
|
|
|
if uncat_id == -1 || !Category.exists?(uncat_id)
|
2013-10-25 07:31:33 +08:00
|
|
|
puts "Seeding uncategorized category!"
|
|
|
|
|
2014-07-10 23:28:49 +08:00
|
|
|
result = Category.exec_sql "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
|
|
|
|
name = 'Uncategorized'
|
2016-10-25 16:43:57 +08:00
|
|
|
name << SecureRandom.hex if result.count > 0
|
2013-10-25 07:31:33 +08:00
|
|
|
|
|
|
|
result = Category.exec_sql "INSERT INTO categories
|
2014-08-26 20:25:23 +08: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}' )
|
2013-10-25 07:31:33 +08:00
|
|
|
RETURNING id
|
|
|
|
"
|
|
|
|
category_id = result[0]["id"].to_i
|
|
|
|
|
2014-01-02 08:08:23 +08:00
|
|
|
Category.exec_sql "DELETE FROM site_settings where name = 'uncategorized_category_id'"
|
2013-10-25 07:31:33 +08:00
|
|
|
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
|
2016-12-13 09:10:27 +08:00
|
|
|
|
2017-05-04 22:15:32 +08:00
|
|
|
ColumnDropper.drop(
|
|
|
|
table: 'categories',
|
2018-02-22 06:56:18 +08:00
|
|
|
after_migration: 'AddSuppressFromLatestToCategories',
|
|
|
|
columns: ['logo_url', 'background_url', 'suppress_from_homepage'],
|
2017-07-28 09:20:09 +08:00
|
|
|
on_drop: ->() {
|
2017-05-04 22:15:32 +08:00
|
|
|
STDERR.puts 'Removing superflous categories columns!'
|
|
|
|
}
|
|
|
|
)
|