3/19/2023 0 Comments Rails postgres appIn future posts we’ll see how to query Postgres with R to analyze the data and gain insights about how people use our products. Here’s what the UI looks like along with an example query to display the first 10 people to sign up: You can also query the data other ways but for quickly exploring, querying, and exporting the data, SQLPro for Postgres is hard to beat. SQLPro for Postgres is a fantastic Mac app for exploring Postgres databases. Step 2: Explore the data using SQLPro for Postgres Then I can just run prdb (my short hand for “Preceden Database”) from the command line to drop the old copy and grab the latest production data: $ prdb heroku-cli: Pulling postgresql-infinite-32999 -> preceden_production_copy pg_dump: last built-in OID is 16383 pg_dump: reading extensions To delete it beforehand, you can run: $ dropdb mylocaldbįor my own workflow combine them and use a Bash alias to make it easier to run: alias prdb="dropdb preceden_production_copy PGUSER=postgres PGPASSWORD=password heroku pg:pull HEROKU_POSTGRESQL_MAGENTA preceden_production_copy -app sushi" In order for this command to work, mylocaldb can’t exist when you run this command. If your local Postgres instance requires a user name and password, you can provide them via the command line as well: $ PGUSER=postgres PGPASSWORD=password heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb -app sushi Where mylocaldb is the name of a local Postgres database, sushi is the name of your Heroku app, and HEROKU_POSTGRESQL_MAGENT is the name of your database which you can obtain by running: $ heroku pg:info -a sushi Heroku makes this fairly easy using the pg:pull command: $ heroku pg:pull HEROKU_POSTGRESQL_MAGENTA mylocaldb -app sushi Step 1: Pull your production data into a local Postgres database Wouldn’t it be nice if you could quickly query your database and explore the results?įortunately there is a way using a combination of Heroku’s pg:pull feature and a Mac app called SQLPro for Postgres. Neither option makes it easy to quickly explore the data. Rake tasks let you perform complex analyses, but make it difficult to explore data because each time you tweak your task to do something new, you need to commit, push to production, run the task, and wait for it to execute. Each method has limitations though: heroku console makes easy to answer simple questions about your data, but makes it difficult to perform complicated analyses that take more than a few lines of code. In the past when I’ve wanted to explore production data for a Heroku-hosted Ruby on Rails app, I’ve primarily used heroku console and rake tasks.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |