Skip to content

Commit

Permalink
DEV-7136 #time 2.5h Resolve issue with incorrect handling of 'limit' …
Browse files Browse the repository at this point in the history
…migration parameter, by adding to the NATIVE_DATABASE_TYPES and handling 'int' as type instead of just 'integer'. Bump version.
  • Loading branch information
Victor Miao committed May 10, 2021
1 parent 3ece56f commit 1f023b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions activerecord6-redshift-adapter.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'activerecord6-redshift-adapter'
s.version = '1.2.0'
s.version = '1.2.1'
s.summary = 'Amazon Redshift adapter for ActiveRecord '
s.description = 'Amazon Redshift _makeshift_ adapter for ActiveRecord 6.'
s.license = 'MIT'

s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau']
s.author = ['Nancy Foen', 'Minero Aoki', 'iamdbc', 'Quentin Rousseau', 'vmeow']
s.email = '[email protected]'
s.homepage = 'https://github.com/kwent/activerecord6-redshift-adapter'
s.homepage = 'https://github.com/ValorWaterAnalytics/activerecord6-redshift-adapter'

s.files = Dir.glob(['LICENSE', 'README.md', 'lib/**/*.rb'])
s.require_path = 'lib'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ class SchemaCreation < SchemaCreation
private

def visit_ColumnDefinition(o)
super
o.sql_type = type_to_sql(o.type, **o.options)
column_sql = +"#{quote_column_name(o.name)} #{o.sql_type}"
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
column_sql
end

def add_column_options!(sql, options)
Expand Down Expand Up @@ -426,7 +429,7 @@ def index_name_length
# Maps logical Rails types to PostgreSQL-specific data types.
def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
case type.to_s
when 'integer'
when 'integer', 'int'
return 'integer' unless limit

case limit
Expand Down
14 changes: 9 additions & 5 deletions lib/active_record/connection_adapters/redshift_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ class RedshiftAdapter < AbstractAdapter
primary_key: "bigint identity primary key",
string: { name: "varchar" },
text: { name: "varchar" },
varchar: { name: "varchar" },
smallint: { name: "smallint" },
int: { name: "integer" },
integer: { name: "integer" },
bigint: { name: "bigint" },
float: { name: "float" },
decimal: { name: "decimal" },
datetime: { name: "timestamp" },
timestamptz: { name: "timestamptz" },
time: { name: "time" },
date: { name: "date" },
bigint: { name: "bigint" },
boolean: { name: "boolean" },
serial: { name: "integer" },
bigserial: { name: "bigint" },
Expand Down Expand Up @@ -350,10 +354,10 @@ def get_oid_type(oid, fmod, column_name, sql_type = '') # :nodoc:
}
end

def initialize_type_map(m) # :nodoc:
register_class_with_limit m, 'int2', Type::Integer
register_class_with_limit m, 'int4', Type::Integer
register_class_with_limit m, 'int8', Type::Integer
def initialize_type_map(m = type_map) # :nodoc:
m.register_type "int2", Type::Integer.new(limit: 2)
m.register_type "int4", Type::Integer.new(limit: 4)
m.register_type "int8", Type::Integer.new(limit: 8)
m.alias_type 'oid', 'int2'
m.register_type 'float4', Type::Float.new
m.alias_type 'float8', 'float4'
Expand Down

0 comments on commit 1f023b3

Please sign in to comment.