Postgres code in config.database.yml for Rails Angular app - ruby-on-rails

I am following this tutorial http://asanderson.org/posts/2013/06/03/bootstrapping-angular-rails-part-1.html to create an app using rails an angular js and having issues in making postgres code work
When i run rake db :create i get this error
YAML syntax error occurred while parsing database.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Error: (<unknown>): mapping values are not allowed in this context at line 71 column 11
What username and password should i use in the postgres code in the database.yml file .How do i find out my postgres uername and password .posgres is already installed in the system
Here is the code in database.yml file
default: &default
adapter: postgresql
encoding: unicode
development:
<<: *default
database: blog1_development
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: pguser
password:
test:
<<: *default
database: blog1_test
adapter: postgresql
encoding: unicode
database: blog_test
pool: 5
username: pguser
password:

I recommend you to use password create a password by
opening cmd prompt
enter this to create password
mysqladmin -u pguser password [newpassword]
after creating the password
change your database.yml file
development:
<<: *default
database: blog1_development
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: pguser
password: [new password]
Enter the password correctly give a space after colon<:> in database.yml in password section when entering password

Related

no records showing after migration to postgres

Just followed the "Migrating to PostgreSQL" Railscast, migrating my local sqlite3 database to postgres:
here is my database.yml file:
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
host: localhost
username: martinbraun
password:
test:
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
username: mbraun
password:
production:
adapter: postgresql
encoding: utf8
database: app_production
pool: 5
username: mbraun
password:
My postgres server is running on postgressapp on port 5432. It tells me that it's running and I get connection to my database app_development.
However, "which psql" tells me:
/usr/bin/psql
and when I start my app, all the records are not loading, I simply see my application layout and all html stuff which is not related to any records. No error is showing up.
I have verified that my database contains data via rails console, so the migration from sqlite3 to postgres was def successful. I am just wondering why my records are not showing and what I do wrong here?

Cannot seem to use development database

I updated my database.yml file to look like so:
test:
adapter: postgresql
encoding: unicode
database: startpoint_test
hostname: localhost
pool: 5
username: postgres
password: password
development:
adapter: postgresql
encoding: unicode
database: startpoint_dev
pool: 5
username: postgres
password: password
And now it seems when I run my application, and sign up a new user the development database does not get a new user inserted into it ...
The tests all pass for signing up a new user
Have you tried using
rake db:create:all
and then
rake db:test:prepare

Rails: How do I change my database from SQLite to PG while in Development?

I generated my rails app with the default SQLite database, but after creating a few models and migrating a few times, I want to change it to Postgresql.
I added the postgres gem to my Gemfile, bundle install, then I replaced all my database.yml code from
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
to
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres
password: mypass
development:
<<: *default
database: sample_app_development
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_production
I get a FATAL: password authentication failed for user "postgres" error even though the password is correct. Is it because I am missing a step? Am I supposed to tell PG using pg Admin III that I want to add this app to my server? Am I supposed to create a new role/connection?
I have run into this problem a few times and don't seem to be able to find an answer for this specific problem.
it gives me this when I try to run rake db:drop :
Couldn't drop sample_app_development : #<PGError: FATAL: role "postgres" does not exist
>
Couldn't drop sample_app_test : #<PGError: FATAL: role "postgres" does not exist
>
=========
Edmunds-MacBook-Pro:sample_app edmundmai$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
Password:
createuser: could not connect to database postgres: FATAL: password authentication failed for user "edmundmai"
Postgres user authentication is a bit weird. The default is to use the same authentication as the OS (at least in Linux). So to get to the Postgres prompt from the command line, you have to do something like this:
sudo -u postgres psql
Note that there's no password - and because the OS takes care of the authentication, there's no need for one (the OS'll ask for your sudo password, though, if required).
So option one is to just strip the password option out of your Rails config file and hope everything works out. Failing that, set up Postgres to accept password-based authentication by editing the pg_hba.conf file (mine's at /etc/postgresql/9.2/main/pg_hba.conf). Here's an example from my local server; the user "postgres" uses the OS's authentication ("peer"), but the user "opengeo" uses a password ("md5"):
# TYPE DATABASE USER ADDRESS METHOD
local all postgres peer
local all opengeo md5
Hope that helps!
To convert your database to postgresql first create a user as below:
$ createuser foo
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) y
To create a db:
CREATE DATABASE foo_db ENCODING 'UTF8' OWNER foo;
make sure your database.yml looks as below:
development:
adapter: postgresql
encoding: unicode
database: foo_db
pool: 5
username: foo
password:
test:
adapter: postgresql
encoding: unicode
database: foo_test
pool: 5
username: foo
password:
development:
adapter: postgresql
database: postgres
username: postgres
password: ;ernakulam
pool: 5
timeout: 5000
test:
adapter: postgresql
database: postgres
pool: 5
timeout: 5000
production:
adapter: postgresql
database: postgres
pool: 5
timeout: 5000`

JRuby JDBC Without Username or Password in database.yml

It it possible to use the JDBC Postgres (jRuby) driver without specifying a username and password in the database.yml file? My project database file currently is:
test: &test
adapter: postgresql
encoding: unicode
database: app_test
pool: 5
development: &development
adapter: postgresql
encoding: unicode
database: app_development
pool: 5
production: &production
adapter: postgresql
encoding: unicode
database: app_production
pool: 5
cucumber:
<<: *test
However, this causes the following error on starting the server / console:
ActiveRecord::JDBCError: The driver encountered an unknown error: FATAL: no PostgreSQL user name specified in startup packet
If possible, it would be nice to not include the username and password out of the database.yml configuration file (this works with MRI and the pg gem). Each team members uses a different username for their local installs.

Have an error only in production!

I'm created project. Works in development mode! Excellent!
DEVELOPMENT:
Typing : ruby lib/scripts/test_sync.rb
And my script works!
PRODUCTION:
Typing : ruby lib/scripts/test_sync.rb
Get Access denied for user 'root'#'localhost' (using password: YES)
Dont know, I did everything. grant previligies, changed password and so on... Coul someone help me, please?
UPD*
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: mysql
host: localhost
database: survey_development
username: root
password:
encoding: utf8
# 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:
adapter: mysql
host: localhost
database: survey_development
username: root
password:
encoding: utf8
production:
adapter: mysql
host: survey
database: survey_production
username: survey
password:
encoding: utf8
mossad:
adapter: mysql
host: baza
database: baza_production
username: baza_survey
password:
encoding: utf8
Try adding RAILS_ENV=production
Your login/password pair is incorrect for MySql database in database.yml.
EDIT
You should remove your password row if it does not exist:
production:
adapter: mysql
host: survey
database: survey_production
username: survey
encoding: utf8

Resources