Creating a table in postgres heroku
I'm the new ruby ruby. I am trying to create a simple API using rack
which takes json data and writes this to the postgres heroku database table. I created a database by postgres heroku but did not find any way to create a table there. Can anyone please point some pointers to some good tutorials that explain how to do this.
source to share
If you have a dev or baseline, you won't be able to directly connect to the DB and manually create the table, so you'll need to write a migration script that will create the table for you.
Using an ORM like ActiveRecord is usually a good idea and it makes it easier to automate all of the SQL grunt work. Use sinatra-activerecord ( https://github.com/janko-m/sinatra-activerecord
) to get handle-rake tasks in your rack app. Just make sure instead of using local sqlite3 you use ENV[DATABASE_URL]
to point to your Heroku db.
Then run a local command rake db:create_migration NAME=json_data
to create the migration file and then, once you've created it, run the Heroku command heroku run bundle exec rake db:migrate
to create all the tables and schemas you need.
source to share