mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 14:49:07 +08:00
5f64fd0a21
Introduce new patterns for direct sql that are safe and fast. MiniSql is not prone to memory bloat that can happen with direct PG usage. It also has an extremely fast materializer and very a convenient API - DB.exec(sql, *params) => runs sql returns row count - DB.query(sql, *params) => runs sql returns usable objects (not a hash) - DB.query_hash(sql, *params) => runs sql returns an array of hashes - DB.query_single(sql, *params) => runs sql and returns a flat one dimensional array - DB.build(sql) => returns a sql builder See more at: https://github.com/discourse/mini_sql
28 lines
1.1 KiB
Ruby
28 lines
1.1 KiB
Ruby
require 'migration/column_dropper'
|
|
|
|
# fix any bust caches post initial migration
|
|
ActiveRecord::Base.send(:subclasses).each { |m| m.reset_column_information }
|
|
|
|
SiteSetting.refresh!
|
|
uncat_id = SiteSetting.uncategorized_category_id
|
|
uncat_id = -1 unless Numeric === uncat_id
|
|
|
|
if uncat_id == -1 || !Category.exists?(uncat_id)
|
|
puts "Seeding uncategorized category!"
|
|
|
|
count = DB.exec "SELECT 1 FROM categories WHERE lower(name) = 'uncategorized'"
|
|
name = 'Uncategorized'
|
|
name << SecureRandom.hex if count > 0
|
|
|
|
result = DB.query_single "INSERT INTO categories
|
|
(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.first.to_i
|
|
|
|
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)
|
|
VALUES ('uncategorized_category_id', 3, #{category_id}, now(), now())"
|
|
end
|