Skip to content

Commit 68c7398

Browse files
committed
Fix postgres schema dump tests limit and array default and minor refactor
1 parent 496b289 commit 68c7398

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ def configure_connection
9797
end
9898
end
9999

100-
@type_map = Type::HashLookupTypeMap.new
101-
initialize_type_map
100+
reload_type_map
102101
end
103102

104103
# @private
@@ -125,7 +124,7 @@ def configure_connection
125124
inet: { name: 'inet' },
126125
int4range: { name: 'int4range' },
127126
int8range: { name: 'int8range' },
128-
integer: { name: 'integer' },
127+
integer: { name: 'integer', limit: 4 },
129128
interval: { name: 'interval' },
130129
json: { name: 'json' },
131130
jsonb: { name: 'jsonb' },

lib/arjdbc/postgresql/oid_types.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,15 @@ def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
118118
end
119119

120120
def reload_type_map
121-
type_map.clear
121+
@lock.synchronize do
122+
if @type_map
123+
type_map.clear
124+
else
125+
@type_map = Type::HashLookupTypeMap.new
126+
end
127+
122128
initialize_type_map
129+
end
123130
end
124131

125132
def initialize_type_map_inner(m)
@@ -274,10 +281,6 @@ def extract_precision(sql_type)
274281
$1.to_i if sql_type =~ /\((\d+)(,\d+)?\)/
275282
end
276283

277-
def extract_limit(sql_type)
278-
$1.to_i if sql_type =~ /\((.*)\)/
279-
end
280-
281284
# Support arrays/ranges for defining attributes that don't exist in the db
282285
ActiveRecord::Type.add_modifier({ array: true }, OID::Array, adapter: :postgresql)
283286
ActiveRecord::Type.add_modifier({ range: true }, OID::Range, adapter: :postgresql)

test/db/postgresql/schema_dump_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_schema_dump_should_not_have_limits_on_text_or_date
5858
def test_schema_dump_integer_with_no_limit_should_have_no_limit
5959
dump = dump_with_data_types
6060
lines = dump.lines.grep(/sample_integer_no_limit/)
61+
6162
assert ! lines.empty?
6263
lines.each { |line| assert line !~ /:limit|limit:/ }
6364
end

0 commit comments

Comments
 (0)