In Spree 3.1 after bundle install. It need to run rake as follow the document:
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec rake spree_sample:load
So I have a project to create a rake task for Heroku post deployment. But problem is the db:seed asked default [username] and [password] which required [Enter] [Enter].
Really don't know how to make it go through
And when I put in one task would look like this
task :autoall do
Rake::Task["db:migrate"].invoke
Rake::Task["db:seed"].invoke # This step stucked waiting for Enter
Rake::Task["spree_sample:load"].invoke
end
The one below better but still waiting for [Enter] [Enter] in the process and die.
task :autoall do
Rake::Task["db:reset"].invoke
Rake::Task["spree_sample:load"].invoke
end
If no other way, I might need to dig in the source and modify.
Help Please!
Related
I am using Michael Hartl's rails tutorials.
Whenever I use the following
$ bundle exec rake db:migrate:reset
Then
$ bundle exec rake db:seed
It waits. It doesn't show anything.
And when I do:
bundle exec rake test
I get
ActiveRecord::PendingMigrationError: Migrations are pending.
To resolve this issue,
bin/rake db:migrate RAILS_ENV=test
When the above is done-"db:migrate RAILS_ENV=test", tests are clear.
However Michael doesn't mention anything happening about this scenario, Can anybody help and explain?
By default, most rake commands are going to run in the context of the RAILS_ENV passed to the command line. If no RAILS_ENV is passed to the command line, it will run in the development context, which is separate from the test context. There are a few exceptions, like rake db:create, which will create your development and test databases, but migrate will work against the specified environment.
I'm going through Michael Hartl's tutorial and I'm unsure what the difference between these 2 commands is. Generally, in the tutorial, there's always 3 steps.
1. bundle exec rake db:reset
This makes sense, to reset the databse.
2. bundle exec rake db:populate
I figure this is to populate the database with the sample data.
3. bundle exec rake db:test:prepare
Why is this command still needed?
The first two commands execute on your development database by default, unless you specified a RAILS_ENV.
rake db:test:prepare performs all the migrations on the test database.
A more detailed explanation can be found here.
Is there a way to do a test run of a rake task? If so what is the command to do it? I don't want to actually touch the development database since my task manipulates the data.
Yes you can actually run bundle exec rake COMMAND -n
Having a look at rakes help we can see it here.
# rake --help
--dry-run Do a dry run without executing actions.
AS the guides, the command used to prepare test database is
bundle exec rake db:test:prepare
However, I have found that following command also works & created the test db for me.
bundle exec rake test:prepare
Wanted to know if this is a valid command, if yes. Where can I find the documentation.
tested on rails 3.2.8
According to github and the source code task 'test:prepare' => 'db:test:prepare' is mentioned at the bottom.
Hence it's a shortcut, wrapper, whatever you want to call it. Another question would be why this doesn't up when you do bundle exec rake -T but hey.
This is very simple I guess, but still..
I have a background task with Resque that is failing and the output is too long to see in Terminal window.. I think it's time to log it. I execute it through
bundle exec env rake resque:work QUEUE='*'
Question is - how do I save that output to log file?
I looked at logging (development.log and it's not showing there of course, b/c it's happening on rake side)...
Thanks!
Take a look at this pull request:
https://github.com/sj26/resque/commit/05e4c5e6f92fe62b25db40984b20dad4b9f870d8
And read the readme. Have you tried to set VVERBOSE=1?
You could just send the output to a file:
bundle exec env rake resque:work QUEUE='*' >> log/resque.log
I run resque like that on my server
nohup bundle exec rake resque:work QUEUE=general PIDFILE=tmp/pids/resque_worker_QUEUE.pid & >> log/resque_worker_QUEUE.log 2>&1
Can't tell you it's the best way, but it works.