Rails4 Deploy ActiveRecord::AdapterNotSpecified - mysql

My deployment is running fine until the migration .. which fails
rake aborted!
DEBUG [874287b0] ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
DEBUG [874287b0] /home/kadoudal/rails/swim-tech.eu/site/swimtech/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.3/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection'
I run : cap staging deploy:check:linked_files, whic is successful , database.yml is symlinked correctly and contains :
# encoding: utf-8
defaults: &defaults
adapter: mysql2
host: localhost
timeout: 60000
encoding: utf8
production:
<<: *defaults
database: mydb_production
username: xxxxxxxxxxx
password: xxxxxxxxxxxxxx
why the Adapter is not found ?

forgot I was running a cap staging.... and there is no staging db in the database.yml

I created a staging server by cloning the production server on Rackspace. In this scenario, I want the staging server to still use the 'production' rails environment and the production db (on the staging server), so I set this in the config/deploy/staging.rb file:
set :stage, :production
and it works great.

Related

Transition from mysql to postgress error

I wanted to change from mysql to postgresql.
I don't care about data so I have changed database.yml:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.postgresql
test:
<<: *default
database: db/test.postgresql
production:
<<: *default
database: db/production.postgresql
And run
rails db:reset db:migrate
But I get error
rails aborted!
PG::ConnectionBad: 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"?
I have restarted both IDE (using c9) and server, but it gave no effect.
Any idea how to solve that problem?
#Edit After running sudo service postgresql start servers starts, and then when I run rails db:create
I get error:
psql: FATAL: role "ubuntu" does not exist
Just run this in your terminal :
$ cd /usr/local/var/postgres/
$ rm postmaster.pid
It's because last time your computer was shut off, Postgresql did not exit gracefully (usually due to running out of battery).

How to configure circle.yml in order to call the database?

I am trying to configure the CircleCi setup.
When I try to run the tests in my own environment then everything works out, but when I try to run it in Circle CI, then I haave got this error.
PHPUnit 5.6.0 by Sebastian Bergmann and contributors.
IIIII.IIIIIIIIIIIIIIIIIIIIIIIIIIIIIFFFFFFFFFFFFIIII..IIIIIIIIIIII 65 / 89 ( 73%)
IIIIIIIIIIIIIIIIIIIIIII. 89 / 89 (100%)
Time: 1.27 seconds, Memory: 56.00MB
There were 12 failures:
1) App\Test\TestCase\Controller\TagsControllerTest::testStages
exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /home/ubuntu/cemcloud2/vendor/cakephp/cakephp/src/Database/Driver/PDODriverTrait.php:48
This is the first part of the error.
I am getting that I have an error with my database configuration.
We are using Vagrant with the script (not sure if this is viable).
Also we are using mariaDB 10.1.19 and I have built up a test database for PHPUnit to run the tests against.
I don't know how to add this database with the configuration of mariadb and specific database.
I know that I have to add the
database.yml.ci
to my config file so I have added it in there and it looks like this.
test:
adapter: mysql
database: cemcloudTest
username: root
password: ''
Also I have added the circle.yml to our project root and it looks like this.
machine:
php:
version: 7.0
mysql:
version: 10.1.19
database:
override:
- cp config/database.yml.ci config/database.yml
- bundle exec rake db:create db:schema:load
Could someone help me out ?
in your cicle.yml database have to be created with name you use in your test config.
database:
override:
- mysql -u ubuntu -e "create database circle_ruby_test"
So that, this is the db conf:
test: # connection name
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
database: circle_ruby_test #your created DB
username: ubuntu #default circle user
pool: 25
socket: /var/run/mysqld/mysqld.sock # default sock location for circle
HTH:)

Rails 4 connect to remote MySQL database and pull Database structure for easy access

