locally all tests are passing but I cannot get rspec to run on Codeship:
Script:
bundle exec rake db:drop db:create db:migrate
DB=catalog bundle exec rake db:drop db:create db:migrate
DB=catalog bundle exec rails db:test:prepare
bundle exec rspec
Codeship error:
Failure/Error: establish_connection :"catalog_#{Rails.env}"
ActiveRecord::AdapterNotSpecified:
'catalog_test' database is not configured. Available: ["development", "test"]
ActiveRecord::ConnectionNotEstablished:
No connection pool with 'CatalogRecord' found.
database.yml:
.
.
.
catalog_development:
<<: *default
database: catalog_development
catalog_test:
<<: *default
database: catalog_test
CatalogRecord
class CatalogRecord < ActiveRecord::Base
self.abstract_class = true
establish_connection :"catalog_#{Rails.env}"
end
Rails projects on CodeShip Basic will have their database.yml file overwritten in order to connect to default databases. I would check out the linked documentation on re-asserting your own database.yml variant.
Related
The builds for my rails app are failing with the following error on running tests
9) FailedKeyChecks should contain a value
Failure/Error: ActiveRecord::Base.connection.execute(query)
ActiveRecord::NoDatabaseError:
FATAL: database "myapp_development" does not exist
10) User is invalid without name
Failure/Error: raise ActiveRecord::NoDatabaseError.new(error.message, error)
ActiveRecord::NoDatabaseError:
FATAL: database "myapp_development" does not exist
what am I doing wrong? My codeship.database.yml file
development:
adapter: postgresql
host: localhost
encoding: unicode
pool: 10
username: <%= ENV['PG_USER'] %>
template: template1
password: <%= ENV['PGPASSWORD'] %>
database: development<%= ENV['TEST_ENV_NUMBER'] %>
port: <%= ENV['DATABASE_PORT'] %>
sslmode: disable
test:
adapter: postgresql
host: localhost
encoding: unicode
pool: 10
username: <%= ENV['PG_USER'] %>
template: template1
password: <%= ENV['PGPASSWORD'] %>
database: test<%= ENV['TEST_ENV_NUMBER'] %>
port: <%= ENV['DATABASE_PORT'] %>
sslmode: disable
my setup commands
rvm use 2.4.1 --install
bundle install
cp codeship.database.yml config/database.yml
export RAILS_ENV=test
bundle exec rake db:create
#bundle exec rake db:migrate
bundle exec rake db:schema:load
and my test commands
RAILS_ENV=test bundle exec rake
RAILS_ENV=test bundle exec rspec
any idea why development database is being referenced? Thanks in advance
Try running bundle exec rake db:create:all
followed by bundle exec rake db:migrate
It might have failed because you forgot the 'all'
I got some problems with my rails_admin gem in the production when I trying make first user admin in Rails console.
In the development all works fine. Look at the error and code.
Error terminal:
2.3.0 :001 > u = User.first
ActiveRecord::NoDatabaseError: FATAL: database "myApp_development" does not exist
database.production.yml
default: &default
adapter: postgresql
encoding: UTF-8
pool: 5
development:
<<: *default
database: myApp_development
username: deployer
password: password
test:
<<: *default
database: myApp_test
username: deployer
password: password
production:
<<: *default
database: myApp_production
username: deployer
password: password
To run rails console in the production environment you should use bundle exec rails console production or bundle exec rails console RAILS_ENV=production, the command bundle exec rails console run console in the development env by default.
Create the database table and do
rake db:migrate RAILS_ENV=production
rails console RAILS_ENV=production
I'm noobie in rails and I have a problem with db. My database.yml:
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
And I succeeded in filling my db with this
namespace :db do
desc "Erase and fill database"
task :populate => :environment do
require 'populator'
require 'faker'
[Country, Region, City, Turbaza].each(&:delete_all)
ActiveRecord::Base.transaction do
Country.populate 5 do |country|
country.name = Faker::Address.country
Region.populate 1..2 do |region|
region.country_id = country.id
region.name = Faker::Address.state
City.populate 1..2 do |city|
city.region_id = region.id
city.name = Faker::Address.city
Turbaza.populate 1..2 do |turbaza|
turbaza.city_id = city.id
turbaza.name = Populator.words(1..3).titleize
end
end
end
end
end
end
end
So I've got my development db filled with data, but I cannot understand how I can do this to my production db and. Please, could anyone help me with this?
if you have already deployed you app into Heroku you can run you rake task via heroku-cli
https://devcenter.heroku.com/articles/heroku-command
heroku run rake db:populate
P.S Heroku provides only pg for free. So i you want to upload your up with pg i have to do
add gem 'pg' to Gemfile
bundle install
commit you changes
rebuild your project in heroku
Running heroku run rake db:populate should do the trick, have you tried? And (IMO) better solution would be just using seeds (http://railscasts.com/episodes/179-seed-data) and running heroku run rake db:seed
I am trying to learn deployment using capistrano. I want to deploy the code on a separate folder in my local machine and run migrations after deployment.
The capistrano gems used in the project are as follows
capistrano (3.4.0)
capistrano-bundler (1.1.4)
capistrano-ext (1.2.1)
capistrano-rails (1.1.3)
The application is using ruby 2.1 and rails 4.1
The deploy file is as follows
require 'capistrano/rails/migrations'
lock '3.4.0'
set :application, 'capistrano_study'
set :repo_url, 'https://github.com/xxxxxx/capistrano_study.git'
# config valid only for current version of Capistrano
set :stages, ["staging", "production"]
set :default_stage, "staging"
set :user, "prajeesh"
after "deploy:updated", "deploy:migrate"
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
staging.rb file as follows.
server 'xx.x.x.xxx', user: 'prajeesh', roles: %w{app db web}, my_property: :my_value
set :deploy_to, "/home/prajeesh/Desktop/projects/capistrano_staging"
Database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: cap_test_staging
pool: 5
username: root
password: xxxxx
# socket: /var/run/mysqld/mysqld.sock
staging:
adapter: mysql2
encoding: utf8
reconnect: false
database: cap_test_staging
pool: 5
username: root
password: xxxxx
When i run the command cap staging:deploy, the deployment is working fine. The issue is that the migrations are not running after deployment.
Does anyone know how to fix this?
Edit:
This is the error that i am getting.
INFO [175f4b0b] Running /usr/bin/env rake db:migrate as
prajeesh#xx.x.x.xxx
DEBUG [175f4b0b] Command: cd /home/prajeesh/Desktop/projects/capistrano_staging/current && ( RAILS_ENV=development /usr/bin/env rake db:migrate )
DEBUG [175f4b0b] rake aborted!
DEBUG [175f4b0b]
cannot load such file -- bundler/setup
If i run the command RAILS_ENV=development /usr/bin/env rake db:migrate directly from the project path, the migration is running but through capistrano it is not working.
Any help would be appreciated.
Hey you should run the below command to get it run command:
cap deploy:migrate
To get it run, you can see the documentation here
Updated for automating migration:
after "deploy:update_code", "deploy:migrate"
Into the file config/deploy.rb.
You should require capistrano/rails/migrations in your Capfile as mentioned in here. It'll do the trick.
If you're on Capistrano 3, I did
set :migration_role, :app in addition to adding require 'capistrano/rails/migrations' to my deploy.rb file.
(source: capistrano-rails docs)
I'm following this tutorial,
and I'm having a problem when running rake db:migrate
In db/migrate I have the create_post.rb file:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :text
t.timestamps
end
end
end
But it does not create the table.
My database.yml file is:
development:
adapter: mysql2
encoding: utf8
database: blog_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
The output from rake db:migrate seems ok.
I'm using phpMyAdmin to handle the database, which is correctly created manually by me.
What am I doing wrong?
If you are connecting to the right database everything seems fine to me.. I had a similar problem a few weeks ago and the accepted answer of this question fixed my issue.
Here are the steps to run:
rake db:drop:all
rake db:create:all
rake db:migrate
I hope it will fix your problem.
WARNING: this will erase your database.
Could you please tell which OS you got?
Delete the line:
socket: /tmp/mysql.sock
and run:
db:migrate
Give the output of:
db:migrate:status
If this is not working for you, you could also try to add:
host: 127.0.0.1
to your database.yml file
If nothing stated above works please do check your schema.rb for migration contents. If migration contents are already there then just do the below command in production:
rails db:schema:load RAILS_ENV=production.