Bojan Mihelac wrote:> I try to extend db:test:copy_structure task to poulate test database
> with some existing data everytime i run it.
>
> It seems that "after_" task is not called as should be:
>
>> namespace :db do
>> namespace :test do
>> task :after_clone_structure do
>> puts "after_clone_structure_to_test"
>> end
>> end
>> end
>
> Anyone know what I am doing wrong?
> thanks in advance,
> Bojan Mihelac
>
>
>
Well, db:test:copy_structure is normal Rake task and not Capistrano
task, so that''s the reason why it doesn''t work.
The working code for loading data from file in MySql test database would be:
namespace :db do
namespace :test do
task :load_data => :environment do
abcs = ActiveRecord::Base.configurations
ActiveRecord::Base.establish_connection(:test)
ActiveRecord::Base.connection.execute(''SET foreign_key_checks =
'')
IO.readlines("db/data.sql").join.split("\n\n").each
do |table|
ActiveRecord::Base.connection.execute(table)
end
end
end
end
rake db:test:load_data
Hope it helps anyone.
--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p. | www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org