I've been trying to setup my first rails app--I'm okay at stumbling around on my local machine (OSX) and finding out how to do stuff...
I want to setup my local machine to deploy on Heroku.
I have a heroku account, and rails running on my mac...how do I get the database setup for both my local config and heroku? I have MySql locally, but it looks like heroku uses Postgre...
Can you give me a step-by-step process so that I can get to making my app and forget about server config?! :)
You should be ok if you havent written any mysql specific code. Rails handles converting the rails model/controller code to whatever database you are using. As it says here, you are probably going to want to type:
heroku db:push
to set up your database using the schema and import the data from your local database.
If you're not already using it, check out Michael Hartl's Ruby on Rails Tutorial.
Germane to your question: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec:deploying
Edited because I apparently forgot how to spell germane...
First, you would setup your database.yml file to use your MySQL on your local machine for development. Set this up however you like, a good example is http://wiki.rubyonrails.org/database-support/mysql#databaseyml_example
And than when you are ready to migrate your development database from your local machine, you would run:
heroku db:push
This will export your MySQL, SQLite or Postgres DB on your development machine and import it into your heroku instance. Your heroku instance will overwrite your database.yml file with the correct Postgres info and your application will have your development schema in the heroku Postgres DB.
Related
I am running my Ruby On Rails 5 app on localhost and now, I imported the production database. It's a PostgreSQL database, exported via the pg_dump tool.
When I modified the database.yml file the Rails app and set there the newly created database, I got this error when running the Rails app (tried also to change the port on which the app is running, but it didn't help):
OpenSSL::Cipher::CipherError at /
In the Rails console is not any information about the error.
What is the reason of such an error? I tried to export the database from the staging server and use it on localhost and everything worked fine.
Based on the docs: https://ruby-doc.org/stdlib-2.4.1/libdoc/openssl/rdoc/OpenSSL/Cipher.html#method-i-final
It looks like you don't have the proper encryption key to connect to the production db.
I would guess you either do have the proper one for staging, or staging is running unencrypted.
Here's someone else with the same error caused by an incorrect key: OpenSSL::Cipher::CipherError when running staging DB on local
Hey so I am following the One Month Rails guide to learning Ruby and I have hit a wall on one of the lessons. I have just finished uploading an image with Paperclip, and as I finished my work on my localhost and checked it on Heroku, something went wrong. The pin/image appears to have been pushed to my Heroku account, the only problem is that the username and password that works for my localhost:3000 won't work for my Heroku account. The same password should work for both, but for some reason something is wrong. I wish I could give you the action that is going on in my terminal, but the ruby rails is the only thing that has a continuous status flow. The problem may have been when I switched my password after not using my account on localhost for a few weeks, but i thought that once i "git pushed" that to heroku master, it would've synced. I have tried heroku run rake db:setup which didn't seem to do too much as well as wrestled by way through "Importing a Heroku Postgres Database with PG Backups", but I had some trouble working through that. Any ideas? Thanks for the help.
Your 'database.yml' should not be sent to Heroku, they take care of that, creating a new database.yml config file with the proper DB access details.
Try logging into your Heroku instance and deleting the file.
Edit: nevermind, assumed you were not able to connect to the DB, not to login into the website.
So if I'm understanding you correctly, you've deployed your application to Heroku and the login (to your application) that was working locally doesn't work on Heroku.
Deploying your application doesn't deploy data. Assuming you've run heroku run rake db:migrate then your database schemas will at least match.
At this point, you've got a couple of options.
Use a seeds.rb file which you can load with heroku run db:seed to setup some 'seed' data so that you can login.
Push your local database to Heroku - either via heroku db:push or using heroku pg:transfer provided by https://github.com/ddollar/heroku-pg-transfer
Use heroku run console to create your user account via the command line
User.create(email: 'someemail.com', password: 'somepassword', password_confirmation: 'somepassword')
I'd be inclined to go with the later option.
How did the user get in their in the first place? Perhaps going back to that step in the tutorial - just remember, if you are using rails console locally to use heroku run console on Heroku.
I've just deployed my application to heroku and pointed my custom domain to the heroku servers. How can I check the records in my heroku database?
You can use heroku run rails console and look at your records with Model.all or any other method.
If you want to backup the database look at heroku PG backups, you then can import your database on your local machine and look at it there. Depending on your db adapter you could use sqlite browser for sqlite3 or phpmyadmin for MySQL.
I found a similar question like this and here is what #Chowlett says:
"You could run heroku pg:psql to fire up a Postgres console, then issue \d to see all tables, and \d tablename to see details for a particular table."
You can also type select * from tablename; to view the table contents.
How to view current database schema for Heroku app in Terminal?
heroku db:pull to pull your production DB locally to take a peek in it.
I'll give the method for connecting via a GUI tool
Run the following command to get the database credentials from Heroku:
heroku pg:credentials DATABASE_URL
Then you can use a GUI tool like PG Commander or PGAdmin to connect to the db
Heroku now has an add-on named PostgreSQL Studio (currently free & in beta) that would let you access your database from within the browser, without having to use CLI, much like PHP MyAdmin.
To attach this add-on to your application,
heroku addons:create pgstudio
Then go to the list of add-ons on Heroku, select PostgreSQL Studio, authorize it, select the database to connect with from the dropdown list of all databases and it will take you to the web-based interface to handle your selected database.
You may refer to this official article on Heroku:
https://devcenter.heroku.com/articles/pgstudio
The easy answer is:
heroku pg:info
You can also download a client side Postgres, like Postico, and using the information provided in that URL to enter password and database name etc, then you can create locally, just like phpMyAdmin.
I use the admin_data gem, works well in Heroku.
You can use heroku dataclips that allows to run queries online. Here you can find documentation https://devcenter.heroku.com/articles/dataclips.
Connect to the database using Sequel Pro. You can find your ClearDB url using heroku config command. The structure for connecting is as follows:
CLEARDB_DATABASE_URL => mysql://[username]:[password]#[host]/[database name]?reconnect=true
I created rails application, it works great in development environment, but now I want to deploy it. I have a vps with passenger and nginx, I deployed rails application with static pages, but now application needs database.
Which best way to clone structure from development base and then deploy it?
Please give any guides to deploy application?
I use (ubuntu 10.04_64, rails 3.0.6)
It sounds like you want a copy of your development database (structure and data).
If you are using a sqlite3 database in development (which you probably are), then on the server (after you've deployed) make a copy of it and name it production.sqlite3
cp development.sqlite3 production.sqlite3
This will copy the structure and data of your development database. If its a static site however, you could do this on the development machine before you deploy.
Let me know if you need instructions to do this for mysql (or any other database) and I will edit this answer.
rake db:migrate RAILS_ENV=production
or I misunderstood the question?
I am trying to learn how to push and pull databases using Heroku's system, I just have a clarifying question.
My existing development database is called project_dev but I want to create a new database. I entered in the following command:
heroku db:pull mysql://root:mydbpassword#localhost/20110302heroku
I have a database.yml file that includes my development, test, and production dbs, and I got this response from Heroku:
Auto-detected local database: mysql://root:mydbpassword#localhost/project_dev?encoding=utf8
Does this mean I have to manually create a new database first if I want to pull from Heroku? Does it mean that I cannot pull at all unless the db is explicitly defined in my database.yml file?
Any pointers would be really helpful. I had a look around on Google, Heroku and SO, but I didn't find the answers I was looking for. Thank you!
Yes, you'll have to first create the new local database but you don't have to declare it in your database.yml file.
When I run heroku db:pull mysql://root:mydbpassword#localhost/newdb it correctly imports into the newdb database. I'm not sure why it auto-detects your local dev database. Do you use the latest heroku and taps gems?