So I have a standard database, then a database that I tie into with readonly permissions to access blogs from a third party blogging platform(ghost).
My database.yml looks like this:
staging:
adapter: mysql2
encoding: utf8
database: application
username: application
password: XXXXXXXX
host: 127.0.0.1
port: 3306
staging_blog:
adapter: mysql2
encoding: utf8
database: application_blog
username: application
password: XXXXXXXX
host: 127.0.0.1
port: 3306
The migrations seem to run without error when run with the 'staging' environment, but they obviously aren't running against the blog database, as that user only has readonly access to the application_blog database.
In my unicorn.stderr.log, I get the following output:
ActiveRecord::AdapterNotSpecified: 'application_blog' database is not configured. Available: ["staging", "staging_blog"]
So I guess my question is... what is necessitating the application blog to be configured in some fashion? How do I make it so that this blog can have a completely different db schema than the staging connection.
It seems you have not created the database 'application_blog'.
Related
I have been using sqlite for my project,
made alot of changes in migration files, I want to upload to heroku, but it does not support sqlite, so I decided to change it to pg.
I changed the database.yml file to the right values, I try to migrate the database, but I get tons of errors of migration, where I decided backthen to remove a column, but it doesn't exist anymore.
Is there anyhow to create a migration file out of the current fine working database in sqlite, that will be put in one migration file to be migrated in pg version ?
This is an example of the configuration of a test database, actually it can be production or development if you want:
test:
adapter: mysql2
database: redmine_test
host: localhost
username: 'user'
password: 'password'
port: 3306
reconnect: true
encoding: utf8
test_sqlite3:
adapter: sqlite3
database: db/test.db
test_pgsql:
adapter: postgresql
database: redmine_development
host: localhost
username: user
password: 'password'
When you use rake db:migrate it will try to execute the migrations for all of your environments, this is Production/Development/Test.
If you want to specify the environment use this command instead:
rake db:migrate RAILS_ENV=NameOfTheEnviroment
I'm new to Ruby on rails. I created my rails project and I would like to connect to an existing postgresql database (of company I work for) and display then some data in my web app.
Can anybody help out how to do that?
These directions assume you are using some version of Linux. However, they would be very similar on other operating systems.
Add the 'postgresql' gem to your Gemfile:
gem 'pg'
Then open a terminal window in the root directory of your application and run:
bundle install
Edit postgresql.conf (located on the remote postgresql server) and find the line that reads:
#listen_addresses = 'localhost'
Remove the comment and change it to:
listen_addresses = '192.168.0.14, localhost'
Replace '192.168.0.14' with the ip of your Rails application.
Now open pg_hba.conf (located on the remote postgresql server) and scroll down to:
# Put your actual configuration here
Directly below that enter your configuration like so:
# TYPE DATABASE USER ADDRESS METHOD
local all all localhost md5
host all your_user 192.168.0.14 md5
After saving both of those files run the command:
sudo service postgresql restart
Now edit your Rails application's config/database.yml:
production:
adapter: postgresql
encoding: utf8
database: the_database_name
username: your_user
password: your_database_password
host: 192.168.0.14
port: 5432
pool: 10
development:
adapter: postgresql
encoding: utf8
database: the_database_name
username: your_user
password: your_database_password
host: 192.168.0.14
port: 5432
pool: 10
Change 'the_database_name', 'your_user', and 'your_database_password' to the appropriate values.
After that, you should be good.
I am getting this error while doing rake db:migrate of newly cloned app.
'development' database is not configured. Available: ["production"]
So after reading the error, I am doing RAILS_ENV=production rake db:migrate
But this isn't working either.
My database.yml has
production:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: admin
password: admin
port: 5433
Please suggest.
Add
development:
adapter: postgresql
encoding: unicode
database: test
pool: 5
username: admin
password: admin
port: 5433
host: localhost
to database.yml file.
Also, if you test your application, you'll need test environment as well.
Your database.yml file shows you have only production environment configured for DB operations. You need to add configuration for development environment as well.
Open your database.yml file and add a configuration for development environment.
Something like the following should suffice (contents in square brackets are to be replaced with your actual values):
development:
adapter:[your adapter]
encoding: [your encoding]
database: [your database for development]
pool: [your pool]
username: [your database server username]
password: [your database server password]
port: [the port you're connecting on]
Remember to indent your yaml code appropriately.
Is there a way to configure the database.yml file to connect to Heroku's Postgres remotely?
I'm having trouble understanding how Heroku, Rails and PG gem work together.
It looks like during deployment, Heroku re-writes the database.yml file - is it possible to see the contents of this updated .yml file and use it locally?
Below are the steps to access Heroku db from local development:
Login to your heroku account.
Navigate to this URL https://postgres.heroku.com/databases/ OR you can get heroku db url by running this command in the terminal: heroku pg:credentials:url
Select your application database.
You will able to see your heroku pg credentials:
Host xxxxxxxxx.77777.amazonaws.com
Database 42feddfddeee
Username 44444444444
Port xxxx
Password 777sfsadferwefsdferwefsdf
collect above details and put in your databse.yml file development evn:
adapter: postgresql
host: < host > # HOST
port: < port > # Port
database: < database name > # Database Name
username: < user_name > # User Name
password: '< password >' # Password
Restart you application,
Best of luck..!!
I am not a postgres user but this should work.
You can alter your database.yml to include host and port
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
host: heroku.host.name
port: <postgres listen port>
And of course, you should allow connection on the server side, both at the firewall level and database level.
A simple hack to see contents of #{Rails.root}/config/database.yml is to write code to load this yml into an object, then print it out on the UI
DB_CONFIG = YAML.load(File.read("#{Rails.root}/config/database.yml", __FILE__))
puts DB_CONFIG["production"].inspect # or what ever method you want to print it
I am a bit of a newbie and may have misunderstood your question - but. Developed a ROR application using postgress database. Then uploaded to Heroku. I ran DB/Migrate/schema.rb to set up the remote Postgresql database.
From memory heroku run rake db:init (but I could be wrong). Whenver I update the database in develpment to get update in Heroku I have to promote code and run heroku run rake db:migrate
From my config/dtabase.yml
development:
adapter: postgresql
encoding: unicode
database: di_development
pool: 5
username: davidlee
password:
test:
adapter: postgresql
encoding: unicode
database: di_test
pool: 5
username: davidlee
password:
production:
adapter: postgresql
encoding: unicode
database: di_production
pool: 5
username: user
password:
and it works. I can't remember doing anything else.
Pierre
I am new in ror developement..i was working on a LIVE server...I just uploaded a file through sftp...after 1 day server suddenly stopped working...You can see the error message from here
it shows
There appears to be a database problem.
Your config/database.yml may not be written correctly. Please check it and fix any errors.
Your database schema may be out of date or nonexistant. Please run rake db:migrate to ensure that the database schema is up-to-date.
The database server may not be running. Please check whether it's running, and start it if it isn't.
Looking at the error page you seem to be using Rails 2.3?
At a guess you have a MySQL database not an SQLite running. You should have the user name and password for the database around somewhere (replace the relevant fields in the 3 sections with them).
Change the database names to reflect your database names.
The server admins might have set a specific socket for MySQL in which case replace the '/tmp/mysql.sock' with the socket number.
Check your Gems to see if the MySQL adapter is installed (you appear to be using Rails 2.3 so try gem list on the terminal for your server - make sure that you are in the root directory for the app).
If the MySQL gem is missing use gem install to install it (this will depend on what your hosting provider allows).
The following links are pretty old - targetted towards Rails 2 which you appear to be using.
http://www.ruby-forum.com/topic/139710
http://forums.mysql.com/read.php?116,353922,359544
database.yml
development:
adapter: mysql
encoding: utf8
database: temp_development
username: root
password:
socket: /tmp/mysql.sock
# 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
encoding: utf8
database: temp_test
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
database: temp_production
username: root
password:
socket: /tmp/mysql.sock