Rake assets precompile failing - activerecord

rails 3.2
In my database.yml, I have:
development: &default
adapter: mysql2
encoding: utf8
reconnect: false
database: mydb
pool: 5
username: 'mydb'
password: 'mypwd'
staging:
<<: *default
host: localhost
sandbox:
<<: *default
host: localhost
When I run:
RAILS_ENV=sandbox
RAILS_GROUPS=assets
bundle exec rake assets:precompile
I get the following:
rake aborted!
ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter
If I do:
RAILS_ENV=staging
RAILS_GROUPS=assets
bundle exec rake assets:precompile
It completes correctly. The staging and sandbox setting are the same. Any idea what's going on here?

Related

how can I fix the fe_sendauth: no password supplied error?

This is my database.yml file.
I am trying to create database for a ruby app but the error always pops up
"fe_sendauth: no password supplied"
Tried to createuser - w --no-password on the CLI ended up with the same error.
Any help to fix this please ?
default: &default
adapter: postgresql
encoding: unicode
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>

No such image in gitlab-ci with docker-in-docker

I'm use docker-api in my rails project.
I'm need create containers with my custom image.
.gitlab-ci.yml:
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DB_HOST: postgres
RAILS_ENV: test
build:
stage: build
image: docker:19.03.0
services:
- docker:19.03.0-dind
script:
- docker build -t my_image docker/my_image/.
rspec:
image: ruby:2.6.3
services:
- postgres:10.1
- docker:19.03.0-dind
script:
- export DOCKER_URL=tcp://docker:2375
- cp config/database.yml.gitlab_ci config/database.yml
- gem install bundler
- bundle install
- rails db:create
- rails db:migrate
- rspec
I'm got error:
Failure/Error:
container = Docker::Container.create('Cmd' => ['tail', '-f', '/dev/null'],
'Image' => 'my_image')
Docker::Error::NotFoundError:
No such image: my_image:latest
How solve this problem?
Each job you specified will use a different instance of dind.
You probably need to push the image from first job and pull it in the second job.
.gitlab-ci.yml:
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DB_HOST: postgres
RAILS_ENV: test
rspec:
image: ruby:2.6.3
services:
- postgres:10.1
- docker:19.03.0-dind
script:
- cp config/database.yml.gitlab_ci config/database.yml
- gem install bundler
- bundle install
- export DOCKER_URL=tcp://docker:2375
- rails db:create
- rails db:migrate
- rake create_image
- rspec
rubocop:
image: ruby:2.6.3
script:
- gem install bundler
- bundle install
- bundle exec rubocop
artifacts:
expire_in: 10 min
create_image.rake
task :create_image do
image = Docker::Image.build_from_dir('./docker/my_image/.')
image.tag('repo' => 'my_image', 'tag' => 'latest', force: true)
end

Unable to create database with ActiveRecord from script

The commands I run:
config['development']
=> {"adapter"=>"mysql2", "encoding"=>"utf8mb4", "collation"=>"utf8mb4_bin", "pool"=>1, "username"=>"root", "password"=>nil, "host"=>"localhost", "database"=>"my_db"}
ActiveRecord::Base.establish_connection(config['development'])
=> #<ActiveRecord::ConnectionAdapters::ConnectionPool:0x007fe20592b348 ...
ActiveRecord::Base.connection.create_database(config['development']['database'])
ActiveRecord::NoDatabaseError: Unknown database 'my_db'
It says unknown database but I am actually trying to create the database with create_database and I follow the docs:
https://apidock.com/rails/ActiveRecord/ConnectionAdapters/PostgreSQLAdapter/create_database
Why is it not working?
Given database.yml:
database.yml
default: &default
adapter: mysql2
encoding: utf8mb4
collation: utf8mb4_bin
pool: 5
username: root
password:
host: localhost
development:
<<: *default
database: my_db
test:
<<: *default
database: my_db_test
I got it working by establishing a connection without the database and then creating the database:
#config = YAML.load(File.open(File.expand_path('../../lib/my_gem_config/database.yml', __FILE__)))
ActiveRecord::Base.establish_connection(config['default'])
ActiveRecord::Base.connection.create_database(#config['development']['database'])
When creating a database in postgres it will use a "template" database to make a copy. I haven't read the source code on how ActiveRecord::Base.connection.create_database actually works and if it indeed does the same. I was able to create the database with your code except that for my config hash I merged: database: 'postgres', schema_search_path: 'public' and that seemed to do the trick. In my case 'postgres' is my template database.

gitlab community unable to login

I followed the directions here https://github.com/gitlabhq/gitlab-recipes/blob/master/install/centos/README.md and have the gitlab community page up and running but I cannot login.
Someone suggested doing this:
bundle exec rake db:seed_fu RAILS_ENV=production
(in /home/git/gitlab)
I got a FATAL error suggesting no role for root, I then followed this:
FATAL: role "root" does not exist
and created a role, now I get this error:
[root#gitlab gitlab]# bundle exec rake db:seed_fu RAILS_ENV=production
== Seed from /home/git/gitlab/db/fixtures/production/001_admin.rb
rake aborted!
ActiveRecord::StatementInvalid: PG::Error: ERROR: permission denied for relation users
: SELECT 1 AS one FROM "users" WHERE "users"."email" = 'admin#example.com' LIMIT 1
/home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/seed-fu-2.3.1/lib/seed-fu/runner.rb:46:in `eval'
[root#gitlab gitlab]# sudo -u git -H cat config/database.yml
#
# PRODUCTION
#
production:
adapter: postgresql
encoding: unicode
database: gitlabhq_production
pool: 10
# username: git
# password:
# host: localhost
# port: 5432
#
# Development specific
#
development:
adapter: postgresql
encoding: unicode
database: gitlabhq_development
pool: 5
username: postgres
password:
#
# Staging specific
#
staging:
adapter: postgresql
encoding: unicode
database: gitlabhq_staging
pool: 5
username: postgres
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: &test
adapter: postgresql
encoding: unicode
database: gitlabhq_test
pool: 5
username: postgres
password:
Please help. I do not know ruby and I also don't know postgresql

Running both MongoDB and Mysql on Rails 2.3.6

In Rails 2.3.6 I'm trying to use both MongoDb via MongoMapper and Mysql on the same application.
I've seen several others question about this but I cannot find how to configure rails to use both database in the same app.
How should I configure my database.yml file?
Right now it is:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
test:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_rails_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql
encoding: utf8
reconnect: false
database: blinddog_rails_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Should I add some intializers?
Thanks in advance,
Augusto
So you would use active record and standard database.yml file. You would also run rails g mongo_mapper:config to create your mongo.yml file. These are seperate and should allow you to use both in your model. This would work for mongoid too.

Resources