Heroku throws SQLITE3 Read only exception - windows

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

Related

rake db structure load 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.

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.

Heroku run rake db:migrate results in no change in the database, app restarted several times

I have a problem with pushing my migrations to the production database.
The issue:
I've altered database schema by adding 1 column.
I've migrated it to the production database:
MacBook-Air-Mac:app msc$ rake db:migrate RAILS_ENV="production"
[RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it.
== AddLengthColumnToBooks: migrating =========================================
-- add_column(:books, :length, :integer)
-> 0.0017s
== AddLengthColumnToBooks: migrated (0.0019s) ================================
Thinking that the new DB schema is now in production, I've deployed the code which does some things with :length.
In production, I got the following error:
undefined method `length=' for #
I did heroku rollback and downgraded the app to the latest reliable version.
THEN (a bit too late probably) I found out that I have to heroku restart the app to load the new indexes. I did this several times.
I opened the console then and checked Book.column_names, but there was no length
I did heroku run rake db:migrate followed by heroku restart one more time, no change.
I've tried migrating another column to the production db, but didn't get any message at all, not even the one from p.2.
What am I doing wrong here?
Update
Based on the answers of Philipe, I did a number of additional steps:
git add db/schema.rb, git add db/migrate/20130325103953_add_length_column_to_books.rb
and 'git add db/migrate/20130401041910_add_duration_column_to_books.rb'. Git's answer was:
Changes to be committed:
(use "git reset HEAD ..." to unstage)
new file: db/migrate/20130325103953_add_length_column_to_books.rb
new file: db/migrate/20130401041910_add_duration_column_to_books.rb
modified: db/schema.rb
Then I did git commit -m "Updating the schema".
Again the output was:
3 files changed, 168 insertions(+), 156 deletions(-)
create mode 100644 db/migrate/20130325103953_add_length_column_to_books.rb
create mode 100644 db/migrate/20130401041910_add_duration_column_to_books.rb
Then I run heroku run rake db:migrate. Unfortunately there was no sign of migrations, simply got:
Running rake db:migrate attached to terminal... up, run.5428
and that's it.
In the production Rails Console, running Book.column_names still lacks both length and duration.
Now I'm even more out of ideas.
`
It doesn't look like you are pushing changes to Heroku. Steps should be as follows;
Make changes to local code
Run any migrations LOCALLY
Add all changed files to Git git add .
Commit all added files to git git commit -m "Adding features"
Push the changes to Heroku git push heroku master - assuming you are using heroku as your remote name and you are working in the master branch
If you have migrations run heroku run rake db:migrate to run the migrations ON HEROKU
Following migrations do heroku restart
That should be all you need to get you working.
I had the same problem; I git added the migrations, git pushed them to the server, cap deployed them, and the database didn't change. Logged in to the server directly, ran rake db:migrate, and the command line seemed to run the migration, but nothing changed.
In my case, somehow rake db:migrate was using the wrong RAILS_ENV. I logged in to the server, and ran
rake db:migrate RAILS_ENV=production
This caused the database to create the new columns, and then all of the code that I had debugged in the test database started working on the server.
I just had same problem. After adding a column to my DB locally, I did heroku run rake db:migrate -app [my app name]. Running my code on production, I got ActiveRecord::UnknownAttributeError (unknown attribute '_____' for [table name].)
This solved my problem:
heroku restart --app [my app name]
if you want to run the migration on Heroku for your postgresql database you can add this line in your Procfile
release: alembic upgrade head
My two cents based on my experience: I thought that heroku run db:migrate also migrated db content into production. No! Only structure. So in my case, log in was not working in production because there were no users in it. I had to sign test user up again and then it worked. Hope it helps rookies like me out there

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?

No such file 'config/database.yml' on Heroku

My app is a Ruby rack app. When my Heroku app starts it breaks because
/app/config.ru:8:in `read': No such file or directory - config/database.yml (Errno::ENOENT)
Why does this happen? I understood Heroku is meant to create this file https://devcenter.heroku.com/articles/cedar-migration
The database credentials will still be configured automatically: at slug compile time, a config/database.yml that parses the DATABASE_URL from the environment will be written into the app.
Frustratingly the doc at https://devcenter.heroku.com/articles/ruby doesn't explain about database.yml
Ok, the first thing - heroku does not use database.yml file. By default rails app loading it from config/ directory automatically. And it's no need to load it manually in config.ru. If you want to use in heroku PosgreSQL - just add add-on. Heroku wil do all other things to link your app and db. If you want to use external MySQL server you should use Amazon RDS add-on
heroku addons:add amazon_rds url=mysql2://user:pass#dbhost/dbname
By this you can use any db. I use GoDaddy mysql bases through the Amazon RDS add-on.
Any way, the problem in your config.ru 8th line something like
read 'config/database.yml'
Delete it and look other ways that not conflicted with heroku
Good luck
It appears Heroku only creates its config/database.yml if you have a folder config under source control. Not explained in docs.

Resources