Skip to content

Commit

Permalink
Merge pull request #4 from myabc/activerecord-5.0
Browse files Browse the repository at this point in the history
Support for Active Record 5
  • Loading branch information
ronen committed Aug 24, 2016
2 parents 8fe9ae7 + 0c9d021 commit ff0a3b6
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
---
sudo: false
rvm:
- 2.1.5
- 2.3.1
gemfile:
- gemfiles/activerecord-4.2/Gemfile.mysql2
- gemfiles/activerecord-4.2/Gemfile.postgresql
- gemfiles/activerecord-4.2/Gemfile.sqlite3
- gemfiles/activerecord-5.0/Gemfile.mysql2
- gemfiles/activerecord-5.0/Gemfile.postgresql
- gemfiles/activerecord-5.0/Gemfile.sqlite3
env: POSTGRESQL_DB_USER=postgres MYSQL_DB_USER=travis
addons:
postgresql: '9.4'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ schema_plus_indexes is tested on

<!-- SCHEMA_DEV: MATRIX - begin -->
<!-- These lines are auto-generated by schema_dev based on schema_dev.yml -->
* ruby **2.1.5** with activerecord **4.2**, using **mysql2**, **sqlite3** or **postgresql**
* ruby **2.3.1** with activerecord **5.0**, using **mysql2**, **sqlite3** or **postgresql**

<!-- SCHEMA_DEV: MATRIX - end -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
eval File.read File.expand_path('../../Gemfile.base', __FILE__)

gem "activerecord", "~> 4.2.6"
gem "activerecord", ">= 5.0.0.beta1", "< 5.1"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "pathname"
eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)

platform :ruby do
gem "mysql2", '>= 0.3.18', '< 0.5'
gem "mysql2"
end

platform :jruby do
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/schema_plus/indexes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
require 'schema_plus/core'
require 'its-it'

require_relative 'indexes/remove_if_exists'
require_relative 'indexes/active_record/base'
require_relative 'indexes/active_record/connection_adapters/abstract_adapter'
require_relative 'indexes/active_record/connection_adapters/postgresql_adapter'
require_relative 'indexes/active_record/connection_adapters/sqlite3_adapter'
require_relative 'indexes/active_record/connection_adapters/index_definition'
require_relative 'indexes/active_record/migration/command_recorder'
require_relative 'indexes/middleware/dumper'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module AbstractAdapter

# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists and not index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end

include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module PostgresqlAdapter
include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module SchemaPlus::Indexes
module ActiveRecord
module ConnectionAdapters
module Sqlite3Adapter
include ::SchemaPlus::Indexes::RemoveIfExists
end
end
end
end
2 changes: 1 addition & 1 deletion lib/schema_plus/indexes/middleware/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def after(env)
indexes = Hash[env.index_definitions.map{ |d| [d.name, d] }]

env.connection.exec_query("SELECT name, sql FROM sqlite_master WHERE type = 'index'").map do |row|
if (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
if row['sql'] && (desc_columns = row['sql'].scan(/['"`]?(\w+)['"`]? DESC\b/).flatten).any?
index = indexes[row['name']]
index.orders = Hash[index.columns.map {|column| [column, desc_columns.include?(column) ? :desc : :asc]}]
end
Expand Down
13 changes: 13 additions & 0 deletions lib/schema_plus/indexes/remove_if_exists.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module SchemaPlus::Indexes
module RemoveIfExists
# Extends rails' remove_index to include this options:
# :if_exists
def remove_index(table_name, *args)
options = args.extract_options!
if_exists = options.delete(:if_exists)
args << options if options.any?
return if if_exists && !index_name_exists?(table_name, options[:name] || index_name(table_name, *args), false)
super table_name, *args
end
end
end
4 changes: 2 additions & 2 deletions schema_dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ruby:
- 2.1.5
- 2.3.1
activerecord:
- 4.2
- 5.0
db:
- mysql2
- sqlite3
Expand Down
4 changes: 2 additions & 2 deletions schema_plus_indexes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_dependency "activerecord", "~> 4.2"
gem.add_dependency "schema_plus_core", "~> 1.0"
gem.add_dependency "activerecord", "~> 5.0"
gem.add_dependency "schema_plus_core", "~> 2.0"
gem.add_dependency "its-it", "~> 1.2"

gem.add_development_dependency "bundler", "~> 1.7"
Expand Down
2 changes: 1 addition & 1 deletion spec/command_recorder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def before(env)
end

it "does not fail when reverting" do
migration = Class.new ::ActiveRecord::Migration do
migration = Class.new ::ActiveRecord::Migration[5.0] do
define_method(:change) {
change_table("comments") do |t|
t.integer :column
Expand Down

0 comments on commit ff0a3b6

Please sign in to comment.