I'm tinkering with Discourse a bit, learning some Ruby and moving towards writing a few plugins.
I have a dev VM (Vagrant-powered), and would like to have test data ready for me there. Even better, if a fellow member-developper of my community clones my Git repo, I would like him to have all the test data there without any effort.
My solution was to directly edit the db/fixtures/*.rb files to insert all the data I need in database. But it seems its not working as I thought it was.
My 001_categories.rb:
# fix any bust caches post initial migration
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!"
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
(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())"
Category.exec_sql "INSERT INTO categories
(name,color,slug,description,text_color, user_id, created_at, updated_at, position, name_lower)
VALUES ('Idées', 'bcb5ad', 'idees', 'Exprimez vos idées !', 'FFFFFF', -1, now(), now(), 2, 'idées' )
"
end
This last INSERT block is mine, and should add a new (and very française) category of my own in there.
Thing is... After a bundle exec rake db:migrate
... it doesnt. What am I doing wrong?