activerecord-cockroachdb-adapter 6.1.8 → 6.1.9

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: cddd7b77a75769847eedbbb0b7957a3602c76f0ecc1b55bf988caebf85404fa6
4
- data.tar.gz: 884de42df8ac2f764529febc00208d7e3c8a0dbe4aec4c43e615c13b3b495eca
3
+ metadata.gz: a8b028b8755fedebaa4aff7f1f98218d553726364df8fcc24647c3bfd7c80e2d
4
+ data.tar.gz: 3f7268dccaf636eb1532697dd525a39930a829eba290f06d7446cc24547e0ea1
5
5
  SHA512:
6
- metadata.gz: 968b9d0b39f778413536feb3b2a1e740f3d785fcb6d472092eeba018c3a6d7b823ba2988aa69fa8571c2da4cf041b027e72b250f325b6377ed9a7f978e2ab53b
7
- data.tar.gz: 21bf7f2cf7b58840b043c155588d3abb605b7b6a72732f9b04203616d5097c7468ead0752ebfc3196310f2fd248b67aed2efed49e751c3ceb4b328e7d333b310
6
+ metadata.gz: cea6678432382da1af4de2fb0216d820bde0be2c254d564fa931fc34683898ec72faf507263bed58187e2f582f55b1c590d1ba8b3fd8487be69518578903821f
7
+ data.tar.gz: a3e7d5dbc70abfeac236084dbcc7e60530d10413fbee0f8d6c08668c11d7ab3394e882b6a5a4b660520a1c456de09585128f66de92708ab2ad314f9ca3c66498
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.1.9 - 2022-04-26
4
+
5
+ - Fix bug where duplicate `rowid` columns would be created when loading
6
+ a schema dump of a table that was not created with an explicit primary key.
7
+ - Support the NOT VISIBLE syntax from CockroachDB, by using the `hidden`
8
+ column modifier in the Rails schema.
9
+
3
10
  ## 6.1.8 - 2022-03-14
4
11
 
5
12
  - Add a test helper from https://github.com/rails/rails/pull/40822
@@ -6,9 +6,10 @@ module ActiveRecord
6
6
  # https://github.com/rgeo/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis/spatial_column.rb
7
7
  def initialize(name, default, sql_type_metadata = nil, null = true,
8
8
  default_function = nil, collation: nil, comment: nil,
9
- serial: nil, spatial: nil)
9
+ serial: nil, spatial: nil, generated: nil, hidden: nil)
10
10
  @sql_type_metadata = sql_type_metadata
11
11
  @geographic = !!(sql_type_metadata.sql_type =~ /geography\(/i)
12
+ @hidden = hidden
12
13
 
13
14
  if spatial
14
15
  # This case comes from an entry in the geometry_columns table
@@ -29,7 +30,7 @@ module ActiveRecord
29
30
  build_from_sql_type(sql_type_metadata.sql_type)
30
31
  end
31
32
  super(name, default, sql_type_metadata, null, default_function,
32
- collation: collation, comment: comment, serial: serial)
33
+ collation: collation, comment: comment, serial: serial, generated: generated)
33
34
  if spatial? && @srid
34
35
  @limit = { srid: @srid, type: to_type_name(geometric_type) }
35
36
  @limit[:has_z] = true if @has_z
@@ -52,6 +53,14 @@ module ActiveRecord
52
53
  spatial? ? @limit : super
53
54
  end
54
55
 
56
+ def virtual?
57
+ @generated.present?
58
+ end
59
+
60
+ def hidden?
61
+ @hidden
62
+ end
63
+
55
64
  def spatial?
56
65
  %i[geometry geography].include?(@sql_type_metadata.type)
57
66
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module CockroachDB
6
+ class SchemaCreation < PostgreSQL::SchemaCreation # :nodoc:
7
+ private
8
+ def add_column_options!(sql, options)
9
+ if options[:hidden]
10
+ sql << " NOT VISIBLE"
11
+ end
12
+ super
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module CockroachDB
6
+ class SchemaDumper < ConnectionAdapters::PostgreSQL::SchemaDumper # :nodoc:
7
+ private
8
+ def prepare_column_options(column)
9
+ spec = super
10
+ if column.hidden?
11
+ spec[:hidden] = true
12
+ end
13
+ spec
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -77,7 +77,7 @@ module ActiveRecord
77
77
  # override
78
78
  # https://github.com/rails/rails/blob/6-0-stable/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb#L624
79
79
  def new_column_from_field(table_name, field)
80
- column_name, type, default, notnull, oid, fmod, collation, comment = field
80
+ column_name, type, default, notnull, oid, fmod, collation, comment, generated, hidden = field
81
81
  type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
82
82
  default_value = extract_value_from_default(default)
83
83
  default_function = extract_default_function(default_value, default)
@@ -99,7 +99,9 @@ module ActiveRecord
99
99
  collation: collation,
100
100
  comment: comment.presence,
101
101
  serial: serial,
102
- spatial: spatial
102
+ spatial: spatial,
103
+ generated: generated,
104
+ hidden: hidden
103
105
  )
104
106
  end
105
107
 
