diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-09 04:39:15 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-09 04:39:15 +0900 |
commit | 35d388b2e9639e5f1c1db032ded04dd5cda7bceb (patch) | |
tree | 0c1a463d1cc9ab5e4628a4a056076b9dd3a9fdb3 /activerecord/lib/active_record/connection_adapters/postgresql/column.rb | |
parent | 61073e3190fe149ed5bf46c8f10276a2a7155112 (diff) | |
parent | f185e0ebc9cc18c596eb9cab1a9cd99e26a20500 (diff) | |
download | rails-35d388b2e9639e5f1c1db032ded04dd5cda7bceb.tar.gz rails-35d388b2e9639e5f1c1db032ded04dd5cda7bceb.tar.bz2 rails-35d388b2e9639e5f1c1db032ded04dd5cda7bceb.zip |
Merge pull request #35890 from kamipo/except_table_name_from_column
Except `table_name` from column objects
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/column.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/column.rb | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb index 3ccc7271ab..ef98d2b37a 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb @@ -2,42 +2,21 @@ module ActiveRecord module ConnectionAdapters - # PostgreSQL-specific extensions to column definitions in a table. - class PostgreSQLColumn < Column #:nodoc: - delegate :array, :oid, :fmod, to: :sql_type_metadata - alias :array? :array - - def initialize(*, max_identifier_length: 63, **) - super - @max_identifier_length = max_identifier_length - end - - def serial? - return unless default_function - - if %r{\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z} =~ default_function - sequence_name_from_parts(table_name, name, suffix) == sequence_name + module PostgreSQL + class Column < ConnectionAdapters::Column # :nodoc: + delegate :array, :oid, :fmod, to: :sql_type_metadata + alias :array? :array + + def initialize(*, serial: nil, **) + super + @serial = serial end - end - private - attr_reader :max_identifier_length - - def sequence_name_from_parts(table_name, column_name, suffix) - over_length = [table_name, column_name, suffix].map(&:length).sum + 2 - max_identifier_length - - if over_length > 0 - column_name_length = [(max_identifier_length - suffix.length - 2) / 2, column_name.length].min - over_length -= column_name.length - column_name_length - column_name = column_name[0, column_name_length - [over_length, 0].min] - end - - if over_length > 0 - table_name = table_name[0, table_name.length - over_length] - end - - "#{table_name}_#{column_name}_#{suffix}" + def serial? + @serial end + end end + PostgreSQLColumn = PostgreSQL::Column # :nodoc: end end |