Misha Stone
Misha Stone

Reputation: 641

Heroku vs YAML - Valid YAML is not being read by Heroku

I've been playing with spaces all day and cannot, for the life of my, get my Heroku app to migrate the database. I keep getting

    rake aborted!
    YAML syntax error occurred while parsing /app/config/database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): did not find expected key while parsing a block mapping at line 62 column 3

Which would be all fine and dandy as an error except I have run my YAML file through three different Validators and have been told by all of them that they are 'valid'.

Here's the edited YAML in question

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: coder-app_title
  username: postgres
  password: 123456
  host: localhost

  username: personal_username
  password: personal_password

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.

test: 
   <<: *default   [[<< This is line 62.]]
   database: coder-add_title_test
   username: postgres
   password: 123456
   host: localhost

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
   production:
     url: <%= ENV['DATABASE_URL'] %>
#
production:

Upvotes: 0

Views: 307

Answers (1)

max
max

Reputation: 102164

The parser error is due to inconsistent indenting. I would recommend you use a decent text editor and use 2 spaces to indent the blocks.

I don't know what you have been using to validate the YAML which is not catching the error - copy pasting into a web based validator does not really work that well. Instead you can use the Ruby YAML module to parse the file:

# run `$ irb` from the root of project
require 'yaml'
YAML.parse(File.open('./config/development.rb'))

Also Heroku will write the production settings into the file so you should not have a production: section in your database.yml file.

This is a corrected version which parses properly:

# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
#   gem install pg
# On OS X with Homebrew:
#   gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
#   gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
#   gem install pg
#       Choose the win32 build.
#       Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

development:
  <<: *default
  database: coder-app_title
  username: postgres
  password: 123456
  host: localhost
  username: personal_username
  password: personal_password

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.

test: 
  <<: *default
  database: coder-add_title_test
  username: postgres
  password: 123456
  host: localhost

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# NOTE. Heroku will write production settings in a post-commit hook. No configuration needed.

Upvotes: 1

Related Questions