Created
June 27, 2014 01:59
-
-
Save jbrowning/4a20f1db010e42c3cafe to your computer and use it in GitHub Desktop.
ActiveRecord rename index error for MariaDB 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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