method
table_structure_with_collation
v7.2.3 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::SQLite3Adapter
table_structure_with_collation(table_name, basic_structure)private
No documentation available.
# File activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb, line 678
def table_structure_with_collation(table_name, basic_structure)
collation_hash = {}
auto_increments = {}
generated_columns = {}
column_strings = table_structure_sql(table_name, basic_structure.map { |column| column["name"] })
if column_strings.any?
column_strings.each do |column_string|
# This regex will match the column name and collation type and will save
# the value in $1 and $2 respectively.
collation_hash[$1] = $2 if COLLATE_REGEX =~ column_string
auto_increments[$1] = true if PRIMARY_KEY_AUTOINCREMENT_REGEX =~ column_string
generated_columns[$1] = $2 if GENERATED_ALWAYS_AS_REGEX =~ column_string
end
basic_structure.map do |column|
column_name = column["name"]
if collation_hash.has_key? column_name
column["collation"] = collation_hash[column_name]
end
if auto_increments.has_key?(column_name)
column["auto_increment"] = true
end
if generated_columns.has_key?(column_name)
column["dflt_value"] = generated_columns[column_name]
end
column
end
else
basic_structure.to_a
end
end