redshift-on-postgres-adapter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cd1d7a7f84eece7766d393beb1138b6ed4914259
|
4
|
+
data.tar.gz: 3ae0f380bdea551702fdfcba699edcb329899005
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 167807e7b94a641e1063c8c1f947ba73fdfb9a85a76595421ed33f76922f56c0a0c56fa2f00c24b7affd23a259953e713a1b02c2b1efeedb724c355e3282e068
|
7
|
+
data.tar.gz: 75c609284a9874b091ca249788533536a578e91785ca1b29365259f8d5e0303d7d1b8be21564e2b1da293c4bf60ddc72f40b81cdfd184eef569db3f3e3ec6fdf
|
@@ -0,0 +1,166 @@
|
|
1
|
+
|
2
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
3
|
+
|
4
|
+
require 'active_record/tasks/redshift_database_tasks'
|
5
|
+
|
6
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(/redshift/, ActiveRecord::Tasks::RedshiftDatabaseTasks)
|
7
|
+
|
8
|
+
module ActiveRecord::ConnectionHandling
|
9
|
+
def redshift_connection(config)
|
10
|
+
conn_params = config.symbolize_keys
|
11
|
+
conn_params.delete_if { |_, v| v.nil? }
|
12
|
+
|
13
|
+
# Map ActiveRecords param names to PGs.
|
14
|
+
conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
|
15
|
+
conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
|
16
|
+
|
17
|
+
# Forward only valid config params to PGconn.connect.
|
18
|
+
valid_conn_param_keys = PGconn.conndefaults_hash.keys + [:requiressl]
|
19
|
+
conn_params.slice!(*valid_conn_param_keys)
|
20
|
+
|
21
|
+
# The postgres drivers don't allow the creation of an unconnected PGconn object,
|
22
|
+
# so just pass a nil connection object for the time being.
|
23
|
+
ActiveRecord::ConnectionAdapters::RedshiftAdapter.new(nil, logger, conn_params, config)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ActiveRecord::ConnectionAdapters::RedshiftAdapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
28
|
+
ADAPTER_NAME = 'Redshift'.freeze
|
29
|
+
|
30
|
+
def initialize(connection, logger, connection_parameters, config)
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
# Configures the encoding, verbosity, schema search path, and time zone of the connection.
|
35
|
+
# This is called by #connect and should not be called manually.
|
36
|
+
def configure_connection
|
37
|
+
if @config[:encoding]
|
38
|
+
@connection.set_client_encoding(@config[:encoding])
|
39
|
+
end
|
40
|
+
# self.client_min_messages = @config[:min_messages] || 'warning'
|
41
|
+
self.schema_search_path = @config[:schema_search_path] || @config[:schema_order]
|
42
|
+
|
43
|
+
# Use standard-conforming strings so we don't have to do the E'...' dance.
|
44
|
+
# set_standard_conforming_strings
|
45
|
+
|
46
|
+
# If using Active Record's time zone support configure the connection to return
|
47
|
+
# TIMESTAMP WITH ZONE types in UTC.
|
48
|
+
# (SET TIME ZONE does not use an equals sign like other SET variables)
|
49
|
+
# if ActiveRecord::Base.default_timezone == :utc
|
50
|
+
# execute("SET time zone 'UTC'", 'SCHEMA')
|
51
|
+
# elsif @local_tz
|
52
|
+
# execute("SET time zone '#{@local_tz}'", 'SCHEMA')
|
53
|
+
# end
|
54
|
+
|
55
|
+
# SET statements from :variables config hash
|
56
|
+
# http://www.postgresql.org/docs/8.3/static/sql-set.html
|
57
|
+
variables = @config[:variables] || {}
|
58
|
+
variables.map do |k, v|
|
59
|
+
if v == ':default' || v == :default
|
60
|
+
# Sets the value to the global or compile default
|
61
|
+
execute("SET SESSION #{k} TO DEFAULT", 'SCHEMA')
|
62
|
+
elsif !v.nil?
|
63
|
+
execute("SET SESSION #{k} TO #{quote(v)}", 'SCHEMA')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def postgresql_version
|
69
|
+
return 100000 + 80002
|
70
|
+
end
|
71
|
+
|
72
|
+
def supports_statement_cache?
|
73
|
+
false
|
74
|
+
end
|
75
|
+
|
76
|
+
def supports_index_sort_order?
|
77
|
+
false
|
78
|
+
end
|
79
|
+
|
80
|
+
def supports_partial_index?
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def supports_transaction_isolation?
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def supports_foreign_keys?
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
def supports_views?
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
def supports_extensions?
|
97
|
+
false
|
98
|
+
end
|
99
|
+
|
100
|
+
def supports_ranges?
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
def supports_materialized_views?
|
105
|
+
false
|
106
|
+
end
|
107
|
+
|
108
|
+
def use_insert_returning?
|
109
|
+
false
|
110
|
+
end
|
111
|
+
|
112
|
+
# Returns the list of a table's column names, data types, and default values.
|
113
|
+
#
|
114
|
+
# The underlying query is roughly:
|
115
|
+
# SELECT column.name, column.type, default.value
|
116
|
+
# FROM column LEFT JOIN default
|
117
|
+
# ON column.table_id = default.table_id
|
118
|
+
# AND column.num = default.column_num
|
119
|
+
# WHERE column.table_id = get_table_id('table_name')
|
120
|
+
# AND column.num > 0
|
121
|
+
# AND NOT column.is_dropped
|
122
|
+
# ORDER BY column.num
|
123
|
+
#
|
124
|
+
# If the table name is not prefixed with a schema, the database will
|
125
|
+
# take the first match from the schema search path.
|
126
|
+
#
|
127
|
+
# Query implementation notes:
|
128
|
+
# - format_type includes the column size constraint, e.g. varchar(50)
|
129
|
+
# - ::regclass is a function that gives the id for a table name
|
130
|
+
def column_definitions(table_name) #:nodoc:
|
131
|
+
exec_query(<<-end_sql, 'SCHEMA').rows
|
132
|
+
SELECT a.attname, format_type(a.atttypid, a.atttypmod),
|
133
|
+
pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
|
134
|
+
FROM pg_attribute a LEFT JOIN pg_attrdef d
|
135
|
+
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
|
136
|
+
WHERE a.attrelid = '#{quote_table_name(table_name)}'::regclass
|
137
|
+
AND a.attnum > 0 AND NOT a.attisdropped
|
138
|
+
ORDER BY a.attnum
|
139
|
+
end_sql
|
140
|
+
end
|
141
|
+
|
142
|
+
# Returns just a table's primary key
|
143
|
+
def primary_keys(table)
|
144
|
+
row = exec_query(<<-end_sql, 'SCHEMA').rows.map do |row|
|
145
|
+
SELECT DISTINCT(attr.attname)
|
146
|
+
FROM pg_attribute attr
|
147
|
+
INNER JOIN pg_depend dep ON attr.attrelid = dep.refobjid AND attr.attnum = dep.refobjsubid
|
148
|
+
INNER JOIN pg_constraint cons ON attr.attrelid = cons.conrelid AND attr.attnum = cons.conkey[1]
|
149
|
+
WHERE cons.contype = 'p'
|
150
|
+
AND dep.refobjid = '#{quote_table_name(table)}'::regclass
|
151
|
+
end_sql
|
152
|
+
row && row.first
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def indexes(table_name, name = nil)
|
157
|
+
[]
|
158
|
+
end
|
159
|
+
|
160
|
+
def get_advisory_lock(lock_id)
|
161
|
+
lock_id
|
162
|
+
end
|
163
|
+
|
164
|
+
def release_advisory_lock(lock_id)
|
165
|
+
end
|
166
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redshift-on-postgres-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dongyi Liao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pg
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This gem provides ActiveRecord adapter for RedShift by overloading the
|
42
|
+
postgresql adapter.
|
43
|
+
email: liaody@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/active_record/connection_adapters/redshift_adapter.rb
|
49
|
+
- lib/active_record/tasks/redshift_database_tasks.rb
|
50
|
+
homepage: http://github.com/liaody
|
51
|
+
licenses:
|
52
|
+
- New BSD License
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.5.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Rails 5 RedShift adapter based on current postgresql adapter.
|
74
|
+
test_files: []
|