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
|
|
|
|
2013-10-24 19:31:33 -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!"
|
|
|
|
|
2014-07-10 11:28:49 -04:00
|
|
|
result = Category.exec_sql "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
|
|
|
|
name = 'Uncategorized'
|
2016-10-25 04:43:57 -04:00
|
|
|
name << SecureRandom.hex if result.count > 0
|
2013-10-24 19:31:33 -04:00
|
|
|
|
|
|
|
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}' )
|
2013-10-24 19:31:33 -04:00
|
|
|
RETURNING id
|
|
|
|
"
|
|
|
|
category_id = result[0]["id"].to_i
|
|
|
|
|
2014-01-01 19:08:23 -05:00
|
|
|
Category.exec_sql "DELETE FROM site_settings where name = 'uncategorized_category_id'"
|
2013-10-24 19:31:33 -04: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-12 20:10:27 -05:00
|
|
|
|
|
|
|
# 60 minutes after our migration runs we need to exectue this code...
|
2017-01-03 22:56:38 -05:00
|
|
|
duration = Rails.env.production? ? 60 : 0
|
2016-12-12 20:10:27 -05:00
|
|
|
if Category.exec_sql("
|
|
|
|
SELECT 1 FROM schema_migration_details
|
|
|
|
WHERE EXISTS(
|
|
|
|
SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
|
2016-12-15 07:53:10 -05:00
|
|
|
WHERE table_schema = 'public' AND table_name = 'categories' AND column_name = 'logo_url'
|
2016-12-12 20:10:27 -05:00
|
|
|
) AND
|
|
|
|
name = 'AddUploadsToCategories' AND
|
2017-01-03 22:56:38 -05:00
|
|
|
created_at < (current_timestamp at time zone 'UTC' - interval '#{duration} minutes')
|
2016-12-12 20:10:27 -05:00
|
|
|
").to_a.length > 0
|
|
|
|
|
|
|
|
|
|
|
|
Category.transaction do
|
|
|
|
STDERR.puts "Removing superflous category columns!"
|
|
|
|
%w[
|
|
|
|
logo_url
|
|
|
|
background_url
|
|
|
|
].each do |column|
|
|
|
|
Category.exec_sql("ALTER TABLE categories DROP column IF EXISTS #{column}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|