@@ -186,6 +188,14 @@ module ActiveRecord
186
188
  @spatial_column_info ||= {}
187
189
  @spatial_column_info[table_name.to_sym] ||= SpatialColumnInfo.new(self, table_name.to_s)
188
190
  end
191
+
192
+ def create_schema_dumper(options)
193
+ CockroachDB::SchemaDumper.create(self, options)
194
+ end
195
+
196
+ def schema_creation
197
+ CockroachDB::SchemaCreation.new(self)
198
+ end
189
199
  end
190
200
  end
191
201
  end
@@ -1,7 +1,10 @@
1
1
  require "rgeo/active_record"
2
2
 
3
3
  require "active_record/connection_adapters/postgresql_adapter"
4
+ require "active_record/connection_adapters/cockroachdb/attribute_methods"
4
5
  require "active_record/connection_adapters/cockroachdb/column_methods"
6
+ require "active_record/connection_adapters/cockroachdb/schema_creation"
7
+ require "active_record/connection_adapters/cockroachdb/schema_dumper"
5
8
  require "active_record/connection_adapters/cockroachdb/schema_statements"
6
9
  require "active_record/connection_adapters/cockroachdb/referential_integrity"
7
10
  require "active_record/connection_adapters/cockroachdb/transaction_manager"
@@ -9,7 +12,6 @@ require "active_record/connection_adapters/cockroachdb/database_statements"
9
12
  require "active_record/connection_adapters/cockroachdb/table_definition"
10
13
  require "active_record/connection_adapters/cockroachdb/quoting"
11
14
  require "active_record/connection_adapters/cockroachdb/type"
12
- require "active_record/connection_adapters/cockroachdb/attribute_methods"
13
15
  require "active_record/connection_adapters/cockroachdb/column"
14
16
  require "active_record/connection_adapters/cockroachdb/spatial_column_info"
15
17
  require "active_record/connection_adapters/cockroachdb/setup"
@@ -199,7 +201,7 @@ module ActiveRecord
199
201
  end
200
202
 
201
203
  def supports_virtual_columns?
202
- false
204
+ @crdb_version >= 2110
203
205
  end
204
206
 
205
207
  def supports_string_to_array_coercion?
@@ -474,7 +476,8 @@ module ActiveRecord
474
476
  SELECT a.attname, format_type(a.atttypid, a.atttypmod),
475
477
  pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod,
476
478
  c.collname, NULL AS comment,
477
- #{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated
479
+ #{supports_virtual_columns? ? 'attgenerated' : quote('')} as attgenerated,
480
+ NULL as is_hidden
478
481
  FROM pg_attribute a
479
482
  LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
480
483
  LEFT JOIN pg_type t ON a.atttypid = t.oid
@@ -500,8 +503,18 @@ module ActiveRecord
500
503
  dtype = field[1]
501
504
  field[1] = crdb_fields[field[0]][2].downcase if re.match(dtype)
502
505
  field[7] = crdb_fields[field[0]][1]&.gsub!(/^\'|\'?$/, '')
506
+ field[9] = true if crdb_fields[field[0]][3]
503
507
  field
504
508
  end
509
+ fields.delete_if do |field|
510
+ # Don't include rowid column if it is hidden and the primary key
511
+ # is not defined (meaning CRDB implicitly created it).
512
+ if field[0] == CockroachDBAdapter::DEFAULT_PRIMARY_KEY
513
+ field[9] && !primary_key(table_name)
514
+ else
515
+ false # Keep this entry.
516
+ end
517
+ end
505
518
  end
506
519
 
507
520
  # Fetch the column comment because it's faster this way
@@ -512,7 +525,7 @@ module ActiveRecord
512
525
  def crdb_column_definitions(table_name)
513
526
  fields = \
514
527
  query(<<~SQL, "SCHEMA")
515
- SELECT c.column_name, c.column_comment, c.crdb_sql_type
528
+ SELECT c.column_name, c.column_comment, c.crdb_sql_type, c.is_hidden::BOOLEAN
516
529
  FROM information_schema.columns c
517
530
  WHERE c.table_name = #{quote(table_name)}
518
531
  SQL
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecord
4
- COCKROACH_DB_ADAPTER_VERSION = "6.1.8"
4
+ COCKROACH_DB_ADAPTER_VERSION = "6.1.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cockroachdb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.8
4
+ version: 6.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cockroach Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-14 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -87,6 +87,8 @@ files:
87
87
  - lib/active_record/connection_adapters/cockroachdb/oid/type_map_initializer.rb
88
88
  - lib/active_record/connection_adapters/cockroachdb/quoting.rb
89
89
  - lib/active_record/connection_adapters/cockroachdb/referential_integrity.rb
90
+ - lib/active_record/connection_adapters/cockroachdb/schema_creation.rb
91
+ - lib/active_record/connection_adapters/cockroachdb/schema_dumper.rb
90
92
  - lib/active_record/connection_adapters/cockroachdb/schema_statements.rb
91
93
  - lib/active_record/connection_adapters/cockroachdb/setup.rb
92
94
  - lib/active_record/connection_adapters/cockroachdb/spatial_column_info.rb