activerecord4-redshift-adapter 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34f882890a917a408523cf0d811fec93c61f662b
4
- data.tar.gz: b946f1a2a36571c0ddfb1e4fa8087396b590d5b4
3
+ metadata.gz: eea0356bef6917cb809017578ae67b75acfdfe6a
4
+ data.tar.gz: 8f0012056c332525da97265ec6e0f9b5fea2410f
5
5
  SHA512:
6
- metadata.gz: a11030528067cd95e0e19f046db194214642be0bfe93d42394d9160e4aa6627ea420e4ee1684273aaaa56e782e587bdb1a67df18a0d52011ac04763d27daa2f0
7
- data.tar.gz: 8638c106814e78f348adeccb9e0b896a53287da248993be0e546cd4c9a4e0da0f06769c6330dc6bfbfd641b41c9c3e565d0bb2e24b46233e4360e6c67c523b87
6
+ metadata.gz: 073586046aa238f83261868024f4d6378de00763d0ce2ac4225bb5b2725f3f499147f7045cc3910d3e249e07b098901e56764e73b9d5cf81a76474c14e5877ca
7
+ data.tar.gz: 270baf4730a43bd80134d08ce5f5582adc99d13d02f644d83de42b6727d8f9de2f3e3caeaf720686062a9e10b1042a4c49e2f43cdbfec31d667a5713a173ffc3
data/README.md CHANGED
@@ -15,9 +15,13 @@ I abandon this driver.
15
15
  Usage
16
16
  -------------------
17
17
 
18
- In Gemfile
18
+ For Rails 4.2, write following in Gemfile:
19
19
  ```
20
- gem 'activerecord4-redshift-adapter', github: 'aamine/activerecord4-redshift-adapter'
20
+ gem 'activerecord4-redshift-adapter', '~> 0.2.0'
21
+ ```
22
+ For Rails 4.1:
23
+ ```
24
+ gem 'activerecord4-redshift-adapter', '~> 0.1.1'
21
25
  ```
22
26
 
23
27
  In database.yml
@@ -52,12 +52,6 @@ module ActiveRecord
52
52
  column name, type, options
53
53
  end
54
54
 
55
- def new_column_definition(name, type, options) # :nodoc:
56
- column = super
57
- column.array = options[:array]
58
- column
59
- end
60
-
61
55
  private
62
56
 
63
57
  def create_column_definition(name, type)
@@ -14,10 +14,6 @@ module ActiveRecord
14
14
  end
15
15
 
16
16
  def add_column_options!(sql, options)
17
- if options[:array] || options[:column].try(:array)
18
- sql << '[]'
19
- end
20
-
21
17
  column = options.fetch(:column) { return super }
22
18
  if column.type == :uuid && options[:default] =~ /\(\)/
23
19
  sql << " DEFAULT #{options[:default]}"
@@ -58,18 +54,6 @@ module ActiveRecord
58
54
  memo += case key
59
55
  when :owner
60
56
  " OWNER = \"#{value}\""
61
- when :template
62
- " TEMPLATE = \"#{value}\""
63
- when :encoding
64
- " ENCODING = '#{value}'"
65
- when :collation
66
- " LC_COLLATE = '#{value}'"
67
- when :ctype
68
- " LC_CTYPE = '#{value}'"
69
- when :tablespace
70
- " TABLESPACE = \"#{value}\""
71
- when :connection_limit
72
- " CONNECTION LIMIT = #{value}"
73
57
  else
74
58
  ""
75
59
  end
@@ -83,7 +67,7 @@ module ActiveRecord
83
67
  # Example:
84
68
  # drop_database 'matt_development'
85
69
  def drop_database(name) #:nodoc:
86
- execute "DROP DATABASE IF EXISTS #{quote_table_name(name)}"
70
+ execute "DROP DATABASE #{quote_table_name(name)}"
87
71
  end
88
72
 
89
73
  # Returns the list of all tables in the schema search path or a specified schema.
@@ -167,18 +151,10 @@ module ActiveRecord
167
151
  end_sql
168
152
  end
169
153
 
170
- # Returns the current database collation.
171
154
  def collation
