activerecord-spanner-adapter 1.4.2 → 1.4.4

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
  SHA256:
3
- metadata.gz: cfd752e3287084b088f8d8e7ba09d2644ec8bb3c5f699b80425ed7babc74ac1f
4
- data.tar.gz: 2c72dad4930f696935f5a8ebe61db261da7ac11d3f8149b22f7bbe0bae900755
3
+ metadata.gz: f1a935693a8621d55fd7f51a17ba93dcc598f97789e6b7825ca7c916fbc0c9e1
4
+ data.tar.gz: 671717a9df5b2d7b6bbf388faea2c9ec6f982906a6456271a8696c2980d62684
5
5
  SHA512:
6
- metadata.gz: 77e3afc2326448c8e7de3e838baf09d87beb631c28129c2588e14ae675cd20ea0bf4c18e89d2e1ec456fb519530dd9d968838fcfc2cab32d5dc66dd5fb586025
7
- data.tar.gz: e4525d57eab407c0122a26ec412533e29e3ef51e942577a0686e36d22ddaf1a0243d30cc46ee350386b4ba292c9dc4a81dd7215e0beba5fc0eb08577f89a5ed1
6
+ metadata.gz: 5fa701ba551c2072ad60e6a7aadde8a4c4e20e3262d091c4854fd37d3663cfa353595017a8de229404c37dc7145ef5852c4ac16f531655c54462e419b217d86b
7
+ data.tar.gz: 24733bae08d92cd3ad8c7ae4cbbdbf016dc845f3f8b1a962bdde535b8df2627c9dc8a62d4d41cad3ec58a295c22de9ccb01924f95c985d1bf6741d647a0fcf4d
@@ -20,7 +20,7 @@ jobs:
20
20
  matrix:
21
21
  # Run acceptance tests all supported combinations of Ruby and ActiveRecord.
22
22
  ruby: [2.6, 2.7, 3.0, 3.1, 3.2]
23
- ar: [6.0.0, 6.0.1, 6.0.2.2, 6.0.3.7, 6.0.4, 6.1.3.2, 6.1.4.7, 6.1.5.1, 6.1.6.1, 7.0.2.4, 7.0.3.1, 7.0.4, 7.0.5]
23
+ ar: [6.0.0, 6.0.1, 6.0.2.2, 6.0.3.7, 6.0.4, 6.1.3.2, 6.1.4.7, 6.1.5.1, 6.1.6.1, 7.0.2.4, 7.0.3.1, 7.0.4, 7.0.5, 7.0.6, 7.0.7]
24
24
  # Exclude combinations that are not supported.
25
25
  exclude:
26
26
  - ruby: 3.0
@@ -61,6 +61,10 @@ jobs:
61
61
  ar: 7.0.4
62
62
  - ruby: 2.6
63
63
  ar: 7.0.5
64
+ - ruby: 2.6
65
+ ar: 7.0.6
66
+ - ruby: 2.6
67
+ ar: 7.0.7
64
68
  env:
65
69
  AR_VERSION: ${{ matrix.ar }}
66
70
  steps:
@@ -29,7 +29,7 @@ jobs:
29
29
  - name: Install dependencies
30
30
  run: bundle install
31
31
  - name: Run acceptance tests on production
32
- run: bundle exec rake acceptance
32
+ run: bundle exec rake acceptance\[,,,"exclude cases/migration"\]
33
33
  env:
34
34
  SPANNER_TEST_PROJECT: ${{ secrets.GCP_PROJECT_ID }}
