Previously i had deleted some migration files,which caused missing relations error(while tying to deploy to new server) so to fix that i added back the deleted migration files.I committed and pushed the new changes to gitlab after which i tried cap production deploy and still getting the missing relation error .On checking he release folder in the server i found that newly added back migrations files were not present.How to fix this.
I thought of trying to manually create the files in server,but cap production deploy is creating new release folders each time
how to fix this
I solved this issue by executing the following commands inside server release folder
1)
I ran
RAILS_ENV=production bundle exec rails db:reset DISABLE_DATABASE_ENVIRONMENT_CHECK=1 --trace
2) RAILS_ENV=production bundle exec rails db:setup DISABLE_DATABASE_ENVIRONMENT_CHECK=1
3)After this i executed cap production deploy and it all seems good
Note1: try executing the above commands first without DISABLE_DATABASE_ENVIRONMENT_CHECK=1 --trace if prompted add this command
Note2: In case u had some migration files deleted and currently u are trying to deploy to new server,then even if cap production deploy fails with missing relation error(caused by deleted migrations) you can get inside the latest release folder and run above commands to get the database setup correctly,after which u can try cap production deploy which most probably wont show any issues(related to deleted migration files)
Related
Do I have to "rake db:migrate" all the time when I committed fully migrated repository in github?
For example, I committed the rails repository in c9.io to github.
It was fully "rake db:migrate"d and didn't need to migrate.
But when I cloned my github repository and executed it,
there was a problem that " hasn't been migrated and you need to rake db:migrate"
I want to know what "really rake db:migrate" meaning in rails
and why cloned repo does need "rake db:migrate" all the time
rake:db migrate runs all the migrations that should be run and changes your db/schema.rb file. When you clone your repository, you add different migration files, so Rails demand you to execute the command again.
I am having an odd Heroku problem. I successfully pushed to Heroku with a new seed file and I saw the changes go through, and this seed file just has one Item.create in it. The old seed file has 10000 creates in it. The seeding should be very quick. So far, I:
1) Made sure that I pushed from master to heroku master. I ran git push heroku master from master
2) I made sure to git add and git commit.
3) When I run heroku run rake db:seed, it still runs like this 100000 line seed file. Any ideas on what might be going on?
Did you reset the database in heroku before updating the seed file? If not, run
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:seed
This removes the previous seed from the production database first.
I'm trying to push my Rails app to Heroku, and I'm at the point where I'm trying to create/migrate the database, but I cannot get the rake command to run. Here's the message I'm getting:
$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.2439
bash: rake: command not found
I spent a lot of time getting Postgres set up on my local machine, and it's working fine (was able to run rake commands without issue, and the app is running locally), but I don't know why I'm getting this error when I try to migrate the heroku database.
Figured it out. Turns out I had an error when I tried to deploy the app to Heroku, so it was never deployed. I didn't realize this because I was trying to push a branch that was not the "master" branch to heroku, thinking it would be fine. I wasn't getting any errors on that push, but that's because heroku won't try to deploy anything other than the "master" branch. Once I pushed the "master" branch, I got a bunch of pre-compile errors. Once those were cleaned up, I the app was deployed properly and I was able to run the rake commands.
Long story short, make sure your app successfully deployed before trying to run rake commands.
so i've successfully installed Harrys Prelauncher on Heroku (https://github.com/harrystech/prelaunchr)
and to export my collected emails into a csv i need to run this command (bundle exec rake prelaunchr:create_winner_csvs)
is there any way to run that command through pgadmin or some other program?
or is the only way for me to download my heroku database and run the command locally? also how and what would i need to do this?
i'm pretty new to rails and postgresql and would really appreciate if someone could help me out!
Because the rake task creates files locally you can't just run it on heroku via heroku run rake. You can however set up your local database.yml to connect to your heroku postgresql instance and run the rake task locally.
Run heroku pg:credentials to get the required database values.
Fill in the production environment of config/database.yml with the values you obtained from step 1 (for the value of 'database' in the yml file, use dbnmae from step 1)
Test your connection with RAILS_ENV=production rails db. This should drop you into a psql console.
Run the rake task. RAILS_ENV=production bundle exec rake prelaunchr:create_winner_csvs
The files will save locally in lib/assets as indicated by the documentation.
From within the directory of the project you can use
heroku run rake prelaunchr:create_winner_csvs
You should probably create a UI form in to your application.
On click on export CSV, it should run background job on heroku (Using delayed jobs).
heroku run rake prelaunchr:create_winner_csvs
Use send_data ruby method. To send your generated and dumped data file on to your browser.
Download the file on to your local system from running heroku instance.
Hope this will resolve your problem.
Cheers!!!
I ran into this problem recently while developing the Prelaunchr campaign for a client. Assuming you have a local version of your app and are using Postgres Copper in Heroku, you can "pull" your Heroku database down to your local machine, set that as your development database in database.yml, and run the rake task from your local app, which should now have the same database as your heroku version. Here is the command to pull the db (subbing out name_for_database & heroku_app_name with your own):
heroku pg:pull HEROKU_POSTGRESQL_COPPER_URL name_for_database --app heroku_app_name
Make sure to restart your local server to see the new database info populated.
I pushed an update to my Rails app production server, and in the update there was a new database migration. I ran rake db:migrate and got the common error seen here. I ran the rake again in bundle exec bash and it was successful. But after restarting my apache server, I'm now getting the 500 Error page. This update worked fine on my localhost, and was mostly this update to the db with supporting changes in the according view and controller/routing.
I don't even know why this error appeared this time, as I have pushed db updates successfully before using only rake. Nonetheless, the rake was successful. The 500 error page only shows on pages that require that specific new ActiveRecord. Any ideas on how to debug?
EDIT: My problem was an extremely simple one. I merely forgot to include the environment with the rake:
bundle exec rake db:migrate RAILS_ENV=production
Unfortunately, it took quite a while to narrow that down, as I couldn't use IRB to check the db entries until I followed these steps.
Did you run rake db:migrate on your server? Also be sure to set the RAILS_ENV flag so your production database is updated:
rake db:migrate RAILS_ENV=production