172
- query(<<-end_sql, 'SCHEMA')[0][0]
173
- SELECT pg_database.datcollate FROM pg_database WHERE pg_database.datname LIKE '#{current_database}'
174
- end_sql
175
155
  end
176
156
 
177
- # Returns the current database ctype.
178
157
  def ctype
179
- query(<<-end_sql, 'SCHEMA')[0][0]
180
- SELECT pg_database.datctype FROM pg_database WHERE pg_database.datname LIKE '#{current_database}'
181
- end_sql
182
158
  end
183
159
 
184
160
  # Returns an array of schema names.
@@ -235,97 +211,14 @@ module ActiveRecord
235
211
  result.rows.first.first
236
212
  end
237
213
 
238
- # Sets the sequence of a table's primary key to the specified value.
239
214
  def set_pk_sequence!(table, value) #:nodoc:
240
- pk, sequence = pk_and_sequence_for(table)
241
-
242
- if pk
243
- if sequence
244
- quoted_sequence = quote_table_name(sequence)
245
-
246
- select_value <<-end_sql, 'SCHEMA'
247
- SELECT setval('#{quoted_sequence}', #{value})
248
- end_sql
249
- else
250
- @logger.warn "#{table} has primary key #{pk} with no default sequence" if @logger
251
- end
252
- end
253
215
  end
254
216
 
255
- # Resets the sequence of a table's primary key to the maximum value.
256
217
  def reset_pk_sequence!(table, pk = nil, sequence = nil) #:nodoc:
257
- unless pk and sequence
258
- default_pk, default_sequence = pk_and_sequence_for(table)
259
-
260
- pk ||= default_pk
261
- sequence ||= default_sequence
262
- end
263
-
264
- if @logger && pk && !sequence
265
- @logger.warn "#{table} has primary key #{pk} with no default sequence"
266
- end
267
-
268
- if pk && sequence
269
- quoted_sequence = quote_table_name(sequence)
270
-
271
- select_value <<-end_sql, 'SCHEMA'
272
- SELECT setval('#{quoted_sequence}', (SELECT COALESCE(MAX(#{quote_column_name pk})+(SELECT increment_by FROM #{quoted_sequence}), (SELECT min_value FROM #{quoted_sequence})) FROM #{quote_table_name(table)}), false)
273
- end_sql
274
- end
275
218
  end
276
219
 
277
- # Returns a table's primary key and belonging sequence.
278
220
  def pk_and_sequence_for(table) #:nodoc:
279
- # First try looking for a sequence with a dependency on the
280
- # given table's primary key.
281
- result = query(<<-end_sql, 'SCHEMA')[0]
282
- SELECT attr.attname, nsp.nspname, seq.relname
283
- FROM pg_class seq,
284
- pg_attribute attr,
285
- pg_depend dep,
286
- pg_constraint cons,
287
- pg_namespace nsp
288
- WHERE seq.oid = dep.objid
289
- AND seq.relkind = 'S'
290
- AND attr.attrelid = dep.refobjid
291
- AND attr.attnum = dep.refobjsubid
292
- AND attr.attrelid = cons.conrelid
293
- AND attr.attnum = cons.conkey[1]
294
- AND seq.relnamespace = nsp.oid
295
- AND cons.contype = 'p'
296
- AND dep.classid = 'pg_class'::regclass
297
- AND dep.refobjid = '#{quote_table_name(table)}'::regclass
298
- end_sql
299
-
300
- if result.nil? or result.empty?
301
- result = query(<<-end_sql, 'SCHEMA')[0]
302
- SELECT attr.attname, nsp.nspname,
303
- CASE
304
- WHEN pg_get_expr(def.adbin, def.adrelid) !~* 'nextval' THEN NULL
305
- WHEN split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2) ~ '.' THEN
306
- substr(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2),
307
- strpos(split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2), '.')+1)
308
- ELSE split_part(pg_get_expr(def.adbin, def.adrelid), '''', 2)
309
- END
310
- FROM pg_class t
311
- JOIN pg_attribute attr ON (t.oid = attrelid)
312
- JOIN pg_attrdef def ON (adrelid = attrelid AND adnum = attnum)
313
- JOIN pg_constraint cons ON (conrelid = adrelid AND adnum = conkey[1])
314
- JOIN pg_namespace nsp ON (t.relnamespace = nsp.oid)
315
- WHERE t.oid = '#{quote_table_name(table)}'::regclass
316
- AND cons.contype = 'p'
317
- AND pg_get_expr(def.adbin, def.adrelid) ~* 'nextval|uuid_generate'
318
- end_sql
319
- end
320
-
321
- pk = result.shift
322
- if result.last
323
- [pk, PostgreSQL::Name.new(*result)]
324
- else
325
- [pk, nil]
326
- end
327
- rescue
328
- nil
221
+ [nil, nil]
329
222
  end
330
223
 
331
224
  # Returns just a table's primary key
@@ -418,7 +311,7 @@ module ActiveRecord
418
311
 
419
312
  def foreign_keys(table_name)
420
313
  fk_info = select_all <<-SQL.strip_heredoc
421
- SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
314
+ SELECT t2.relname AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
422
315
  FROM pg_constraint c
423
316
  JOIN pg_class t1 ON c.conrelid = t1.oid
424
317
  JOIN pg_class t2 ON c.confrelid = t2.oid
@@ -76,9 +76,9 @@ module ActiveRecord
76
76
  ADAPTER_NAME = 'Redshift'.freeze
77
77
 
78
78
  NATIVE_DATABASE_TYPES = {
79
- primary_key: "integer primary key",
80
- string: { name: "character varying" },
81
- text: { name: "text" },
79
+ primary_key: "integer identity primary key",
80
+ string: { name: "varchar" },
81
+ text: { name: "varchar" },
82
82
  integer: { name: "integer" },
83
83
  float: { name: "float" },
84
84
  decimal: { name: "decimal" },
@@ -86,8 +86,7 @@ module ActiveRecord
86
86
  time: { name: "time" },
87
87
  date: { name: "date" },
88
88
  bigint: { name: "bigint" },
89
- json: { name: "json" },
90
- jsonb: { name: "jsonb" }
89
+ boolean: { name: "boolean" },
91
90
  }
92
91
 
93
92
  OID = Redshift::OID #:nodoc:
@@ -105,16 +104,10 @@ module ActiveRecord
105
104
  # AbstractAdapter
106
105
  def prepare_column_options(column, types) # :nodoc:
107
106
  spec = super
108
- spec[:array] = 'true' if column.respond_to?(:array) && column.array
109
107
  spec[:default] = "\"#{column.default_function}\"" if column.default_function
110
108
  spec
111
109
  end
112
110
 
113
- # Adds +:array+ as a valid migration key
114
- def migration_keys
115
- super + [:array]
116
- end
117
-
118
111
  # Returns +true+, since this connection adapter supports prepared statement
119
112
  # caching.
120
113
  def supports_statement_cache?
@@ -403,16 +396,11 @@ module ActiveRecord
403
396
  m.alias_type 'char', 'varchar'
404
397
  m.alias_type 'name', 'varchar'
405
398
  m.alias_type 'bpchar', 'varchar'
399
+ m.register_type 'bool', Type::Boolean.new
406
400
  m.alias_type 'timestamptz', 'timestamp'
407
401
  m.register_type 'date', OID::Date.new
408
402
  m.register_type 'time', OID::Time.new
409
403
 
410
- m.register_type 'json', OID::Json.new
411
- m.register_type 'jsonb', OID::Jsonb.new
412
-
413
- # FIXME: why are we keeping these types as strings?
414
- m.alias_type 'interval', 'varchar'
415
-
416
404
  m.register_type 'timestamp' do |_, _, sql_type|
417
405
  precision = extract_precision(sql_type)
418
406
  OID::DateTime.new(precision: precision)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord4-redshift-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Minero Aoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-12 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  requirements: []
88
88
  rubyforge_project:
89
- rubygems_version: 2.4.5
89
+ rubygems_version: 2.4.5.1
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Amazon Redshift adapter for ActiveRecord 4