LoginSignup
9
8

More than 5 years have passed since last update.

Rails4.2.1のCircleCIでMySQLのutf8mb4を使うと落ちるのの修正法

Last updated at Posted at 2015-03-30

kamipo氏のutf8mb4モンキーパッチを使っていると、Rails4.2.1とCircleCIの組み合わせで下記のような感じで落ちる

$ export RAILS_ENV="test"
export RACK_ENV="test"
bundle exec rake db:create db:schema:load --trace
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
** Invoke db:schema:load (first_time)
** Invoke db:load_config 
** Execute db:schema:load
-- create_table("comments", {:force=>:cascade})
   -> 0.0058s
-- add_index("comments", ["user_id"], {:name=>"index_comments_on_user_id", :using=>:btree})
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Index column size too large. The maximum column size is 767 bytes.: CREATE  INDEX `index_comments_on_user_id` USING btree ON `comments` (`user_id`) 

CircleCIが実行しているrake db:schema:loadconfig/initializersに入っている神パッチを読んでくれないのが原因。そのため、db:schema:loadではなくdb:migrate:resetを使うようにcircle.ymlを書きかえる。

diff --git a/circle.yml b/circle.yml
index c49f32c..2ebe72a 100644
--- a/circle.yml
+++ b/circle.yml
@@ -19,3 +19,6 @@ dependencies:
 +database:
+  override:
+    - export RAILS_ENV=test; export RACK_ENV=test; bundle exec rake db:migrate:reset --trace

exportが重なっているのがびみょうに不自然だが、これは既存のCircleCIとできるかぎりあわせるため。

これでおk

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8