35
35
  SPANNER_TEST_INSTANCE: ruby-activerecord-test
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.4.2"
2
+ ".": "1.4.4"
3
3
  }
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.4.4 (2023-09-06)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Support for changes in Rails 7.0.7. ([#260](https://github.com/googleapis/ruby-spanner-activerecord/issues/260))
8
+
9
+ ### 1.4.3 (2023-06-09)
10
+
11
+ #### Bug Fixes
12
+
13
+ * unquote string default value ([#253](https://github.com/googleapis/ruby-spanner-activerecord/issues/253))
14
+
3
15
  ### 1.4.2 (2023-06-01)
4
16
 
5
17
  #### Bug Fixes
@@ -23,21 +23,23 @@ module ActiveRecord
23
23
  skip_test_table_create!
24
24
  super
25
25
 
26
- connection.drop_table :rename_column_comments, if_exists: true
27
- connection.drop_table :rename_column_posts, if_exists: true
28
-
29
- connection.create_table(:rename_column_posts) do |t|
30
- t.string :name, limit: 128
31
- t.integer :comment_count
32
- end
33
-
34
- connection.create_table(:rename_column_comments) do |t|
35
- t.string :comment
36
- # The Spanner ActiveRecord adapter does not support creating an index on a column that also has a foreign key,
37
- # as Cloud Spanner automatically creates a managed index for the foreign key. The index is therefore created
38
- # separately.
39
- t.references :rename_column_post, foreign_key: true
40
- t.index :rename_column_post_id
26
+ connection.ddl_batch do
27
+ connection.drop_table :rename_column_comments, if_exists: true
28
+ connection.drop_table :rename_column_posts, if_exists: true
29
+
30
+ connection.create_table(:rename_column_posts) do |t|
31
+ t.string :name, limit: 128
32
+ t.integer :comment_count
33
+ end
34
+
35
+ connection.create_table(:rename_column_comments) do |t|
36
+ t.string :comment
37
+ # The Spanner ActiveRecord adapter does not support creating an index on a column that also has a foreign key,
38
+ # as Cloud Spanner automatically creates a managed index for the foreign key. The index is therefore created
39
+ # separately.
40
+ t.references :rename_column_post, foreign_key: true
41
+ t.index :rename_column_post_id
42
+ end
41
43
  end
42
44
 
43
45
  RenameColumnPost.reset_column_information
@@ -7,15 +7,47 @@ module Models
7
7
  class DefaultValueTest < SpannerAdapter::TestCase
8
8
  include TestHelpers::WithSeparateDatabase
9
9
 
10
- class DynamicItem < ActiveRecord::Base; end
10
+ class LiteralValue < ActiveRecord::Base; end
11
+ class ExpressionValue < ActiveRecord::Base; end
11
12
 
12
- def test_dynamic_default_values
13
- connection.create_table :dynamic_items do |t|
13
+ def test_literal_default_values
14
+ default = OpenStruct.new(
15
+ col_string: "default",
16
+ col_int64: 123,
17
+ col_float64: 1.23,
18
+ col_numeric: BigDecimal("1.23"),
19
+ col_bool: true,
20
+ col_date: Date.new(2023, 5, 9),
21
+ col_timestamp: DateTime.new(2023, 5, 9, 1, 2, 3),
22
+ )
23
+
24
+ connection.create_table :literal_values do |t|
25
+ t.column :col_string, :string, default: default.col_string
26
+ t.column :col_int64, :bigint, default: default.col_int64
27
+ t.column :col_float64, :float, default: default.col_float64
28
+ t.column :col_numeric, :numeric, default: default.col_numeric
29
+ t.column :col_bool, :boolean, default: default.col_bool
30
+ t.column :col_date, :date, default: default.col_date
31
+ t.column :col_timestamp, :datetime, default: default.col_timestamp
32
+ end
33
+
34
+ item = LiteralValue.new
35
+ default.each_pair { |col, expected| assert_equal(expected, item[col]) }
36
+ item.save!
37
+ default.each_pair { |col, expected| assert_equal(expected, item[col]) }
38
+ item.reload
39
+ default.each_pair { |col, expected| assert_equal(expected, item[col]) }
40
+ end
41
+
42
+ def test_expression_default_values
43
+ connection.create_table :expression_values do |t|
44
+ t.column :col_numeric, :numeric, default: -> { "NUMERIC '1.23'" }
14
45
  t.column :col_timestamp, :datetime, default: -> { "CURRENT_TIMESTAMP()" }
15
46
  end
16
47
 
17
- item = DynamicItem.create!
48
+ item = ExpressionValue.create!
18
49
  item.reload
50
+ assert_equal(BigDecimal("1.23"), item.col_numeric)
19
51
  assert(item.col_timestamp)
20
52
  end
21
53
  end
@@ -20,6 +20,7 @@ module TestHelpers
20
20
 
21
21
  def teardown
22
22
  spanner_adapter_connection.database.drop
23
+ ActiveRecord::Base.connection_pool.disconnect!
23
24
  end
24
25
 
25
26
  def connection_config
@@ -32,12 +32,15 @@ module ActiveRecord
32
32
  module ConnectionAdapters
33
33
  module Spanner
34
34
  module Quoting
35
+ QUOTED_COLUMN_NAMES = Concurrent::Map.new # :nodoc:
36
+ QUOTED_TABLE_NAMES = Concurrent::Map.new # :nodoc:
37
+
35
38
  def quote_column_name name
36
- self.class.quoted_column_names[name] ||= "`#{super.gsub '`', '``'}`".freeze
39
+ QUOTED_COLUMN_NAMES[name] ||= "`#{super.gsub '`', '``'}`".freeze
37
40
  end
38
41
 
39
42
  def quote_table_name name
40
- self.class.quoted_table_names[name] ||= super.gsub(".", "`.`").freeze
43
+ QUOTED_TABLE_NAMES[name] ||= super.gsub(".", "`.`").freeze
41
44
  end
42
45
 
43
46
  STR_ESCAPE_REGX = /[\n\r'\\]/.freeze
@@ -87,6 +87,10 @@ module ActiveRecordSpannerAdapter
87
87
  default = nil
88
88
  end
89
89
 
90
+ if default && type == "STRING"
91
+ default = unquote_string default
92
+ end
93
+
90
94
  Table::Column.new \
91
95
  table_name,
92
96
  column_name,
@@ -286,8 +290,70 @@ module ActiveRecordSpannerAdapter
286
290
  [matched[1], limit]
287
291
  end
288
292
 
293
+ def unquote_string value
294
+ return unquote_raw_string value, 1 if value[0] == "r" || value[0] == "R"
295
+ unescape_string unquote_raw_string value
296
+ end
297
+
289
298
  private
290
299
 
300
+ def unquote_raw_string value, prefix_length = 0
301
+ triple_quote_range = prefix_length..(prefix_length + 2)
302
+ if value[triple_quote_range] == '"""' || value[triple_quote_range] == "'''"
303
+ value[(prefix_length + 3)...-3]
304
+ else
305
+ value[(prefix_length + 1)...-1]
306
+ end
307
+ end
308
+
309
+ def unescape_string value # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
310
+ str = ""
311
+ i = 0
312
+
313
+ while i < value.length
314
+ case value[i]
315
+ when "\\"
316
+ i += 1
317
+ case value[i]
318
+ when "a" then str += "\a"
319
+ when "b" then str += "\b"
320
+ when "f" then str += "\f"
321
+ when "n" then str += "\n"
322
+ when "r" then str += "\r"
323
+ when "t" then str += "\t"
324
+ when "v" then str += "\v"
325
+ when "\\" then str += "\\"
326
+ when "?" then str += "?"
327
+ when "'" then str += "'"
328
+ when '"' then str += '"'
329
+ when "`" then str += "`"
330
+ when "0".."7"
331
+ str += unescape_unicode value, i, 3, 8
332
+ i += 2
333
+ when "x", "X"
334
+ str += unescape_unicode value, i + 1, 2, 16
335
+ i += 2
336
+ when "u"
337
+ str += unescape_unicode value, i + 1, 4, 16
338
+ i += 4
339
+ when "U"
340
+ str += unescape_unicode value, i + 1, 8, 16
341
+ i += 8
342
+ end
343
+ else
344
+ str += value[i]
345
+ end
346
+
347
+ i += 1
348
+ end
349
+
350
+ str
351
+ end
352
+
353
+ def unescape_unicode value, start, length, base
354
+ [value[start...(start + length)].to_i(base)].pack "U"
355
+ end
356
+
291
357
  def column_options table_name, column_name
292
358
  sql = +"SELECT COLUMN_NAME, OPTION_NAME, OPTION_TYPE, OPTION_VALUE"
293
359
  sql << " FROM INFORMATION_SCHEMA.COLUMN_OPTIONS"
@@ -5,5 +5,5 @@
5
5
  # https://opensource.org/licenses/MIT.
6
6
 
7
7
  module ActiveRecordSpannerAdapter
8
- VERSION = "1.4.2".freeze
8
+ VERSION = "1.4.4".freeze
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-spanner-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-01 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-spanner
@@ -539,7 +539,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
539
539
  - !ruby/object:Gem::Version
540
540
  version: '0'
541
541
  requirements: []
542
- rubygems_version: 3.4.2
542
+ rubygems_version: 3.4.19
543
543
  signing_key:
544
544
  specification_version: 4
545
545
  summary: Rails ActiveRecord connector for Google Spanner Database