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
Related
I'm using the Hibernate framework along with Maven in IntelliJ. I'm creating a MySQL database, I also have some ORM classes that map the MySQL database, and then I'm running some JUNIT tests to make sure everything works.
Where I'm having trouble is in two places, which are related to each other:
When I run mvn test, sometimes my JUNIT tests work fine and are
able to query the simulated database, establish a connection (even
though it's just with the simulated database), execute a statement,
etc. However, sometimes, if I run mvn clean before running mvn test,
while the JUNIT tests still execute, the tests output with failures
(not errors, just failures, thought this is still bad, of course).
The problem outlined in #1 is essentially duplicated when I upload to GitHub and run CircleCI (which isn't surprising, since CircleCI runs mvn test when doing its integration testing). Most of my uploads failed, but one of them finally worked. However, I'm not exactly sure why the "final" upload was successful while the others weren't.
The error messages I'm getting either from mvn test or the CircleCI builds are typically as follows. These errors are from my pent-ultimate upload, the one I did just prior to the next upload which actually worked:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
com.mysql.cj.exceptions.CJException: Public Key Retrieval is not allowed
java.sql.SQLNonTransientConnectionException: Could not create connection to database server
I should also note that my intention is to run mvn clean first, then upload to CircleCI, however, running mvn clean seems to be somehow involved in perpetuating these errors.
As far as different resources I'm using go, here they are. If I'm forgetting something, please let me know and I should be able to include it.
In my hibernate.cfg.xml file, I have the following lines:
<property name="connection.url">jdbc:mysql://localhost:3306/stocks</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
At the end of the word "stocks" on the first line, I have sometimes appended any of the following (sometimes I only appended one of the following, other times I combined them, depending on the error(s) from either Maven or CircleCI). Appending some combination of these lines seemed to help get things to work, but running mvn clean seemed to halt any effect these additions were having:
autoReconnect=true
useSSL=false
allowPublicKeyRetrieval=true
Running the JUNIT tests from within IntelliJ usually works, but if I run mvn clean first, then IntelliJ usually won't work, unless I then go back into this file and append ?autoReconnect=true&useSSL=false. If I do that, then IntelliJ will run the JUNIT tests fine.
In my config.yml file for CircleCI, I have the following code. Certain statements were added in MAVEN_OPTS based on other research I did to try to counteract the errors I was getting, but I don't know if these statements are having any impact one way or the other:
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
- image: circleci/mysql:latest-ram
environment:
- MYSQL_ROOT_PASSWORD: (my real password goes here)
- MYSQL_DATABASE: stocks
- MYSQL_USER: bob
- MYSQL_PASSWORD: (the real password goes here)
working_directory: ~/repo
environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true -Dmaven.wagon.http.ssl.ignore.validity.dates=true
steps:
- checkout
- run: sudo apt install -y mysql-client
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: mvn dependency:go-offline
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}
# run tests!
- run: mvn integration-test
If anyone has any idea what's going on, I appreciate the help. My goal is to be able to upload to CircleCI by first running mvn clean so only the src files, pom.xml file, and .circleci folder are included in the upload. Also, not to belabor the point, but my most recent upload to CircleCI did in fact work, but I'm not sure what made that build work while all the others ones did not.
RAIL_ENV= testing or development server looks proper, but on production server not show proper GUI
As per the images shared it seems that the css and styling is not working in production environment.
For it to work, following command would be used:
RAILS_ENV=production rake assets:precompile
Reload the page and check if the css and js rules are being picked or not.
If you're using heroku perhaps you could try it on heroku. First run RAILS_ENV=production rake assets:precompile then run git add . within your working folder. Commit, push and then push to heroku master. See if you still have this issue.
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
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"
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.