Skip to content

Instantly share code, notes, and snippets.

@jbrowning
Created June 27, 2014 01:59
Show Gist options
  • Save jbrowning/4a20f1db010e42c3cafe to your computer and use it in GitHub Desktop.
Save jbrowning/4a20f1db010e42c3cafe to your computer and use it in GitHub Desktop.
ActiveRecord rename index error for MariaDB 10
gem 'activerecord', '4.1.2'
gem 'mysql2'
require 'active_record'
require 'minitest/autorun'
require 'logger'
DATABASE_NAME = 'rename_index_test'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
ActiveRecord::Base.establish_connection(adapter: 'mysql2', database: DATABASE_NAME)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts, force: true do |t|
end
create_table :comments, force: true do |t|
t.integer :post_id
end
add_index :comments, :post_id, name: "comments_post_index"
end
class RenamePostIndex < ActiveRecord::Migration
def change
change_table :comments do |t|
t.rename_index :comments_post_index, :comments_post_id_index
end
end
end
class BugTest < Minitest::Test
def test_rename_index
# Raises ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax;
# check the manual that corresponds to your MariaDB server version for the right syntax to
# use near 'INDEX `comments_post_index` TO `comments_post_id_index`' at line 1: ALTER TABLE
# `comments` RENAME INDEX `comments_post_index` TO `comments_post_id_index`
RenamePostIndex.new.change
end
end
source 'https://rubygems.org'
gem 'activerecord', '4.1.2'
gem 'mysql2'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment