Skip to content

Commit 27cb149

Browse files
committed
update specific sql + precise delegation to model (see rails fd5bd98)
1 parent 342d280 commit 27cb149

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

lib/active_record/relation/query_methods_ext.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def force_index(index_name, direction: nil)
5757
def force_index!(index_name, direction: nil)
5858
return self unless from_clause_is_a_table_name?
5959

60-
index_name = sanitize_sql(index_name.to_s)
60+
index_name = model.sanitize_sql(index_name.to_s)
6161
direction = direction.to_s.upcase
6262
direction = %w[ASC DESC].include?(direction) ? ",#{direction}" : ""
6363

@@ -84,7 +84,7 @@ def index_hint(hint)
8484
def index_hint!(hint)
8585
return self unless from_clause_is_a_table_name?
8686

87-
hint = sanitize_sql(hint.to_s)
87+
hint = model.sanitize_sql(hint.to_s)
8888
@index_hint = hint.to_s
8989
self.from_clause = build_from_clause_with_hints
9090
self
@@ -120,7 +120,7 @@ def build_from_clause_with_hints
120120

121121
table_name =
122122
if from_clause.empty?
123-
quoted_table_name
123+
model.quoted_table_name
124124
else
125125
# Remove previous table hints if any. And spaces.
126126
from_clause.value.partition("@").first.strip

test/excludes/ActiveRecord/ConnectionAdapters/PostgreSQLAdapterTest.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@
3535
exclude :test_translate_no_connection_exception_to_not_established, "CRDB doesn't implement pg_terminate_backend()"
3636

3737
exclude :test_disable_extension_without_schema, ExcludeMessage::NO_HSTORE
38+
exclude :test_extensions_omits_current_schema_name, ExcludeMessage::NO_HSTORE
39+
exclude :test_extensions_includes_non_current_schema_name, ExcludeMessage::NO_HSTORE
40+
exclude :test_disable_extension_with_schema, ExcludeMessage::NO_HSTORE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
exclude "test_#resolve_raises_if_the_adapter_is_using_the_pre_7.2_adapter_registration_API", "One adapter is missing in the test, added below"
2+
3+
test "#resolve raises if the adapter is using the pre 7.2 adapter registration API with CRDB" do
4+
exception = assert_raises(ActiveRecord::AdapterNotFound) do
5+
ActiveRecord::ConnectionAdapters.resolve("fake_legacy")
6+
end
7+
8+
assert_equal(
9+
"Database configuration specifies nonexistent 'fake_legacy' adapter. Available adapters are: abstract, cockroachdb, fake, mysql2, postgresql, sqlite3, trilogy. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile if it's not in the list of available adapters.",
10+
exception.message
11+
)
12+
ensure
13+
ActiveRecord::ConnectionAdapters.instance_variable_get(:@adapters).delete("fake_legacy")
14+
end

test/schema/cockroachdb_specific_schema.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# with an explanation of why they don't work.
66

77
ActiveRecord::Schema.define do
8-
ActiveRecord::TestCase.enable_extension!("uuid-ossp", ActiveRecord::Base.lease_connection)
9-
ActiveRecord::TestCase.enable_extension!("pgcrypto", ActiveRecord::Base.lease_connection) if ActiveRecord::Base.lease_connection.supports_pgcrypto_uuid?
8+
ActiveRecord::TestCase.enable_extension!("uuid-ossp", connection)
9+
ActiveRecord::TestCase.enable_extension!("pgcrypto", connection) if connection.supports_pgcrypto_uuid?
1010

1111
uuid_default = connection.supports_pgcrypto_uuid? ? {} : { default: "uuid_generate_v4()" }
1212

@@ -45,6 +45,7 @@
4545
t.string :char2, limit: 50, default: "a varchar field"
4646
t.text :char3, default: "a text field"
4747
t.bigint :bigint_default, default: -> { "0::bigint" }
48+
t.binary :binary_default_function, default: -> { "convert_to('A', 'UTF8')" }
4849
t.text :multiline_default, default: "--- []
4950
5051
"
@@ -177,11 +178,13 @@
177178
t.integer :position_1
178179
t.integer :position_2
179180
t.integer :position_3
181+
t.integer :position_4
180182

181-
# CockroachDB does not support deferrable, hence these three lines have been simplified.
183+
# CockroachDB does not support deferrable, hence these four lines have been simplified.
182184
t.unique_constraint :position_1, name: "test_unique_constraints_position_1"
183185
t.unique_constraint :position_2, name: "test_unique_constraints_position_2"
184186
t.unique_constraint :position_3, name: "test_unique_constraints_position_3"
187+
t.unique_constraint :position_4, name: "test_unique_constraints_position_4"
185188
end
186189

187190
if supports_partitioned_indexes?
@@ -200,6 +203,9 @@
200203

201204
add_index(:companies, [:firm_id, :type], name: "company_include_index", include: [:name, :account_id])
202205

206+
# In the original PostgreSQL schema, there would be a table here, populated using triggers.
207+
# This is not supported by Cockroachdb so we removed that bit.
208+
203209
create_table :buildings, force: true do |t|
204210
t.st_point :coordinates, srid: 3857
205211
t.st_point :latlon, srid: 4326, geographic: true

0 commit comments

Comments
 (0)