diff --git a/activerecord6-redshift-adapter.gemspec b/activerecord6-redshift-adapter.gemspec index 6dcc22f..35b7c71 100644 --- a/activerecord6-redshift-adapter.gemspec +++ b/activerecord6-redshift-adapter.gemspec @@ -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 = 'fantast.d@gmail.com' - 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' diff --git a/lib/active_record/connection_adapters/redshift/schema_statements.rb b/lib/active_record/connection_adapters/redshift/schema_statements.rb index 9ab9007..2852275 100644 --- a/lib/active_record/connection_adapters/redshift/schema_statements.rb +++ b/lib/active_record/connection_adapters/redshift/schema_statements.rb @@ -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) @@ -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 diff --git a/lib/active_record/connection_adapters/redshift_adapter.rb b/lib/active_record/connection_adapters/redshift_adapter.rb index 66eec87..0ec30d1 100644 --- a/lib/active_record/connection_adapters/redshift_adapter.rb +++ b/lib/active_record/connection_adapters/redshift_adapter.rb @@ -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" }, @@ -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'