From 7f0ede738a0504fb11cc09ef955fb58104b52028 Mon Sep 17 00:00:00 2001 From: Oliver Tan Date: Wed, 2 Feb 2022 13:12:31 +1100 Subject: [PATCH] handle atttypmod being correct for decimals from v22.1 --- .../connection_adapters/cockroachdb_adapter.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/active_record/connection_adapters/cockroachdb_adapter.rb b/lib/active_record/connection_adapters/cockroachdb_adapter.rb index e0e478df..41089bf3 100644 --- a/lib/active_record/connection_adapters/cockroachdb_adapter.rb +++ b/lib/active_record/connection_adapters/cockroachdb_adapter.rb @@ -297,9 +297,19 @@ def initialize_type_map(m = type_map) precision = extract_precision(sql_type) scale = extract_scale(sql_type) + + # The type for the numeric depends on the width of the field, + # so we'll do something special here. + # + # When dealing with decimal columns: + # + # places after decimal = fmod - 4 & 0xffff + # places before decimal = (fmod - 4) >> 16 & 0xffff + # + # For older versions of CockroachDB (