rake db structure load Heroku - heroku

setup is Heroku Cedar, RDS postgres, rails4
expected heroku run rake db:structure:load to create tables but no tables were created. It probably didn't execute a line from db/structure.sql
Is this the correct behavior?
As a work around, revert to psql directly into RDS.

Related

heroku pg:pull from database's on Amazon

I having being trying to run pg:pull from my Heroku app which one has a database on Amazon RDS, but the commands keep returning 'app-name has no databases' even if I use the database url set on my Config Vars .. Am I missing something ?
try ...
heroku pg:pull DATABASE_URL local_database_name --remote app_name
return ...
app_name has no databases
heroku pg:pull is not compatible with databases that aren't hosted on the plaform. This is specified in the documentation:
pg:pull can be used to pull remote data from a Heroku Postgres database to a database on your local machine. The command looks like this:
You will need to run pg_dump and a subsequent pg_restore manually to achieve the same result as the automated pg:pull command.

heroku rake db:structure:load failure

I need to use some PostgreSQL proprietary features such as rules and triggers for table partitioning. As long as I know, these kind of features cannot be dump to schema.rb so I have changed my schema_format configuration parameter to :sql.
Now, when I try to load rake db:structure:load to load the generated structure.sql into the heroku database, it fails saying: sh: psql: not found
How can I do it?
You can use pg:psql to run the script from your development machine against the database:
cd your-rails-project
heroku pg:psql -a your-app-name <db/structure.sql
Just make sure that the branch you have checked out locally is the same as the one you have deployed.

Transfer specific tables using heroku pg:transfer

With the taps gem it was possible to do:
heroku db:pull -f '^(?!requests).*' --app AppName --confirm AppName"
which would transfer the schema and all tables and indexes except for those of the requests table would be left in the production database.
Is there any option to do this yet with pg:transfer? I can't see one.
You can use the full pg_dump command on your local computer against your remote heroku postgres database. pg_dump has several options, including selectively dumping tables.
See http://www.postgresql.org/docs/current/static/app-pgdump.html for the complete information on pg_dump

Heroku database migrations failing with "unable to connect"

I'm having a heck of a time getting a Postgres database on a heroku instance to allow me to run database migrations.
I'm also incredibly new to Heroku, so apologies in advance if this is a silly question :)
So my app is on Heroku and can successfully connect to its database - it just can't do anything because the tables aren't set up. My connect block in the code looks like this:
if ENV['DATABASE_URL']
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
else
ActiveRecord::Base.establish_connection(dbconfig['development'])
end
The environment variable is set by Heroku at deploy time - this also works. If I jump in after everything is initialized with Pry or something, connection works great. The dbconfig hash is populated from my db/config.yml which works fine locally.
I can rake db:migrate on my local system just fine. However, trying this via heroku run rake db:migrate gives me an error dump beginning with:
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The only other odd thing I can think of here is that I'm using a gem called standalone migrations (declared in Gemfile) which should allow me to do this without pulling in the rest of Rails.
So, my question, why aren't my migrations running?

Heroku throws SQLITE3 Read only exception

After I deploy an app to Heroku, I run migration scripts and get this error message
...ites\padrino\prophetmargin> heroku rake ar:migrate
rake aborted!
SQLite3::ReadOnlyException: attempt to write a readonly database: CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
/disk1/home/slugs/215264_925fd2c_65a3/mnt/.bundle/gems/gems/padrino-core-0.9.11/lib/padrino-core/cli/rake.rb:9:in `init'
How can this be? I also tried running heroku dbpush sqlite://db/my-db.db and that also did not work.
heroku doesn't use sqlite3 but postgres. I'm not sure why you're getting this error though as I use sqlite3 in devel and when pushing to heroku they do some magic which migrates over to postgres.
I'm not exactly sure how Heroku does this db backend 'swap' but it looks like it's not happening for you as it's trying to write out the sqlite db file which obviously fails due to Heroku's read-only file system.
Sorry this isn't much of an answer, you may actually know all this already, but if you're new to heroku, it might give you some insight?
hmm... just noticed... what's the ar:migrate command? I haven't run Heroku for a few months which changes all the time, but normally you'd want a heroku rake db:migrate

Resources