activerecord-redshiftbulk-adapter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.buildpath +5 -0
- data/.gitignore +26 -0
- data/.project +17 -0
- data/Gemfile +14 -0
- data/LICENSE +30 -0
- data/README.md +101 -0
- data/Rakefile +26 -0
- data/activerecord-redshift-bulk-adapter-0.0.1.gem +0 -0
- data/activerecord-redshift-bulk-adapter-0.0.2.gem +0 -0
- data/activerecord-redshift-bulk-adapter-0.0.3.gem +0 -0
- data/activerecord-redshift-bulk-adapter-0.0.4.gem +0 -0
- data/activerecord-redshiftbulk-adapter.gemspec +24 -0
- data/lib/active_record/connection_adapters/redshiftbulk_adapter.rb +1294 -0
- data/lib/activerecord_redshiftbulk/table_manager.rb +230 -0
- data/lib/activerecord_redshiftbulk_adapter.rb +4 -0
- data/lib/activerecord_redshiftbulk_adapter/version.rb +4 -0
- data/lib/monkeypatch_activerecord.rb +195 -0
- data/lib/monkeypatch_arel.rb +96 -0
- data/spec/active_record/base_spec.rb +37 -0
- data/spec/active_record/connection_adapters/redshiftbulk_adapter_spec.rb +97 -0
- data/spec/dummy/config/database.example.yml +12 -0
- data/spec/spec_helper.rb +33 -0
- metadata +136 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActiveRecord::Base do
|
4
|
+
let(:connection) { ActiveRecord::Base.redshift_connection(TEST_CONNECTION_HASH) }
|
5
|
+
|
6
|
+
describe '.redshift_connection' do
|
7
|
+
it "opens a connection" do
|
8
|
+
expect(connection).to be_active
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'set UTC timezone for datetime' do
|
13
|
+
class TimezoneTest < ActiveRecord::Base
|
14
|
+
default_timezone = :jst
|
15
|
+
establish_connection(TEST_CONNECTION_HASH.merge('adapter' => 'redshift', 'read_timezone' => 'UTC'))
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
connection.query <<-SQL
|
20
|
+
CREATE TABLE public.timezone_tests ( "id" INTEGER NULL, "created_at" TIMESTAMP NULL );
|
21
|
+
INSERT INTO public.timezone_tests VALUES (1, '2013-07-01 12:00:00');
|
22
|
+
SQL
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
connection.query <<-SQL
|
27
|
+
DROP TABLE public.timezone_tests;
|
28
|
+
SQL
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns timestamp as UTC' do
|
32
|
+
data = TimezoneTest.all.first
|
33
|
+
expect(data.created_at.zone).to eq 'UTC'
|
34
|
+
expect(data.created_at).to eq Time.parse '2013-07-01 12:00:00 UTC'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe ActiveRecord::ConnectionAdapters::RedshiftbulkAdapter do
|
4
|
+
before(:all) do
|
5
|
+
@connection = ActiveRecord::Base.redshift_connection(TEST_CONNECTION_HASH)
|
6
|
+
|
7
|
+
@connection.query <<-sql
|
8
|
+
CREATE TABLE public.test ( "id" INTEGER NULL, "name" VARCHAR(80) NULL );
|
9
|
+
CREATE TABLE public.test2 ( "id" INTEGER, "name" VARCHAR );
|
10
|
+
INSERT INTO public.test VALUES (1, 'first');
|
11
|
+
INSERT INTO public.test VALUES (2, 'second');
|
12
|
+
CREATE TABLE test.test ( "id" INTEGER NOT NULL, "is" BOOL NOT NULL );
|
13
|
+
CREATE TABLE test.test2 ( "id" INTEGER, "is" BOOL );
|
14
|
+
sql
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
@connection.query <<-sql
|
19
|
+
DROP TABLE public.test, public.test2, test.test, test.test2;
|
20
|
+
sql
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#initialize" do
|
24
|
+
it "opens a connection" do
|
25
|
+
@connection.active?.should be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#tables" do
|
30
|
+
it "returns all tables in public schema" do
|
31
|
+
@connection.schema_search_path = "public"
|
32
|
+
@connection.tables.should == ["public.test", "public.test2"]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns all tables in all schemas" do
|
36
|
+
@connection.schema_search_path = "public, test"
|
37
|
+
@connection.tables.should == ["public.test", "public.test2", "test.test", "test.test2"]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#columns" do
|
42
|
+
it "returns all columns in table in public schema" do
|
43
|
+
id = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("id", "", "integer", true)
|
44
|
+
name = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("name", "", "character varying(80)", true)
|
45
|
+
@connection.columns("test").should == [id, name]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns all columns in table" do
|
49
|
+
id = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("id", "", "integer", false)
|
50
|
+
is = ActiveRecord::ConnectionAdapters::RedshiftColumn.new("is", "", "boolean", false)
|
51
|
+
@connection.columns("test.test").should == [id, is]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#table_exists?" do
|
56
|
+
it "checks if table in schema exists" do
|
57
|
+
@connection.table_exists?("public.test").should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "checks if unknown table in schema doesn't exist" do
|
61
|
+
@connection.table_exists?("public.null").should be_false
|
62
|
+
end
|
63
|
+
|
64
|
+
it "checks if table in implied schema exists" do
|
65
|
+
@connection.table_exists?("test2").should be_true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#current_database" do
|
70
|
+
it "returns current database" do
|
71
|
+
@connection.current_database.should == TEST_CONNECTION_HASH[:database]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#schema_search_path" do
|
76
|
+
it "returns current database" do
|
77
|
+
@connection.schema_search_path = '"$user", public'
|
78
|
+
@connection.schema_search_path.should == '"$user", public'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#update_sql" do
|
83
|
+
it "returns the number of updated rows" do
|
84
|
+
@connection.update_sql("UPDATE public.test SET name = 'test'").should == 2
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "#quote_string" do
|
89
|
+
it "quotes the string without surrouding quotes" do
|
90
|
+
@connection.quote_string("quote'd").should == "quote''d"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "returns identical string when no quoting is required" do
|
94
|
+
@connection.quote_string("quote").should == "quote"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# CREATE USER test_user WITH PASSWORD 'test_password';
|
2
|
+
# CREATE SCHEMA test AUTHORIZATION test_user;
|
3
|
+
host: CLUSTERNAME.IDENTIFIER.REGION.redshift.amazonaws.com
|
4
|
+
port: 5432
|
5
|
+
username: test_user
|
6
|
+
password: test_password
|
7
|
+
database: dev
|
8
|
+
#As RedShift does not support RETURNING keyword yet
|
9
|
+
use_insert_returning: false
|
10
|
+
# ssl: true
|
11
|
+
# search_path:
|
12
|
+
# role:
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "yaml"
|
3
|
+
require "active_record/connection_adapters/redshift_adapter"
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
8
|
+
# loaded once.
|
9
|
+
#
|
10
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
22
|
+
|
23
|
+
TEST_CONNECTION_FILENAME = File.expand_path("../dummy/config/database.yml", __FILE__)
|
24
|
+
|
25
|
+
if File.exist?(TEST_CONNECTION_FILENAME)
|
26
|
+
TEST_CONNECTION_HASH = YAML.load(File.read(TEST_CONNECTION_FILENAME)).with_indifferent_access
|
27
|
+
else
|
28
|
+
puts
|
29
|
+
puts "Create #{TEST_CONNECTION_FILENAME} with connection info "
|
30
|
+
puts "for your Redshift test database in order to run the test suite."
|
31
|
+
puts
|
32
|
+
exit(1)
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-redshiftbulk-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keith Gabryelski
|
8
|
+
- Doug Ericson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: pg
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: activerecord
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 3.0.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 3.0.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: activesupport
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.0.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 3.0.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: arel
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.0.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: This gem provides the Rails 3 with database adapter for AWS RedShift.
|
85
|
+
email: redshift.bulk.gem@dougericson.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".buildpath"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".project"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- activerecord-redshift-bulk-adapter-0.0.1.gem
|
98
|
+
- activerecord-redshift-bulk-adapter-0.0.2.gem
|
99
|
+
- activerecord-redshift-bulk-adapter-0.0.3.gem
|
100
|
+
- activerecord-redshift-bulk-adapter-0.0.4.gem
|
101
|
+
- activerecord-redshiftbulk-adapter.gemspec
|
102
|
+
- lib/active_record/connection_adapters/redshiftbulk_adapter.rb
|
103
|
+
- lib/activerecord_redshiftbulk/table_manager.rb
|
104
|
+
- lib/activerecord_redshiftbulk_adapter.rb
|
105
|
+
- lib/activerecord_redshiftbulk_adapter/version.rb
|
106
|
+
- lib/monkeypatch_activerecord.rb
|
107
|
+
- lib/monkeypatch_arel.rb
|
108
|
+
- spec/active_record/base_spec.rb
|
109
|
+
- spec/active_record/connection_adapters/redshiftbulk_adapter_spec.rb
|
110
|
+
- spec/dummy/config/database.example.yml
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
homepage: https://github.com/dougericson/activerecord-redshift-adapter
|
113
|
+
licenses:
|
114
|
+
- New BSD License
|
115
|
+
metadata: {}
|
116
|
+
post_install_message:
|
117
|
+
rdoc_options: []
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
requirements: []
|
131
|
+
rubyforge_project:
|
132
|
+
rubygems_version: 2.4.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Rails 3 database adapter support for AWS RedShift.
|
136
|
+
test_files: []
|