Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 support #79

Merged
merged 26 commits into from Jul 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cdf35c5
Update git ignores.
spectator Feb 14, 2013
a8e8b62
Get rid of Jeweler, rubygems and bundler can do the same job, but bet…
spectator Feb 14, 2013
1cdd79f
KIll some whitespaces.
spectator Feb 14, 2013
c18bfc0
Update AR syntax.
spectator Feb 14, 2013
b1d29ea
Make sure we're in the same timezone.
spectator Feb 14, 2013
6c728b1
Add missed update for new GF syntax.
spectator Feb 14, 2013
2c9112b
Kill some whitespaces.
spectator Feb 14, 2013
ccc5b04
Update gem file.lock with bumped version.
spectator Feb 14, 2013
b1e8582
Use AR3 and AR4 compatible syntax.
spectator Feb 14, 2013
4bde79c
More whitespaces cleanup.
spectator Feb 14, 2013
965d0b3
Make sure attributes cache is dropped. This makes synchronize work on…
spectator Feb 14, 2013
57c9043
Kill whitespaces.
spectator Feb 14, 2013
24417ca
Cleanup more whitespaces.
spectator Feb 15, 2013
8634cfc
Move mysql gem to appraisals to avoid issues with bundler locking wro…
spectator Feb 15, 2013
dfd6520
Ignore Gemfile.lock, it's not valid file for gemspec anymore.
spectator Mar 5, 2013
9017c9a
Use secure source and Rails 4 beta.
spectator Mar 5, 2013
c7d8a2a
Secure source and Rails 4 beta.
spectator Mar 5, 2013
39c855a
Remove whitespaces.
spectator Mar 5, 2013
725cea1
Require ruby-debug only for Ruby < 1.9
spectator Mar 5, 2013
2df47df
Correct AR syntax.
spectator Mar 13, 2013
89db29c
Use latest Rails 4 RC2.
spectator Jun 14, 2013
a6f73d6
Use TRADITIONAL mode for MySQL / Postgres.
spectator Jun 14, 2013
adc345e
Set strict mode to false for MySQL only.
spectator Jun 14, 2013
7acc7aa
Replace Appraisals with simple conditionals in gemfile.
spectator Jun 15, 2013
d48d1ee
Correct class name for SQLite3.
spectator Jun 15, 2013
161dc35
Update SeamlessDatabasePool gem.
spectator Jun 15, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -17,6 +17,8 @@ tmtags
coverage
rdoc
pkg
*.gem
*.lock

## PROJECT::SPECIFIC
log/*.log
Expand All @@ -26,4 +28,4 @@ test/database.yml
.bundle/
.redcar/
.rvmrc
docsite/
docsite/
70 changes: 33 additions & 37 deletions Gemfile
@@ -1,42 +1,38 @@
source :gemcutter
source 'https://rubygems.org'

gem "activerecord", "~> 3.0"
gemspec

group :development do
gem "rake"
gem "jeweler", ">= 1.4.0"
# Database Adapters
platforms :ruby do
gem "mysql2", "~> 0.3.0"
gem "pg", "~> 0.9"
gem "sqlite3-ruby", "~> 1.3.1"
gem "seamless_database_pool", "~> 1.0.13"
end

group :test do
# Database Adapters
platforms :ruby do
gem "mysql", "~> 2.8.1"
gem "mysql2", "~> 0.3.0"
gem "pg", "~> 0.9"
gem "sqlite3-ruby", "~> 1.3.1"
gem "seamless_database_pool", "~> 1.0.11"
end

platforms :jruby do
gem "jdbc-mysql"
gem "activerecord-jdbcmysql-adapter"
end

# Support libs
gem "factory_girl", "~> 1.3.3"
gem "delorean", "~> 0.2.0"

# Debugging
platforms :mri_18 do
gem "ruby-debug", "= 0.10.4"
end

platforms :jruby do
gem "ruby-debug-base", "= 0.10.4"
gem "ruby-debug", "= 0.10.4"
end

platforms :mri_19 do
gem "debugger"
end
platforms :jruby do
gem "jdbc-mysql"
gem "activerecord-jdbcmysql-adapter"
end

# Support libs
gem "factory_girl", "~> 4.2.0"
gem "delorean", "~> 0.2.0"

# Debugging
platforms :mri_18 do
gem "ruby-debug", "= 0.10.4"
end

platforms :jruby do
gem "ruby-debug-base", "= 0.10.4"
gem "ruby-debug", "= 0.10.4"
end

platforms :mri_19, :mri_20 do
gem "debugger"
end

version = ENV['RAILS_VERSION'] || "3.2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RAILS_VERSION is shorter but technically it should be ACTIVERECORD_VERSION or AR_VERSION. Thoughts?


eval_gemfile File.expand_path("../gemfiles/#{version}.gemfile", __FILE__)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how you're loading gemfiles for different versions of Rails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure whichever is better. AR_VERSION sounds good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, replied to wrong message.

Thanks, I think Steve Klabnik blogged about this so this is his idea :)

85 changes: 0 additions & 85 deletions Gemfile.lock

This file was deleted.

23 changes: 0 additions & 23 deletions Rakefile
Expand Up @@ -4,29 +4,6 @@ Bundler.setup
require 'rake'
require 'rake/testtask'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "activerecord-import"
gem.summary = %Q{Bulk-loading extension for ActiveRecord}
gem.description = %Q{Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyond}
gem.email = "zach.dennis@gmail.com"
gem.homepage = "http://github.com/zdennis/activerecord-import"
gem.authors = ["Zach Dennis"]
gem.files = FileList["VERSION", "Rakefile", "README*", "lib/**/*"]

