method

new_column_from_field

Importance_0
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: SchemaStatements
new_column_from_field(table_name, field, _definitions) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb, line 917
          def new_column_from_field(table_name, field, _definitions)
            column_name, type, default, notnull, oid, fmod, collation, comment, identity, attgenerated = field
            type_metadata = fetch_type_metadata(column_name, type, oid.to_i, fmod.to_i)
            default_value = extract_value_from_default(default)

            if attgenerated.present?
              default_function = default
            else
              default_function = extract_default_function(default_value, default)
            end

            if match = default_function&.match(/\Anextval\('"?(?<sequence_name>.+_(?<suffix>seq\d*))"?'::regclass\)\z/)
              serial = sequence_name_from_parts(table_name, column_name, match[:suffix]) == match[:sequence_name]
            end

            PostgreSQL::Column.new(
              column_name,
              default_value,
              type_metadata,
              !notnull,
              default_function,
              collation: collation,
              comment: comment.presence,
              serial: serial,
              identity: identity.presence,
              generated: attgenerated
            )
          end
Register or log in to add new notes.