i'm a ruby new bie.I'm trying to create a simple API using rack that takes a json data and writes that to the postgres heroku database table.
i created a database on postgres heroku, but didn't find out any option to create a table there.
Can any one provide some pointers to some good tutorials which explain how to go about accomplishing this.
1 Answer
If you have a dev or basic plan, you won't be able to connect directly to the DB and manually create the table, so you will need to write a migration script that will create the table for you.
Using an ORM like ActiveRecord is generally a good idea and it makes it very easy to automate all the SQL grunt work. Use the sinatra-activerecord (https://github.com/janko-m/sinatra-activerecord
) gem to get the rake helper tasks on your rack app. Just make sure that instead of using local sqlite3, you use ENV[DATABASE_URL] to point to your Heroku db.
Then run the local command rake db:create_migration NAME=json_data to make your migration file and then once you have created it, run the Heroku command heroku run bundle exec rake db:migrate to create all the tables and schemas you need.
CREATE TABLESQL?