class Pakyow::Data::Adapters::Sql::Differ
@api private
Public Class Methods
new(connection:, source:, attributes: source.attributes)
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 9 def initialize(connection:, source:, attributes: source.attributes) @connection, @source, @attributes = connection, source, attributes end
Public Instance Methods
attributes()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 25 def attributes Hash[@attributes.map { |attribute_name, attribute| [attribute_name, @connection.adapter.finalized_attribute(attribute)] }] end
attributes_to_add()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 31 def attributes_to_add {}.tap { |attributes| self.attributes.each do |attribute_name, attribute_type| unless schema.find { |column| column[0] == attribute_name } attributes[attribute_name] = attribute_type end end } end
changes?()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 17 def changes? attributes_to_add.any? || columns_to_remove.any? || column_types_to_change.any? end
column_types_to_change()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 51 def column_types_to_change {}.tap { |attributes| self.attributes.each do |attribute_name, attribute_type| if found_column = schema.find { |column| column[0] == attribute_name } column_name, column_info = found_column unless column_info[:type] == attribute_type.meta[:column_type] && (!attribute_type.meta.include?(:native_type) || column_info[:db_type] == attribute_type.meta[:native_type]) attributes[column_name] = attribute_type.meta[:migration_type] end end end } end
columns_to_remove()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 41 def columns_to_remove {}.tap { |columns| schema.each do |column_name, column_info| unless @source.attributes.keys.find { |attribute_name| attribute_name == column_name } columns[column_name] = column_info end end } end
exists?()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 13 def exists? raw_connection.table_exists?(table_name) end
table_name()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 21 def table_name @source.dataset_table end
Private Instance Methods
raw_connection()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 66 def raw_connection @connection.adapter.connection end
schema()
click to toggle source
# File lib/pakyow/data/adapters/sql/differ.rb, line 70 def schema raw_connection.schema(table_name) end