database file for rails app - ruby-on-rails

6 months back I wrote a rails app (craigslist scraper) and all of the code was pushed to github and then deployed to heroku. Since this time I got a new laptop and am getting back into learning code. I am trying to get the same app running locally on my machine but am getting an error that no DB is connected (( Rails.application.database_configuration: Could not load database configuration. No such file )) how can I download the DB file from GitHub or get the DB going again and run a fresh scrape? thanks in advance!

You need to run.
rake db:create db:migrate
This will create the database from your database.yml file, then run the migrations.

Related

Rails Application deployed on Heroku writing to localhost db and redirecting to localhost view

I recently deployed a RoR app to Heroku.
The app loads fine.
I have a 'new' action that creates a new model record via a form submission (POST).
The issue is:
On submit, the controller writes to my local database and redirects to my local view corresponding to the controller action: http://localhost:3000/mycontroller/myview
My production database is empty! Any ideas on what is causing this and the fix?? Why is my remote deployment on Heroku accessing localhost???
I only need production on Heroku.
advTHANXance!
Have you tried
RAILS_ENV=production rails db:create
RAILS_ENV=production rails db:migrate
But if you don't run those two, you will surely get migrate error.
Please provide some details about your error.
1) Check if you have a postgres plugin in heroku console
2) Secondly when you push check if you get any error related to PG .
3) dont forget to do heroku restart --app appname
4) login to heroku using **heroku bash** and then run rails c, then check that what database you are using
for it use the command
ActiveRecord::Base.connection_config
now you will get response like
{:adapter=>ADAPTER_NAME, :host=>HOST, :port=>PORT,
:database=>DB, :pool=>POOL, :username=>USERNAME,
:password=>PASSWORD}
if you see dbname as the name in heroku dashboard database name
if it is same then the database is what you are using is of production.
and for transfer to local,re-check your routes and clear your cache,thats the only reason for it.

Heroku still referencing old database

I've provisioned and switched to a new database in my heroku app. And it seemed to work fine, but now I attempted to run the console and it had the data from my old database. I ran heroku addons:destroy <DATABASE_URL> --remote live and now the hobby-dev db has been destroyed and now when I try to run a query from the console I get PG::ConnectionBad: FATAL: role "fgedboaquoao" is not permitted to log in
Anybody know how I can stop my app from referencing the old database?
I had it hard coded in my production.rb to share the databases. that was the problem

removing postgres database on ubuntu from commandline

I am working on a rails app. Due to some messing up with the code I deleted the app from my local development machine and cloned the previous commit from the git repo.
Now i want to delete the db file(postgres) of the deleted one from the local machine as well. I had issues in the past that made me unable to access several features due to database conflicts(due to same db name). So i fixed that by removing the database and recreating with the cloned app. I had done it before from commandline but i forget now on how to do it. Could some one tell me where is the postgres database file located in ubuntu or how to remove from commandline? Thanks in advance.
There is a postgresql shell command dropdb which you can use.
After a bit of searching i found that doing this will remove the database. From the commandline just cd into your app directory and run this command
rake RAILS_ENV='development' db:drop
This will remove the database(although am still unable to find the exact location where its stored physically in hard drive). This is the solution if you cant access rails console, or some rake commands.
After that we can just recreate the database using
rake db:create

Rails model update doen't work after cap migrate

I have a Rails 3.2 application and I have some issues on the production side:
I have a model 'Poject' and did a migration to add a string for 'description'.
running
rake db:migrate
works fine on my developer machine like all the times.
But when I do a cap deploy and cap migrate on the production server I cannot update my
project models which where already in the database. Only new ones work fine.
I'm using postgres 9.1
I don't know what's the issue here since its working fine on my local machine.
Regards
Oliver
I think what you are looking for is cap deploy:migrate.
Run the migrate rake task. By default, it runs this in most recently deployed
version of the app...
You can read more about it here: https://github.com/capistrano/capistrano/wiki/Capistrano-Tasks
Also make sure you are using the right environment while using capistrano
Thank you, I did run the cap deploy:migrate task. But here the problem was that I was validating the existence of a newly created field and this caused the trouble with the records which where already in the database.
thanks.

Rails/Heroku : db:push runs correctly but does not create the DB

I've been having problems yesterday with Heroku shared Postgres DB. It looks like my db is not correctly 'pushed' to my heroku DB.
Configuration
Using 'pg' gem for both development and production environments.
Using Heroku's 'shared-database' add-on.
Running Rails 3.1.1.
What I'm trying to do
Push my source code to Heroku and then synchronize my postgres DB with Heroku's one. No problem for the source itself, but I can't get my DB up and running.
What I've tried so far
1: Source code push : git push heroku master. OK. This works.
2: Then I try to run : heroku db:push. Seems to be running normally, no error, the schema is sent to Heroku, the different tables are correctly detected and seem to be sent as well :
3: Let's check it out, is everything allright ? heroku info :
Doh ! The database is still empty (and therefore I get DB-related errors when accessing dynamic pages). Can't understand what's happening, I've spent time on this issue yesterday evening but only been mpessing with Heroku for a little while and never encountered this issue. Any clues ?
I'm not convinced that the Database size figure is a live figure. Here's a clean deployment of an app to Heroku and the output of heroku info at each stage. The first run is post application creation, the second after a push of the code, the third after a heroku db:push.
The database was uploaded before the third output and the application is running however the DB:size is not reporting the figure.
Is your application actually erroring because the database isn't present?
The problem is in the commit process.
You should run manually after each commit from your console :
heroku run rake db:migrate
Enjoy
daniel

Resources