bundler = Bundler.load
bundler.dependencies_for(:default).each do |dependency|
gem.add_dependency dependency.name, *dependency.requirements_list
end

# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

namespace :display do
task :notice do
puts
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

78 changes: 16 additions & 62 deletions activerecord-import.gemspec
@@ -1,68 +1,22 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/activerecord-import/version', __FILE__)

Gem::Specification.new do |s|
s.name = "activerecord-import"
s.version = "0.2.10"
Gem::Specification.new do |gem|
gem.authors = ["Zach Dennis"]
gem.email = ["zach.dennis@gmail.com"]
gem.summary = "Bulk-loading extension for ActiveRecord"
gem.description = "Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyond"
gem.homepage = "http://github.com/zdennis/activerecord-import"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Zach Dennis"]
s.date = "2012-08-30"
s.description = "Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyond"
s.email = "zach.dennis@gmail.com"
s.extra_rdoc_files = [
"README.markdown"
]
s.files = [
"README.markdown",
"Rakefile",
"VERSION",
"lib/activerecord-import.rb",
"lib/activerecord-import/active_record/adapters/abstract_adapter.rb",
"lib/activerecord-import/active_record/adapters/jdbcmysql_adapter.rb",
"lib/activerecord-import/active_record/adapters/mysql2_adapter.rb",
"lib/activerecord-import/active_record/adapters/mysql_adapter.rb",
"lib/activerecord-import/active_record/adapters/postgresql_adapter.rb",
"lib/activerecord-import/active_record/adapters/seamless_database_pool_adapter.rb",
"lib/activerecord-import/active_record/adapters/sqlite3_adapter.rb",
"lib/activerecord-import/adapters/abstract_adapter.rb",
"lib/activerecord-import/adapters/mysql_adapter.rb",
"lib/activerecord-import/adapters/postgresql_adapter.rb",
"lib/activerecord-import/adapters/sqlite3_adapter.rb",
"lib/activerecord-import/base.rb",
"lib/activerecord-import/import.rb",
"lib/activerecord-import/mysql.rb",
"lib/activerecord-import/mysql2.rb",
"lib/activerecord-import/postgresql.rb",
"lib/activerecord-import/sqlite3.rb",
"lib/activerecord-import/synchronize.rb"
]
s.homepage = "http://github.com/zdennis/activerecord-import"
s.require_paths = ["lib"]
s.rubygems_version = "1.8.24"
s.summary = "Bulk-loading extension for ActiveRecord"
gem.files = `git ls-files`.split($\)
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.name = "activerecord-import"
gem.require_paths = ["lib"]
gem.version = ActiveRecord::Import::VERSION

