activerecord-redshift-adapter 0.9.12 → 8.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/LICENSE +25 -1
- data/README.md +28 -86
- data/lib/active_record/connection_adapters/redshift_7_0/array_parser.rb +92 -0
- data/lib/active_record/connection_adapters/redshift_7_0/column.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_0/database_statements.rb +232 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid/decimal.rb +15 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid/json.rb +41 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid/jsonb.rb +25 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid/type_map_initializer.rb +62 -0
- data/lib/active_record/connection_adapters/redshift_7_0/oid.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_0/quoting.rb +99 -0
- data/lib/active_record/connection_adapters/redshift_7_0/referential_integrity.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_0/schema_definitions.rb +70 -0
- data/lib/active_record/connection_adapters/redshift_7_0/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_0/schema_statements.rb +421 -0
- data/lib/active_record/connection_adapters/redshift_7_0/type_metadata.rb +39 -0
- data/lib/active_record/connection_adapters/redshift_7_0/utils.rb +81 -0
- data/lib/active_record/connection_adapters/redshift_7_0_adapter.rb +768 -0
- data/lib/active_record/connection_adapters/redshift_7_1/array_parser.rb +92 -0
- data/lib/active_record/connection_adapters/redshift_7_1/column.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_1/database_statements.rb +180 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid/decimal.rb +15 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid/json.rb +41 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid/jsonb.rb +25 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid/type_map_initializer.rb +62 -0
- data/lib/active_record/connection_adapters/redshift_7_1/oid.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_1/quoting.rb +161 -0
- data/lib/active_record/connection_adapters/redshift_7_1/referential_integrity.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_1/schema_definitions.rb +70 -0
- data/lib/active_record/connection_adapters/redshift_7_1/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_1/schema_statements.rb +422 -0
- data/lib/active_record/connection_adapters/redshift_7_1/type_metadata.rb +43 -0
- data/lib/active_record/connection_adapters/redshift_7_1/utils.rb +81 -0
- data/lib/active_record/connection_adapters/redshift_7_1_adapter.rb +847 -0
- data/lib/active_record/connection_adapters/redshift_7_2/array_parser.rb +92 -0
- data/lib/active_record/connection_adapters/redshift_7_2/column.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_2/database_statements.rb +180 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid/decimal.rb +15 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid/json.rb +41 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid/jsonb.rb +25 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid/type_map_initializer.rb +62 -0
- data/lib/active_record/connection_adapters/redshift_7_2/oid.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_2/quoting.rb +164 -0
- data/lib/active_record/connection_adapters/redshift_7_2/referential_integrity.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_2/schema_definitions.rb +70 -0
- data/lib/active_record/connection_adapters/redshift_7_2/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_7_2/schema_statements.rb +422 -0
- data/lib/active_record/connection_adapters/redshift_7_2/type_metadata.rb +43 -0
- data/lib/active_record/connection_adapters/redshift_7_2/utils.rb +81 -0
- data/lib/active_record/connection_adapters/redshift_7_2_adapter.rb +847 -0
- data/lib/active_record/connection_adapters/redshift_8_0/array_parser.rb +92 -0
- data/lib/active_record/connection_adapters/redshift_8_0/column.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_8_0/database_statements.rb +181 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid/date_time.rb +36 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid/decimal.rb +15 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid/json.rb +41 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid/jsonb.rb +25 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid/type_map_initializer.rb +62 -0
- data/lib/active_record/connection_adapters/redshift_8_0/oid.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_8_0/quoting.rb +164 -0
- data/lib/active_record/connection_adapters/redshift_8_0/referential_integrity.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_8_0/schema_definitions.rb +70 -0
- data/lib/active_record/connection_adapters/redshift_8_0/schema_dumper.rb +17 -0
- data/lib/active_record/connection_adapters/redshift_8_0/schema_statements.rb +422 -0
- data/lib/active_record/connection_adapters/redshift_8_0/type_metadata.rb +43 -0
- data/lib/active_record/connection_adapters/redshift_8_0/utils.rb +81 -0
- data/lib/active_record/connection_adapters/redshift_8_0_adapter.rb +846 -0
- data/lib/active_record/connection_adapters/redshift_adapter.rb +13 -1286
- data/lib/active_record/tasks/redshift_7_0_tasks.rb +148 -0
- data/lib/active_record/tasks/redshift_7_1_tasks.rb +151 -0
- data/lib/active_record/tasks/redshift_7_2_tasks.rb +151 -0
- data/lib/active_record/tasks/redshift_8_0_tasks.rb +151 -0
- data/lib/active_record/tasks/redshift_tasks.rb +13 -0
- data/lib/activerecord-redshift-adapter.rb +13 -0
- metadata +110 -84
- data/.gitignore +0 -26
- data/Gemfile +0 -14
- data/Rakefile +0 -26
- data/activerecord-redshift-adapter.gemspec +0 -24
- data/lib/activerecord_redshift/table_manager.rb +0 -230
- data/lib/activerecord_redshift_adapter/version.rb +0 -4
- data/lib/activerecord_redshift_adapter.rb +0 -4
- data/lib/monkeypatch_activerecord.rb +0 -195
- data/lib/monkeypatch_arel.rb +0 -96
- data/spec/active_record/base_spec.rb +0 -37
- data/spec/active_record/connection_adapters/redshift_adapter_spec.rb +0 -97
- data/spec/dummy/config/database.example.yml +0 -12
- data/spec/spec_helper.rb +0 -33
@@ -1,195 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Querying
|
3
|
-
delegate :unload, :copy, :to => :scoped
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
module ActiveRecord::QueryMethods
|
8
|
-
module CopyUnloadParser
|
9
|
-
def self.parse_options(options, options_hash, valid_switches, valid_options, valid_unquoted_options, valid_special_options)
|
10
|
-
# credentials first
|
11
|
-
credentials = nil
|
12
|
-
if options_hash.has_key?(:credentials)
|
13
|
-
credentials = options_hash[:credentials]
|
14
|
-
else
|
15
|
-
creds = {}
|
16
|
-
creds[:aws_access_key_id] = options_hash[:aws_access_key_id] if options_hash.has_key?(:aws_access_key_id)
|
17
|
-
creds[:aws_secret_access_key] = options_hash[:aws_secret_access_key] if options_hash.has_key?(:aws_secret_access_key)
|
18
|
-
creds[:token] = options_hash[:token] if options_hash.has_key?(:token)
|
19
|
-
creds[:master_symmetric_key] = options_hash[:master_symmetric_key] if options_hash.has_key?(:master_symmetric_key)
|
20
|
-
credentials = creds.map{|k,v| "#{k}=#{v}"}.join(';')
|
21
|
-
end
|
22
|
-
|
23
|
-
option_list = []
|
24
|
-
option_list << "WITH CREDENTIALS AS #{connection.quote_value(credentials)}" unless credentials.blank?
|
25
|
-
|
26
|
-
valid_switches.each do |switch_name|
|
27
|
-
if options.include? switch_name
|
28
|
-
option_list << switch_name.to_s.upcase
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
valid_options.each do |option_name|
|
33
|
-
if options_hash.has_key? option_name
|
34
|
-
option_list << "#{option_name.to_s.upcase} AS #{connection.quote_value(options_hash[option_name])}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
valid_unquoted_options.each do |option_name|
|
39
|
-
if options_hash.has_key? option_name
|
40
|
-
option_list << "#{option_name.to_s.upcase} #{options_hash[option_name]}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
return credentials, option_list
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
module ActiveRecord
|
50
|
-
module QueryMethods
|
51
|
-
# UNLOAD ('select_statement')
|
52
|
-
# TO 's3_path'
|
53
|
-
# [ WITH ] CREDENTIALS [AS] 'aws_access_credentials'
|
54
|
-
# [ option [ ... ] ]
|
55
|
-
#
|
56
|
-
# where option is
|
57
|
-
#
|
58
|
-
# { DELIMITER [ AS ] 'delimiter_char'
|
59
|
-
# | FIXEDWIDTH [ AS ] 'fixedwidth_spec' }
|
60
|
-
# | ENCRYPTED
|
61
|
-
# | GZIP
|
62
|
-
# | ADDQUOTES
|
63
|
-
# | NULL [ AS ] 'null_string'
|
64
|
-
# | ESCAPE
|
65
|
-
# | ALLOWOVERWRITE
|
66
|
-
VALID_UNLOAD_SWITCHES = [
|
67
|
-
:gzip,
|
68
|
-
:addquotes,
|
69
|
-
:escape,
|
70
|
-
:allowoverwrite
|
71
|
-
]
|
72
|
-
VALID_UNLOAD_OPTIONS = [
|
73
|
-
:delimiter,
|
74
|
-
:fixedwidth,
|
75
|
-
:null
|
76
|
-
]
|
77
|
-
VALID_UNQUOTED_UNLOAD_OPTIONS = [ ]
|
78
|
-
VALID_SPECIAL_UNLOAD_OPTIONS = [
|
79
|
-
:credentials,
|
80
|
-
:aws_access_key_id,
|
81
|
-
:aws_secret_access_key,
|
82
|
-
:master_symmetric_key,
|
83
|
-
:token
|
84
|
-
]
|
85
|
-
|
86
|
-
def unload(to_s3_filename, *options)
|
87
|
-
if options.last.is_a? Hash
|
88
|
-
options_hash = options.last
|
89
|
-
else
|
90
|
-
options_hash = {}
|
91
|
-
end
|
92
|
-
|
93
|
-
credentials, unload_options =
|
94
|
-
ActiveRecord::QueryMethods::CopyUnloadParser.parse_options(options, options_hash,
|
95
|
-
VALID_UNLOAD_SWITCHES, VALID_UNLOAD_OPTIONS, VALID_UNQUOTED_UNLOAD_OPTIONS, VALID_SPECIAL_UNLOAD_OPTIONS)
|
96
|
-
|
97
|
-
|
98
|
-
relation = Arel::Nodes::UnloadStatement.new(Arel::Nodes::Unload.new(Arel::Nodes::Relation.new(clone), to_s3_filename), unload_options.join(" "))
|
99
|
-
relation
|
100
|
-
end
|
101
|
-
|
102
|
-
VALID_COPY_SWITCHES = [
|
103
|
-
:encrypted,
|
104
|
-
:gzip,
|
105
|
-
:removequotes,
|
106
|
-
:explicit_ids,
|
107
|
-
:escape,
|
108
|
-
:acceptanydate,
|
109
|
-
:ignoreblanklines,
|
110
|
-
:truncatecolumns,
|
111
|
-
:fillrecord,
|
112
|
-
:trimblanks,
|
113
|
-
:noload,
|
114
|
-
:emptyasnull,
|
115
|
-
:blanksasnull,
|
116
|
-
:escape,
|
117
|
-
:roundec
|
118
|
-
]
|
119
|
-
VALID_COPY_OPTIONS = [
|
120
|
-
:delimiter,
|
121
|
-
:fixedwidth,
|
122
|
-
:csv,
|
123
|
-
:acceptinvchars,
|
124
|
-
:dateformat,
|
125
|
-
:timeformat,
|
126
|
-
:null
|
127
|
-
]
|
128
|
-
|
129
|
-
VALID_UNQUOTED_COPY_OPTIONS = [
|
130
|
-
:maxerror,
|
131
|
-
:ignoreheader,
|
132
|
-
:comprows,
|
133
|
-
:compupdate,
|
134
|
-
:statupdate
|
135
|
-
]
|
136
|
-
|
137
|
-
VALID_SPECIAL_COPY_OPTIONS = [
|
138
|
-
:credentials,
|
139
|
-
:aws_access_key_id,
|
140
|
-
:aws_secret_access_key,
|
141
|
-
:master_symmetric_key,
|
142
|
-
:token
|
143
|
-
]
|
144
|
-
|
145
|
-
# COPY table_name [ (column1 [,column2, ...]) ]
|
146
|
-
# FROM 's3://objectpath'
|
147
|
-
# [ WITH ] CREDENTIALS [AS] 'aws_access_credentials'
|
148
|
-
# [ option [ ... ] ]
|
149
|
-
|
150
|
-
# where option is
|
151
|
-
|
152
|
-
# { FIXEDWIDTH 'fixedwidth_spec'
|
153
|
-
# | [DELIMITER [ AS ] 'delimiter_char']
|
154
|
-
# [CSV [QUOTE [ AS ] 'quote_character']}
|
155
|
-
|
156
|
-
# | ENCRYPTED
|
157
|
-
# | GZIP
|
158
|
-
# | REMOVEQUOTES
|
159
|
-
# | EXPLICIT_IDS
|
160
|
-
|
161
|
-
# | ACCEPTINVCHARS [ AS ] ['replacement_char']
|
162
|
-
# | MAXERROR [ AS ] error_count
|
163
|
-
# | DATEFORMAT [ AS ] { 'dateformat_string' | 'auto' }
|
164
|
-
# | TIMEFORMAT [ AS ] { 'timeformat_string' | 'auto' | 'epochsecs' | 'epochmillisecs' }
|
165
|
-
# | IGNOREHEADER [ AS ] number_rows
|
166
|
-
# | ACCEPTANYDATE
|
167
|
-
# | IGNOREBLANKLINES
|
168
|
-
# | TRUNCATECOLUMNS
|
169
|
-
# | FILLRECORD
|
170
|
-
# | TRIMBLANKS
|
171
|
-
# | NOLOAD
|
172
|
-
# | NULL [ AS ] 'null_string'
|
173
|
-
# | EMPTYASNULL
|
174
|
-
# | BLANKSASNULL
|
175
|
-
# | COMPROWS numrows
|
176
|
-
# | COMPUPDATE [ { ON | TRUE } | { OFF | FALSE } ]
|
177
|
-
# | STATUPDATE [ { ON | TRUE } | { OFF | FALSE } ]
|
178
|
-
# | ESCAPE
|
179
|
-
# | ROUNDEC
|
180
|
-
def copy(to_s3_filename, *options)
|
181
|
-
if options.last.is_a? Hash
|
182
|
-
options_hash = options.last
|
183
|
-
else
|
184
|
-
options_hash = {}
|
185
|
-
end
|
186
|
-
|
187
|
-
credentials, copy_options =
|
188
|
-
::ActiveRecord::QueryMethods::CopyUnloadParser.parse_options(options, options_hash,
|
189
|
-
VALID_COPY_SWITCHES, VALID_COPY_OPTIONS, VALID_UNQUOTED_COPY_OPTIONS, VALID_SPECIAL_COPY_OPTIONS)
|
190
|
-
|
191
|
-
|
192
|
-
conncection.execute(Arel::Nodes::CopyStatement.new(Arel::Nodes::Copy.new(table_name, to_s3_filename), copy_options.join(" ")).to_sql)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
data/lib/monkeypatch_arel.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
module Arel
|
2
|
-
module Nodes
|
3
|
-
class Relation < Arel::Nodes::Unary
|
4
|
-
end
|
5
|
-
|
6
|
-
class Unload < Arel::Nodes::Binary
|
7
|
-
alias :statement :left
|
8
|
-
alias :statement= :left=
|
9
|
-
alias :to :right
|
10
|
-
alias :to= :right=
|
11
|
-
def initialize statement = nil, to = nil
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize_copy other
|
16
|
-
super
|
17
|
-
@right = @right.clone
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class UnloadStatement < Arel::Nodes::Binary
|
22
|
-
alias :relation :left
|
23
|
-
alias :relation= :left=
|
24
|
-
alias :options :right
|
25
|
-
alias :options= :right=
|
26
|
-
|
27
|
-
def initialize relation = nil, options = []
|
28
|
-
super
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize_copy other
|
32
|
-
super
|
33
|
-
@right = @right.clone
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Copy < Arel::Nodes::Binary
|
38
|
-
alias :statement :left
|
39
|
-
alias :statement= :left=
|
40
|
-
alias :from :right
|
41
|
-
alias :from= :right=
|
42
|
-
def initialize statement = nil, from = nil
|
43
|
-
super
|
44
|
-
end
|
45
|
-
|
46
|
-
def initialize_copy other
|
47
|
-
super
|
48
|
-
@right = @right.clone
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class CopyStatement < Arel::Nodes::Binary
|
53
|
-
alias :relation :left
|
54
|
-
alias :relation= :left=
|
55
|
-
alias :options :right
|
56
|
-
alias :options= :right=
|
57
|
-
|
58
|
-
def initialize relation = nil, options = []
|
59
|
-
super
|
60
|
-
end
|
61
|
-
|
62
|
-
def initialize_copy other
|
63
|
-
super
|
64
|
-
@right = @right.clone
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module Arel
|
72
|
-
module Visitors
|
73
|
-
class ToSql < Arel::Visitors::Visitor
|
74
|
-
|
75
|
-
def visit_Arel_Nodes_UnloadStatement o
|
76
|
-
"#{visit o.relation} #{o.options}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def visit_Arel_Nodes_Unload o
|
80
|
-
"UNLOAD (#{visit o.statement}) TO #{visit o.to}"
|
81
|
-
end
|
82
|
-
|
83
|
-
def visit_Arel_Nodes_CopyStatement o
|
84
|
-
"#{visit o.relation} #{o.options}"
|
85
|
-
end
|
86
|
-
|
87
|
-
def visit_Arel_Nodes_Copy o
|
88
|
-
"COPY #{o.statement} FROM #{visit o.from}"
|
89
|
-
end
|
90
|
-
|
91
|
-
def visit_Arel_Nodes_Relation o
|
92
|
-
visit o.expr.to_sql
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,37 +0,0 @@
|
|
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
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe ActiveRecord::ConnectionAdapters::RedshiftAdapter 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
|
@@ -1,12 +0,0 @@
|
|
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
DELETED
@@ -1,33 +0,0 @@
|
|
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
|