redshift_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/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +2 -0
- data/lib/active_record/connection_adapters/redshift_adapter.rb +69 -0
- data/lib/redshift_adapter/version.rb +3 -0
- data/lib/redshift_adapter.rb +5 -0
- data/redshift_adapter.gemspec +23 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3db76d4c535d7b5de1e6c05c53002a30157464fe
|
4
|
+
data.tar.gz: e90035449abc2b920c3d5824bd795ed712540c15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e901f0c9c443574bf685f537692490a14745fc9bef6b0ca69f8e0b8617d5faafc4d2427094b1d2eb7b82373aa826ee6f888845b9b18b19fb924d0c641feed36e
|
7
|
+
data.tar.gz: b3abd1bc8e47be96b1b92aeec4ed1e85e5bb1caaace26782c46d9d58ad1e6ec3a848516caa5bb3c084f4f6f364a46489f59f442f0a6a939c9f9e746f0e0f05d8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Fonix Mobile Ltd. (UK)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# RedshiftAdapter
|
2
|
+
|
3
|
+
ActiveRecord adapter for Amazon Redshift database. The gem overrides a minimal amount of code in the postgres adapter that ships with ActiveRecord to work. We only use this adapter for querying redshift so it is possible that inserting/updating is completely broken.
|
4
|
+
|
5
|
+
Here is a list of things that are broken in redshift that we work around:
|
6
|
+
|
7
|
+
=# show client_min_messages;
|
8
|
+
ERROR: must be superuser to examine "client_min_messages"
|
9
|
+
|
10
|
+
=# set time zone utc;
|
11
|
+
ERROR: SET TIME ZONE is not supported
|
12
|
+
|
13
|
+
=# SET standard_conforming_strings = on;
|
14
|
+
ERROR: unrecognized configuration parameter "standard_conforming_strings"
|
15
|
+
|
16
|
+
This functions are overriden to do nothing. The main thing I'm worried about is `standard_conforming_strings`. Not being able to set this value may have introduced SQL injection somewhere. I'm fairly confident that normal strings will not generate SQL injection. However, other exotic features like arrays/byte data/etc might be problematic.
|
17
|
+
|
18
|
+
Model.connection.execute("select " + Model.connection.quote("\\"))[0]
|
19
|
+
=> {"?column?"=>"\\"}
|
20
|
+
|
21
|
+
Model.connection.execute("select " + Model.connection.quote("\n"))[0]
|
22
|
+
=> {"?column?"=>"\n"}
|
23
|
+
|
24
|
+
Model.where("column" => "\\").limit(1)
|
25
|
+
|
26
|
+
Model.connection.execute("select " + Model.connection.quote("\\n"))[0]
|
27
|
+
=> {"?column?"=>"\\n"}
|
28
|
+
|
29
|
+
|
30
|
+
We also work around an 8.2 compatability problem in ActiveRecord 4.2 which has been fixed in the latest ActiveRecord:
|
31
|
+
|
32
|
+
https://github.com/rails/rails/commit/c6f8af367ec404642b8b5bd0994b8e083f60984b
|
33
|
+
|
34
|
+
Also be aware that we haven't run the specs in postgresql AR against this version nor do we have any specs. This is a YOLO redshift adapter.
|
35
|
+
|
36
|
+
The main advantage of this adapter over its competitors is that it is usually easy to follow AR security updates and fixes. Usually you just update the AR gem and everything works fine because there is almost no code that this Gem overrides/copies from AR.
|
37
|
+
|
38
|
+
## Installation
|
39
|
+
|
40
|
+
Add this line to your application's Gemfile:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
gem 'redshift_adapter'
|
44
|
+
```
|
45
|
+
|
46
|
+
And then execute:
|
47
|
+
|
48
|
+
$ bundle
|
49
|
+
|
50
|
+
Or install it yourself as:
|
51
|
+
|
52
|
+
$ gem install redshift_adapter
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
Add the following to database.yml
|
57
|
+
|
58
|
+
my_redshift_db:
|
59
|
+
adapter: redshift
|
60
|
+
host: name.unique.eu-west-1.redshift.amazonaws.co
|
61
|
+
database: dbname
|
62
|
+
port: 5439
|
63
|
+
username: username
|
64
|
+
password: password
|
65
|
+
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it ( https://github.com/[my-github-username]/redshift_adapter/fork )
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
2
|
+
require 'active_record/connection_adapters/postgresql/oid/type_map_initializer'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module ConnectionHandling
|
6
|
+
|
7
|
+
def redshift_connection(config)
|
8
|
+
conn_params = config.symbolize_keys
|
9
|
+
|
10
|
+
conn_params.delete_if { |_, v| v.nil? }
|
11
|
+
|
12
|
+
# Map ActiveRecords param names to PGs.
|
13
|
+
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
14
|
+
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
15
|
+
|
16
|
+
# Forward only valid config params to PGconn.connect.
|
17
|
+
conn_params.keep_if { |k, _| VALID_CONN_PARAMS.include?(k) }
|
18
|
+
|
19
|
+
# The postgres drivers don't allow the creation of an unconnected PGconn object,
|
20
|
+
# so just pass a nil connection object for the time being.
|
21
|
+
ConnectionAdapters::RedshiftAdapter.new(nil, logger, conn_params, config)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
module ConnectionAdapters
|
27
|
+
class RedshiftAdapter < PostgreSQLAdapter
|
28
|
+
def set_standard_conforming_strings
|
29
|
+
end
|
30
|
+
def client_min_messages=(level)
|
31
|
+
end
|
32
|
+
|
33
|
+
def postgresql_version
|
34
|
+
80200
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute(sql, name=nil)
|
38
|
+
if name == "SCHEMA" && sql.start_with?("SET time zone")
|
39
|
+
return
|
40
|
+
else
|
41
|
+
super
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
module ActiveRecord
|
49
|
+
module ConnectionAdapters
|
50
|
+
module PostgreSQL
|
51
|
+
module OID
|
52
|
+
class TypeMapInitializer
|
53
|
+
def query_conditions_for_initial_load(type_map)
|
54
|
+
known_type_names = type_map.keys.map { |n| "'#{n}'" }
|
55
|
+
known_type_types = %w('r' 'e' 'd')
|
56
|
+
<<-SQL % [known_type_names.join(", "), known_type_types.join(", ")]
|
57
|
+
WHERE
|
58
|
+
t.typname IN (%s)
|
59
|
+
OR t.typtype IN (%s)
|
60
|
+
OR t.typinput = 'array_in'::regproc
|
61
|
+
OR t.typelem != 0
|
62
|
+
SQL
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redshift_adapter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redshift_adapter"
|
8
|
+
spec.version = RedshiftAdapter::VERSION
|
9
|
+
spec.authors = ["Ben Murphy"]
|
10
|
+
spec.email = ["benm@fonix.com"]
|
11
|
+
spec.summary = %q{Amazon Redshift Adapter for Rails 4}
|
12
|
+
spec.description = %q{Amazon Redshift Adapter for Rails 4}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redshift_adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Murphy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Amazon Redshift Adapter for Rails 4
|
42
|
+
email:
|
43
|
+
- benm@fonix.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/active_record/connection_adapters/redshift_adapter.rb
|
54
|
+
- lib/redshift_adapter.rb
|
55
|
+
- lib/redshift_adapter/version.rb
|
56
|
+
- redshift_adapter.gemspec
|
57
|
+
homepage: ''
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.14
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Amazon Redshift Adapter for Rails 4
|
81
|
+
test_files: []
|