if s.respond_to? :specification_version then
s.specification_version = 3
gem.required_ruby_version = ">= 1.9.2"

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0"])
s.add_development_dependency(%q<rake>, [">= 0"])
s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0"])
else
s.add_dependency(%q<activerecord>, ["~> 3.0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
s.add_dependency(%q<activerecord>, ["~> 3.0"])
end
else
s.add_dependency(%q<activerecord>, ["~> 3.0"])
s.add_dependency(%q<rake>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
s.add_dependency(%q<activerecord>, ["~> 3.0"])
end
gem.add_runtime_dependency "activerecord", ">= 3.0"
gem.add_development_dependency "rake"
end

4 changes: 4 additions & 0 deletions gemfiles/3.1.gemfile
@@ -0,0 +1,4 @@
platforms :ruby do
gem 'mysql', '~> 2.8.1'
gem 'activerecord', '~> 3.1.0'
end
4 changes: 4 additions & 0 deletions gemfiles/3.2.gemfile
@@ -0,0 +1,4 @@
platforms :ruby do
gem 'mysql', '~> 2.8.1'
gem 'activerecord', '~> 3.2.0'
end
4 changes: 4 additions & 0 deletions gemfiles/4.0.gemfile
@@ -0,0 +1,4 @@
platforms :ruby do
gem 'mysql', '~> 2.9'
gem 'activerecord', '~> 4.0.0.rc2'
end
26 changes: 13 additions & 13 deletions lib/activerecord-import/adapters/abstract_adapter.rb
@@ -1,60 +1,60 @@
module ActiveRecord::Import::AbstractAdapter
NO_MAX_PACKET = 0
QUERY_OVERHEAD = 8 #This was shown to be true for MySQL, but it's not clear where the overhead is from.

module ClassMethods
def get_insert_value_sets( values, sql_size, max_bytes ) # :nodoc:
value_sets = []
value_sets = []
arr, current_arr_values_size, current_size = [], 0, 0
values.each_with_index do |val,i|
comma_bytes = arr.size
sql_size_thus_far = sql_size + current_size + val.bytesize + comma_bytes
if NO_MAX_PACKET == max_bytes or sql_size_thus_far <= max_bytes
current_size += val.bytesize
current_size += val.bytesize
arr << val
else
value_sets << arr
arr = [ val ]
current_size = val.bytesize
end

# if we're on the last iteration push whatever we have in arr to value_sets
value_sets << arr if i == (values.size-1)
end
[ *value_sets ]
end
end

module InstanceMethods
def next_value_for_sequence(sequence_name)
%{#{sequence_name}.nextval}
end

# +sql+ can be a single string or an array. If it is an array all
# elements that are in position >= 1 will be appended to the final SQL.
def insert_many( sql, values, *args ) # :nodoc:
# the number of inserts default
number_of_inserts = 0

base_sql,post_sql = if sql.is_a?( String )
[ sql, '' ]
elsif sql.is_a?( Array )
[ sql.shift, sql.join( ' ' ) ]
end
sql_size = QUERY_OVERHEAD + base_sql.size + post_sql.size

sql_size = QUERY_OVERHEAD + base_sql.size + post_sql.size

# the number of bytes the requested insert statement values will take up
values_in_bytes = values.sum {|value| value.bytesize }

# the number of bytes (commas) it will take to comma separate our values
comma_separated_bytes = values.size-1

# the total number of bytes required if this statement is one statement
total_bytes = sql_size + values_in_bytes + comma_separated_bytes

max = max_allowed_packet

# if we can insert it all as one statement
if NO_MAX_PACKET == max or total_bytes < max
number_of_inserts += 1
Expand Down
4 changes: 2 additions & 2 deletions lib/activerecord-import/adapters/mysql_adapter.rb
Expand Up @@ -12,9 +12,9 @@ def max_allowed_packet # :nodoc:
val.to_i
end
end

# Returns a generated ON DUPLICATE KEY UPDATE statement given the passed
# in +args+.
# in +args+.
def sql_for_on_duplicate_key_update( table_name, *args ) # :nodoc:
sql = ' ON DUPLICATE KEY UPDATE '
arg = args.first
Expand Down