Rails looking for a databases not specified by database.yml - mysql

I recently pulled some code and ran rspec. The tests passed with no problem. When I ran "rake db:migrate" and "rake db:prepare" however, I got an issue.
Now no rspec test passes, and every failure cites the same error:
Mysql2::Error: Table 'app_test.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`
The thing is, that database name is not specified anywhere in the code. In database.yml, 'app_test' is specified, with no '.admins' suffix.
Similarly, when I run rails server, I get the following error:
Mysql2::Error: Table 'app_dev.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`
Only 'app_dev' is specified in yml.
The rake commands (db:migrate, db:test:prepare, db:create, db:drop, etc.) are all modifying the database.yml specified databases, it's just that Rails is looking for databases with the '.admins' suffix. Where is this '.admins' suffix coming from and how can I remove it?

app_test and app_dev are database names.
it's just that Rails is looking for databases with the '.admins'
suffix.
Actually app_test.admins and app_dev.admins are tables that rails is looking for in the two databases. Couple of approaches that I would try:
rake db:create
rake db:migrate
or
rake db:schema:load

The issue was as follows:
When I pulled the code, for whatever reason, the 'Admins' table disappeared from db/schema.rb. This table cannot be restored via rake:db:migrate because the migration that created it uses t.database_authenticatable, which has been deprecated and no longer works with the Devise gem. Because we're building on legacy code, we only run rake db:migrate on recently changed migrations, never from an empty database (for an empty database, we use rake db:schema:load).
Since the table was missing from db/schema.rb it would not be restored even if I used rake db:schema:load. To fix the issue, I had to use git reset to revert to an old version of db/schema.rb.
To fix the Devise deprecation issue so that you can run all of your migrations, go here - https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style

Is rake db:prepare a valid command? Did you try rake db:create:all?

Is it possible that your rails-settings-cached is configured to use admin table? Do you remember typing rails g settings admin?
Check in your models for a admin.rb file, or for a model that derivates from RailsSettings::CachedSettings
Check your initializers for the same gem as well

Related

gitlab Health Check is Unhealthy

I'm migration my gitlab to another server. the old gitlab server use postgresql and the new gitlab server use mysql.
I'm convert it with tools calld “DBConvert for MySQL & PostgreSQL”.
Database had sucess convert , and the repo files also copyd to the new gitlab server.
But my projects can't use , when click the projects it notice http code 500.
In gitlab Health check ,it notice
Migrations are pending.
To resolve this issue, run: bin/rake db:migrate RAILS_ENV=production"
And when I run this cmd , it notice "No Rakefile found"
How to proceed from there?
Make sure to execute bin/rake db:migrate RAILS_ENV=production from your GitLab-CE installation folder.
Or try from the same GitLab folder:
bundle exec rake db:migrate RAILS_ENV=production"
my src and dst gitlab version are 8.8.4 , it's the same
In that case, simply do not execute any db:migrate RAILS_ENV=production: that will avoid creating duplicate tables.
Problem is resloved , see link How to resloved "Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=production".

How to run db:setup in Capistrano 3 and Rails 4

Just getting started with Capistrano 3, and I noticed on one of my first deploys for my_app that it was complaining about the MySQL database not existing.
DEBUG [aec39935] ActiveRecord::NoDatabaseError: Unknown database 'my_app'
Well that's expected, since this a brand new deploy to a clean server. I included the capistrano-rails gem that's meant to take care of db migrations
require 'capistrano/rails/migrations'
I'd expect it to run db:create before db:migrate so that the database is created, but looks like it doesn't.
Is there a way for me to manually add this in, or reconfigure it so that it does run it?
Thanks.
To my knowledge, you can either create a special task to do this, or just run db:setup manually once. I'd personally recommend the latter.
If you want to make a custom task, take a look at the rails/migration task as an example: https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/migrations.rake#L15

rake failure due to imagemagick

I'm seeding a development database (mysql) using rake db:seed in Rails 3. The rake task fails, stating,
Validation failed: Logo /var/folders/.../logo.png is not recognized by the 'identify' command.
When I run which identify, I get the expected path /usr/local/bin/identify. ImageMagick is indeed installed (via Homebrew), and appears to work with png images just fine from the command line.
I even rebuilt the app on another machine, thinking that my environment is borked, and I got the same error.
Is there a poltergeist in my terminal sessions?
Have you tried running a bundle exec before the rake. In the past this has often solved these sorts of problems for me. It will ensure your rails environment is loaded before running the rake task.
bundle exec rake db:seed
Hope that helps!
// Addition
Also are you using the Paperclip gem to do this import? I do remember that I needed to ensure the path to ImageMagick was set in my development.rb file to ensure this was picked up.
Eg.
Paperclip.options[:command_path] = "/usr/local/bin"

Rails 3 Mysql rake db:create issue

I've recently upgraded to Rails 3 and am getting the following issue when trying to run rake db:create to create a mysql database of which has been defined in database.yml
Some info about my setup:
running snow leopard
rails gem v3.0.3
mysql gem v2.8.1
mysql 5.5.8
I'm presented with this issue:
$rake db:create
(in /Users/elliottheis/Sites/demoProject)
rake aborted!
uninitialized constant Mysql::Error
(See full trace by running task with --trace)
Does anyone have any ideas how to solve this, it's driving me nuts!
Make sure Mysql is in your Gemfile and the database.yml is setup for Mysql. Uninitialized constant simply and will most likely always mean you have not told Rails where to find it. It you can type mysql -uroot into Terminal and see the Version then you know that MySql is fine. Try post a bit more information and we will see if we cant get to the bottom of this.
rake -r mysql db:create --trace
If this does not work then something has gone wrong in the installation. Try This.
Uninstall Mysql - Follow these instructions
Reinstall Mysql - Follow these instructions
Let us know how you get on and tell us the solution when you get it. All the best
I know this has already been answered, but in case this happens to someone else, my issue was identical to Elliot's.
However, my fix revolved around using mysql gem 2.8 and Snow Leopard, which which is explained in another Stackoverflow thread:
As it turns out, that class should not exist; the error message is
caused by a problem with the latest Mysql driver. mysql-2.8.1 looked
for my libraries in a directory named with an extra level of ‘mysql’
at the end. For instance, my libraries (under MacOS X 10.5.8), are in
/usr/local/mysql/lib, but the mysql.bundle library looks for the MySQL
libraries at /usr/local/mysql/lib/mysql … which is wrong.
So I needed to install the mysql gem version before 2.8. Follow the instructions on this Web site, and your issue should be resolved.

push Rails3 on Heroku. can not find mysql gem

i'm getting an error when pushing to heroku using rails 3. I'm on windows with ruby 1.8.7
Administrator#WIN-DQC3IH63U7C ~/nasha (master)
$ heroku rake db:migrate
rake aborted!
no such file to load -- mysql
/disk1/home/slugs/280561_9c64ba2_1741/mnt/Rakefile:4
(See full trace by running task with --trace)
(in /disk1/home/slugs/280561_9c64ba2_1741/mnt)
Heroku doesn't use the database you use for running your application locally.
Heroku uses PostgreSQL (http://docs.heroku.com/database)
Did you freeze Rails into vendor? This problem usually appears with Heroku when you freeze Rails. You must leave Heroku use it's own Rails based on your .gems file. You can read more about this here http://docs.heroku.com/gems#heroku-gem-manifest
If this is not the problem, did you follow the instructions regarding Heroku and Rails 3 applications? You can read about it here http://docs.heroku.com/rails3 Please notice that you must setup the Bamboo Stack for your Rails 3 application to work correctly.
You need have the mysql gem in your Gemfile
gem "mysql"