In my team, we are developing a system that is accessed by different platforms such as a Ruby on Rails website, a desktop java application and Android as well as iOS apps.
Our central MySQL database is running remotely on a server and can be accessed through PHPMyAdmin (and ControlPanel).
While the connection between the other platforms works well, I struggle with connecting my Rails app to the database. I would like to copy the database structure (tables, indexes, columns) so that I can access the database within Rails just as I would access data from a model that has been created locally (e.g. Customer.find(name: "Florian") ).
Is there a way to accomplish this? I tried several things such as altering my database.yml file, but when I then run something, like for example rails c it shows:
/Users/florianpfisterer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/mysql2-0.4.2/lib/mysql2.rb:31:in `require': dlopen(/Users/florianpfisterer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/mysql2-0.4.2/mysql2/mysql2.bundle, 9): Library not loaded: /usr/local/opt/mysql/lib/libmysqlclient.18.dylib
Referenced from: /Users/florianpfisterer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/mysql2-0.4.2/mysql2/mysql2.bundle
Reason: image not found - /Users/florianpfisterer/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-15/2.2.0-static/mysql2-0.4.2/mysql2/mysql2.bundle (LoadError)
...
My `database.yml' file:
development:
adapter: mysql2
encoding: utf8
host: <host-IP>
username: <username>
password: <password>
port: <port>
database: <database>
pool: 5
timeout: 5000
The same block is under test and production as well. In my Gemfile I have included:
gem 'mysql2'
I'm running Mac OS X 10.11.2 El Capitan and the server is a linux system. My Rails version is Rails 4.2.4 and Ruby ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15].
Thank you!
EDIT:
Thank you all, finally fixed my database.yml file and running rake db:schema:dump did it. But how do I convert my schema.rb to locally usable ActiveRecord::Models ?
Use this in your Gemfile
gem 'mysql2', '~> 0.3.18'
config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: 5
socket: /var/run/mysqld/mysqld.sock
username: <%= ENV['DATABASE_USER'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
insert into your .bashrc
export DATABASE_USER='root'
export DATABASE_PASSWORD='123'
Add library path to your .bash_profile file:
MYSQL=/usr/local/mysql/bin
export PATH=$PATH:$MYSQL
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH
The problem not in connection but with loading mysql itself.

Rails - Multiple development instances with a single source and database.yml file

Can we connect to multiple development instances with a single source and a single database.yml file? I mean, I need to have 4 development instances from same source which connects 4 different MySQL databases. Can I start the servers by using different PORT IDs?
example:
development:
adapter: mysql2
database: TEST1_development
host: localhost
username: root
password: password
encoding: utf8
pool: 30
development-2:
adapter: mysql2
database: TEST2_development
host: localhost
username: root
password: password
encoding: utf8
pool: 30
development-3:
adapter: mysql2
database: TEST3_development
host: localhost
username: root
password: password
encoding: utf8
pool: 30
development-4:
adapter: mysql2
database: TEST4_development
host: localhost
username: root
password: password
encoding: utf8
pool: 30
Then, then how we can start 4 different servers (at localhost) connecting these 4 databases simultaneously? (we normally use rails server for single instance in development.)
Thanks :)-
You are not limited to the default rails environments. You could just have development-2, development-3 environments. Read this post on the 37signals blog where DHH talks about that
database.yml can read environment variables.
development:
adapter: postgresql
host: localhost
database: <%= ENV['POSTGRES_DATABASE'] %>
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>
then make sure these are set when you start your server.
It is super easy.
Just update your database.yml file as given in the question. Suppose our development instances are development, development-2, development-3 and development-4.
First you just create 3 copies of the environment file development.rb (can find insideconfig/environments/) and rename it to development-2.rb, development-3.rb and development-4.rb.
Then, just do run the below steps before starting the servers.
RAILS_ENV=development rake db:create (OR just rake db:create as it defaults to development)
RAILS_ENV=development-2 rake db:create
RAILS_ENV=development-3 rake db:create
RAILS_ENV=development-4 rake db:create
RAILS_ENV=development rake db:schema:load (OR just rake db:schema:load as it defaults to development)
RAILS_ENV=development-2 rake db:schema:load
RAILS_ENV=development-3 rake db:schema:load
RAILS_ENV=development-4 rake db:schema:load
RAILS_ENV=development rake db:seed (OR just rake db:seed as it defaults to development)
RAILS_ENV=development-2 rake db:seed
RAILS_ENV=development-3 rake db:seed
RAILS_ENV=development-4 rake db:seed
Then, start all instances with different server pid's as given below.
rails s -p 3000 -e development --pid tmp/pids/server.pid (OR rails s by default)
rails s -p 3002 -e development-2 --pid tmp/pids/server.2.pid
rails s -p 3003 -e development-3 --pid tmp/pids/server.3.pid
rails s -p 3004 -e development-4 --pid tmp/pids/server.4.pid
That will start all instances simultaneously from the same source and a single database.yml file. Thank you all for all your replies and help :)-

Rails connects to MySQL from WEBrick but not from Passenger

I just created a new Rails 4 app with MySql as follows:
rails new mysqltest -d mysql
And modified the database.yml with the right credentials.
I generated a sample contoller and updated the routes for root route.
When I start using WEBrick in production,
rails s -e production
The site works. I see the index page.
When I start using Passenger without 3000 port, I see the following error:
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
Passsenger is running in Production environment.
My database.yml
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.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: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
database: sample
pool: 5
username: sample
password: sample
socket: /var/run/mysqld/mysqld.sock
The case I used in database.yml file and the apache config file were different.
Both should be same. eg. production.
In apache config, I gave as Production. After changing it to production it worked.
Source - https://groups.google.com/forum/#!topic/phusion-passenger/Kr-R0gSw6i8
Did you create your local production database?
rake db:create:all
RAILS_ENV=production bundle exec rake db:migrate
Is your database.yml file setup properly to use a production database?
Do you have a mysql gem in your gem file.
Common problems.