New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

heroku-api-postgres

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heroku-api-postgres

0.13.1
Rubygems
Version published
Maintainers
1
Created
Source

Heroku::Api::Postgres

This gem has been extracted from https://db-backups.com.

Your "one click" backup solution for Heroku apps.

Ruby library to invoke Heroku Postgres APIs. An extension to the official Platform API gem to introduce the missing APIs for Postgres.

This gem is not officialy supported. We use the same APIs that the offical Heroku Toolbelt uses, therefore is unrealistic that a breaking change in the APIs would break it, since it means it would break both this gem and the official Heroku CLI.

Not all APIs are implemented at the moment but we are working hard on implementing all of them.

Please check the list of implemented and not implemented services.

Contributes and Pull Requests are welcome!

Installation

Add this line to your application's Gemfile:

gem 'heroku-api-postgres'

And then execute:

$ bundle

Or install it yourself as:

$ gem install heroku-api-postgres

Usage

This gem client needs to be instantiated in a similar way to the PlatformAPI. You can use the same oauth key or API key that you use for the PlatformAPI.

postgres_api_client = Heroku::Api::Postgres.connect(ENV['HEROKU_API_KEY'])
postgres_api_client = Heroku::Api::Postgres.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])

Look into Models for a detailed description of the JSON objects returned by the APIs. Those are the bare objects returned by the official Heroku API.

Databases

databases_client = postgres_api_client.databases
database_info = databases_client.info(app_id, database_id)

returns a Database.

database = postgres_api_client.databases.wait(app_id, database_id, wait_interval: 5)

Waits for the given database to be ready.

Polls every wait_interval seconds (default 3).

Credentials

credentials_client = postgres_api_client.credentials
credentials_client.rotate(app_id, database_id)

Rotate the database credentials.

Backups

backups_client = postgres_api_client.backups
backups = backups_client.info(app_id, backup_id)

returns a Backup.

backups = backups_client.list(app_id)

returns an array of Backup.

The app_id can be either the name of your heroku app or the id.

Check official API

To retrieve the APP_ID and DATABASE_ID needed to run the tests you can use the name of the app as APP_ID and execute: heroku addons --json --app YOUR_APP to retrieve the DATABASE_ID.

schedules = backups_client.schedules(app_id, database_id)

Returns all the backup schedules associated with the database.

Returns an array of Schedule

schedule = backups_client.schedule(app_id, database_id)

Schedules the backups at 00:00 UTC.

Returns a Schedule

backup = backups_client.capture(app_id, database_id)

Captures a new backup for the given database

Returns a Backup

backup_url = backups_client.url(app_id, backup_num)

Returns a temporary, public accessible URL to download a backup. Needs the num attribute of a Backup.

Returns a BackupUrl

backup = backups_client.restore(app_id, database_id, dump_url)

Restores a dump from a public URL.

Returns a Backup

backup = postgres_api_client.backups.wait(app_id, backup_id, wait_interval: 5)

Waits for the given backup/restore to be ready.

Polls every wait_interval seconds (default 3).

You can pass a block to be executed at each interval:

backup = postgres_api_client.backups.wait(app_id, backup_id) do |info|
    puts "Processed #{info[:processed_bytes]} bytes"
end

How do I get the database_id ?

You can obtain a database id by calling the Heroku Platform API

heroku = PlatformAPI.connect_oauth(ENV['HEROKU_OAUTH_TOKEN'])
addons = heroku.addon.list
databases = addons.select { |addon| addon['addon_service']['name'] == 'heroku-postgresql' }
databases_ids = databases.map{ |addon| addon['id'] }

Check also the Official API

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can run bin/check to run linter and the tests together. You can also run bin/console for an interactive prompt that will allow you to experiment.

You need some app and database ids to run the tests and record the cassettes. In particular you need an app with a postgres database on the free plan and one with a database on a pro plan.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/coorasse/heroku-api-postgres.

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 13 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts