adapter_extensions 0.9.5.rc1 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -1
- data/LICENSE +1 -1
- data/README.md +23 -0
- data/lib/adapter_extensions/connection_adapters/abstract_adapter.rb +9 -3
- data/lib/adapter_extensions/connection_adapters/mysql_adapter.rb +0 -1
- data/lib/adapter_extensions/version.rb +1 -1
- data/test/connection/postgresql/setup.sql +1 -0
- data/test/integration/adapter_test.rb +16 -10
- data/test/integration/postgresql_tests.rb +28 -0
- metadata +11 -8
- data/README +0 -7
data/CHANGELOG
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
0.9.5 -
|
1
|
+
0.9.5 - November 8, 2011
|
2
2
|
* Add in REPLACE to LOAD DATA INFILE command (jayzes/kookster)
|
3
3
|
* Remove FasterCSV from dependencies (not used apparently)
|
4
|
+
* Allow to pass options (like RESTART IDENTITY) to truncate (thbar)
|
5
|
+
* Don't print "Using AdapterExtensions" when required (thbar)
|
4
6
|
|
5
7
|
0.5 - January 14, 2009
|
6
8
|
* Updated dependencies for gem to current versions of ActiveRecord, ActiveSupport and Rake. May not be compatible with Rails versions less than 2.x.
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2011 Anthony Eden
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
4
4
|
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
This library provides extensions to Rails' ActiveRecord adapters.
|
2
|
+
|
3
|
+
As of version 0.9.5, adapter_extensions has dependencies on ActiveSupport and ActiveRecord 2.1.x or higher.
|
4
|
+
|
5
|
+
### How to test
|
6
|
+
|
7
|
+
Currently tested on MySQL and Postgres.
|
8
|
+
|
9
|
+
#### Testing on MySQL
|
10
|
+
|
11
|
+
see `test/connection/mysql/connection.rb` and tweek if needed, then:
|
12
|
+
|
13
|
+
mysql -u root -p -e "create database adapter_extensions_unittest"
|
14
|
+
rake test
|
15
|
+
|
16
|
+
One test should fail with 'known issue with MySQL' (see commit 75da4b08).
|
17
|
+
|
18
|
+
#### Testing on Postgresql
|
19
|
+
|
20
|
+
see `test/connection/postgresql/connection.rb` and tweek if needed, then:
|
21
|
+
|
22
|
+
createdb adapter_extensions_unittest
|
23
|
+
rake test DB=postgresql
|
@@ -5,9 +5,15 @@ module ActiveRecord #:nodoc:
|
|
5
5
|
# is provided, in others it is adapter-dependent and the method will
|
6
6
|
# raise a NotImplementedError if the adapter does not implement that method
|
7
7
|
class AbstractAdapter
|
8
|
-
# Truncate the specified table
|
9
|
-
|
10
|
-
|
8
|
+
# Truncate the specified table - allow to pass an optional string
|
9
|
+
# to let the called add extra parameters like RESET IDENTITY for pg
|
10
|
+
def truncate(table_name, options=nil)
|
11
|
+
statement = [
|
12
|
+
'TRUNCATE TABLE',
|
13
|
+
table_name,
|
14
|
+
options
|
15
|
+
].compact.join(' ')
|
16
|
+
execute(statement)
|
11
17
|
end
|
12
18
|
|
13
19
|
# Bulk loading interface. Load the data from the specified file into the
|
@@ -77,7 +77,6 @@ module ActiveRecord #:nodoc:
|
|
77
77
|
q << " IGNORE #{options[:ignore]} LINES" if options[:ignore]
|
78
78
|
q << " (#{options[:columns].map { |c| quote_column_name(c.to_s) }.join(',')})" if options[:columns]
|
79
79
|
|
80
|
-
puts q
|
81
80
|
if options[:disable_keys]
|
82
81
|
with_keys_disabled(table_name) { execute(q) }
|
83
82
|
else
|
@@ -6,6 +6,12 @@ class AdapterTest < Test::Unit::TestCase
|
|
6
6
|
require File.dirname(__FILE__) + "/#{ENV['DB']}_tests"
|
7
7
|
include "#{ENV['DB'].capitalize}Tests".constantize
|
8
8
|
|
9
|
+
def select_value(query)
|
10
|
+
value = connection.select_value(query)
|
11
|
+
value = Integer(value) if ENV['DB'] =~ /postgresql/
|
12
|
+
value
|
13
|
+
end
|
14
|
+
|
9
15
|
def test_add_select_into_table
|
10
16
|
new_table_name = 'new_people'
|
11
17
|
sql_query = 'select * from people'
|
@@ -19,18 +25,18 @@ class AdapterTest < Test::Unit::TestCase
|
|
19
25
|
connection.execute("insert into truncate_test (x) values ('#{value}')")
|
20
26
|
end
|
21
27
|
|
22
|
-
assert_equal
|
28
|
+
assert_equal 3, select_value("SELECT count(*) FROM truncate_test")
|
23
29
|
assert_nothing_raised { connection.truncate('truncate_test') }
|
24
|
-
assert_equal
|
30
|
+
assert_equal 0, select_value("SELECT count(*) FROM truncate_test")
|
25
31
|
end
|
26
32
|
|
27
33
|
def test_bulk_load
|
28
34
|
connection.truncate('people')
|
29
|
-
assert_equal
|
35
|
+
assert_equal 0, select_value("SELECT count(*) FROM people")
|
30
36
|
assert_nothing_raised do
|
31
37
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people.txt'), 'people')
|
32
38
|
end
|
33
|
-
assert_equal
|
39
|
+
assert_equal 3, select_value("SELECT count(*) FROM people")
|
34
40
|
end
|
35
41
|
|
36
42
|
def test_bulk_load_csv
|
@@ -39,7 +45,7 @@ class AdapterTest < Test::Unit::TestCase
|
|
39
45
|
options = {:fields => {:delimited_by => ','}}
|
40
46
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people.csv'), 'people', options)
|
41
47
|
end
|
42
|
-
assert_equal
|
48
|
+
assert_equal 3, select_value("SELECT count(*) FROM people")
|
43
49
|
end
|
44
50
|
|
45
51
|
def test_bulk_load_with_enclosed_by
|
@@ -48,7 +54,7 @@ class AdapterTest < Test::Unit::TestCase
|
|
48
54
|
options = {:fields => {:delimited_by => ',', :enclosed_by => '"'}}
|
49
55
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people.csv'), 'people', options)
|
50
56
|
end
|
51
|
-
assert_equal
|
57
|
+
assert_equal 3, select_value("SELECT count(*) FROM people")
|
52
58
|
end
|
53
59
|
|
54
60
|
def test_bulk_load_with_null_string
|
@@ -57,21 +63,21 @@ class AdapterTest < Test::Unit::TestCase
|
|
57
63
|
options = {:fields => {:delimited_by => ',', :null_string => ''}}
|
58
64
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people.csv'), 'people', options)
|
59
65
|
end
|
60
|
-
assert_equal
|
66
|
+
assert_equal 3, select_value("SELECT count(*) FROM people")
|
61
67
|
end
|
62
68
|
|
63
69
|
def test_bulk_load_interprets_empty_strings_as_empty_strings
|
64
70
|
connection.truncate('people')
|
65
71
|
options = {:fields => {:delimited_by => ','}}
|
66
72
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people_with_empties.csv'), 'people', options)
|
67
|
-
assert_equal
|
73
|
+
assert_equal 0, select_value("SELECT count(*) FROM people WHERE first_name IS NULL")
|
68
74
|
end
|
69
75
|
|
70
76
|
def test_bulk_load_interprets_empty_strings_as_nulls
|
71
77
|
connection.truncate('people')
|
72
78
|
options = {:fields => {:delimited_by => ',', :null_string => ''}}
|
73
79
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people_with_empties.csv'), 'people', options)
|
74
|
-
assert_equal
|
80
|
+
assert_equal 1, select_value("SELECT count(*) FROM people WHERE first_name IS NULL"),
|
75
81
|
"NOTE: this is a known issue with MySQL - any other db should work correctly"
|
76
82
|
end
|
77
83
|
|
@@ -108,7 +114,7 @@ class AdapterTest < Test::Unit::TestCase
|
|
108
114
|
options = {:fields => {:delimited_by => ',', :enclosed_by => '"'}}
|
109
115
|
connection.bulk_load(File.join(File.dirname(__FILE__), 'people.csv'), 'people', options)
|
110
116
|
connection.copy_table(table_name, dest_table_name)
|
111
|
-
assert_equal 3,
|
117
|
+
assert_equal 3, select_value("SELECT count(*) FROM #{dest_table_name}").to_i
|
112
118
|
end
|
113
119
|
|
114
120
|
private
|
@@ -3,4 +3,32 @@ module PostgresqlTests
|
|
3
3
|
# TODO: mock connection adapter?
|
4
4
|
assert connection.support_select_into_table?
|
5
5
|
end
|
6
|
+
|
7
|
+
def blank_slate!
|
8
|
+
connection.truncate('truncate_test', 'RESTART IDENTITY')
|
9
|
+
assert_equal "0", connection.select_value("SELECT count(*) FROM truncate_test")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_truncate_should_not_reset_identity_by_default
|
13
|
+
blank_slate!
|
14
|
+
|
15
|
+
connection.execute("insert into truncate_test (x) values ('a')")
|
16
|
+
connection.truncate('truncate_test')
|
17
|
+
|
18
|
+
connection.execute("insert into truncate_test (x) values ('a')")
|
19
|
+
# in this case the id should not be reset to 1
|
20
|
+
assert_equal "2", connection.select_value("SELECT id FROM truncate_test")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_truncate_should_reset_identity_if_requested
|
24
|
+
blank_slate!
|
25
|
+
|
26
|
+
connection.execute("insert into truncate_test (x) values ('a')")
|
27
|
+
connection.truncate('truncate_test', 'RESTART IDENTITY')
|
28
|
+
|
29
|
+
connection.execute("insert into truncate_test (x) values ('a')")
|
30
|
+
# when using RESTART IDENTITY the id should be reset to 1
|
31
|
+
assert_equal "1", connection.select_value("SELECT id FROM truncate_test")
|
32
|
+
end
|
33
|
+
|
6
34
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adapter_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 49
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 9
|
8
9
|
- 5
|
9
|
-
|
10
|
-
version: 0.9.5.rc1
|
10
|
+
version: 0.9.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Anthony Eden
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-12-18 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: rake
|
@@ -27,6 +26,7 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - ">="
|
29
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 57
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 8
|
@@ -42,6 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 11
|
45
46
|
segments:
|
46
47
|
- 2
|
47
48
|
- 1
|
@@ -57,6 +58,7 @@ dependencies:
|
|
57
58
|
requirements:
|
58
59
|
- - ">="
|
59
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 11
|
60
62
|
segments:
|
61
63
|
- 2
|
62
64
|
- 1
|
@@ -79,7 +81,7 @@ files:
|
|
79
81
|
- Gemfile
|
80
82
|
- HOW_TO_RELEASE
|
81
83
|
- LICENSE
|
82
|
-
- README
|
84
|
+
- README.md
|
83
85
|
- Rakefile
|
84
86
|
- adapter_extensions.gemspec
|
85
87
|
- lib/adapter_extensions.rb
|
@@ -101,7 +103,6 @@ files:
|
|
101
103
|
- test/integration/people_with_empties.csv
|
102
104
|
- test/integration/postgresql_tests.rb
|
103
105
|
- test/test_helper.rb
|
104
|
-
has_rdoc: true
|
105
106
|
homepage: https://github.com/activewarehouse/adapter_extensions
|
106
107
|
licenses: []
|
107
108
|
|
@@ -115,6 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
116
|
requirements:
|
116
117
|
- - ">="
|
117
118
|
- !ruby/object:Gem::Version
|
119
|
+
hash: 3
|
118
120
|
segments:
|
119
121
|
- 0
|
120
122
|
version: "0"
|
@@ -123,6 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
125
|
requirements:
|
124
126
|
- - ">="
|
125
127
|
- !ruby/object:Gem::Version
|
128
|
+
hash: 23
|
126
129
|
segments:
|
127
130
|
- 1
|
128
131
|
- 3
|
@@ -131,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
134
|
requirements: []
|
132
135
|
|
133
136
|
rubyforge_project: activewarehouse
|
134
|
-
rubygems_version: 1.
|
137
|
+
rubygems_version: 1.8.10
|
135
138
|
signing_key:
|
136
139
|
specification_version: 3
|
137
140
|
summary: Extensions to Rails ActiveRecord adapters.
|
data/README
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
This library provides extensions to Rails' ActiveRecord adapters.
|
2
|
-
|
3
|
-
As of version 0.5, adapter_extensions has dependencies on ActiveSupport and ActiveRecord 2.1.x or higher.
|
4
|
-
|
5
|
-
To use the MySQL adapter extensions with Rails 2.x, you must patch the mysql_adapter with the mysql_adapter_opt_local_infile.patch.
|
6
|
-
|
7
|
-
To execute the unit tests you must first construct a adapter_extensions_unittest database.
|